Skip to content

About

TeX-to-MathML conversion library in .NET

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Temml for .NET

NuGet

Convert TeX math to MathML, in C#.

It is an unofficial community port of Temml by Ron Kok. It ports upstream 0.14.0. The output is MathML, which browsers display without any script.

To learn more, read the documentation.

Preview the docs site locally:

cd docs-site && npm ci && npm run api && npm run dev

Open http://localhost:4321/temml-dotnet/ . That URL is the marketing page. Documentation starts at http://localhost:4321/temml-dotnet/docs/ . Article sources stay in docs/articles/. See docs-site/README.md.

Installation

The packages target net10.0 and netstandard2.0.

Package What it has
Temml TeX to MathML, macros, the stylesheets and font. No third-party runtime dependencies.
Temml.AngleSharp Rendering into an AngleSharp document, auto-render, and \ref post-processing.

Run dotnet add package Temml. To render into an HTML document, run dotnet add package Temml.AngleSharp.

Usage

Rendering to a string

var mathml = TemmlRenderer.RenderToString(@"c = \pm\sqrt{a^2 + b^2}");

Console.WriteLine(mathml); // <math>...</math>

snippet source | anchor

Display mode

var display = TemmlRenderer.RenderToString(
    @"\sum_{k=1}^{n} k = \frac{n(n+1)}{2}",
    new TemmlOptions { DisplayMode = true }
);

Console.WriteLine(display); // <math display="block" ...>...</math>

snippet source | anchor

Handling errors

Invalid TeX comes back as error markup unless you set ThrowOnError. See Errors.

try
{
    TemmlRenderer.RenderToString(@"\sqrt{", new TemmlOptions { ThrowOnError = true });
}
catch (ParseError error)
{
    Console.WriteLine(error.Message); // the message upstream Temml reports
    Console.WriteLine(error.RawMessage);
    Console.WriteLine(error.Position); // 6, the offset in the input
}

snippet source | anchor

Macros

var options = new TemmlOptions
{
    Macros = new TemmlMacroDictionary
    {
        [@"\RR"] = @"\mathbb{R}",
        [@"\norm"] = @"\lVert #1 \rVert",
    },
};

Console.WriteLine(TemmlRenderer.RenderToString(@"\norm{x} \in \RR", options));

snippet source | anchor

See Macros and extensions. mhchem, physics, and texvc are built in.

Rendering the math in an HTML page

With Temml.AngleSharp:

var document = parser.ParseDocument(
    @"<!DOCTYPE html><body><p>Euler: \(e^{i\pi} + 1 = 0\)</p><p>$$\int_0^1 x^2\,dx$$</p></body>"
);

TemmlDom.RenderMathInElement(document.Body!);

Console.WriteLine(document.Body!.InnerHtml);

snippet source | anchor

See DOM and auto-render.

Styles and fonts

Include one Temml stylesheet and serve Temml.woff2 next to it. Both are embedded in the package. See Styles and fonts.

Security

Commands that load resources or set HTML attributes are blocked by default. Read Security before rendering TeX from users.

Coming from JavaScript

Migrating from upstream maps the JavaScript names to the C# ones. Compatibility records the ported version.

Contributing

See CONTRIBUTING.md.

License

MIT. Temml is Copyright (c) 2020 Ron Kok. The .NET port is Copyright (c) 2026 Darío Kondratiuk. See LICENSE and NOTICE.

About

TeX-to-MathML conversion library in .NET

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages