Quickstart
Temml for .NET converts TeX math to MathML in C#. Browsers display MathML themselves, so a page needs a stylesheet and, for a few glyphs, a small font, but no script. This package is an unofficial community port of Temml by Ron Kok.
Install
Section titled “Install”The package targets net10.0 and netstandard2.0.
dotnet add package TemmlRender to a string
Section titled “Render to a string”TemmlRenderer.RenderToString takes a TeX expression, without $ delimiters, and returns MathML markup. In C#, write TeX in a verbatim string (@"...") or a raw string literal, so backslashes stay as written.
var mathml = TemmlRenderer.RenderToString(@"c = \pm\sqrt{a^2 + b^2}");
Console.WriteLine(mathml); // <math>...</math>A browser shows that expression like this:
c = \pm\sqrt{a^2 + b^2}Display mode
Section titled “Display mode”Set DisplayMode for an equation on its own line, with large operators and limits above and below.
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>\sum_{k=1}^{n} k = \frac{n(n+1)}{2}Work with the tree
Section titled “Work with the tree”RenderToMathMLTree returns the build tree before it becomes a string. Change it, then call ToMarkup.
var tree = TemmlRenderer.RenderToMathMLTree(@"e^{i\pi} + 1 = 0");tree.Classes.Add("euler");
Console.WriteLine(tree.ToMarkup()); // <math class="euler">...</math>Show it on a page
Section titled “Show it on a page”Serve one of the Temml stylesheets together with Temml.woff2, and write the markup into an HTML5 page. The files are embedded in the package. See Styles and fonts.
<!DOCTYPE html><html> <head> <link rel="stylesheet" href="/css/Temml-Local.css"> </head> <body> <!-- the string RenderToString returned --> </body></html>- Options lists every setting.
- Errors explains what happens with invalid TeX.
- DOM and auto-render renders into an AngleSharp document, or finds the math in a whole page.
- Security covers TeX from users.
MIT · Copyright 2020 Ron Kok · unofficial community port of Temml