Macros and extensions
Macros for one render
Section titled “Macros for one render”Put macros in Macros. The key is the command name with its backslash, and the value is its expansion. #1 to #9 stand for arguments. A string converts to TemmlMacro implicitly; a TemmlMacro can also wrap a function, as macros can upstream.
var options = new TemmlOptions{ Macros = new TemmlMacroDictionary { [@"\RR"] = @"\mathbb{R}", [@"\norm"] = @"\lVert #1 \rVert", },};
Console.WriteLine(TemmlRenderer.RenderToString(@"\norm{x} \in \RR", options));\def\RR{\mathbb{R}} \def\norm#1{\lVert #1 \rVert} \norm{x} \in \RRKeeping macros between renders
Section titled “Keeping macros between renders”\def and \newcommand last for one expression. \gdef and \global\let write into the dictionary you passed in Macros, so a later render that gets the same dictionary sees them. Pass a new dictionary to start over.
// \gdef writes into the dictionary you pass, so later renders see the macro.var shared = new TemmlOptions { Macros = new TemmlMacroDictionary() };
TemmlRenderer.RenderToString(@"\gdef\half{\frac{1}{2}}", shared);Console.WriteLine(TemmlRenderer.RenderToString(@"\half + \half = 1", shared));A dictionary that renders can write to is shared state. Do not use one instance from several threads at once.
Preambles
Section titled “Preambles”DefinePreamble parses a block of definitions, including \definecolor, and returns the macros to pass to later renders.
var preamble = TemmlRenderer.DefinePreamble( @"\newcommand\d[0]{\operatorname{d}\!} \def\foo{x^2} \definecolor{sortaGreen}{RGB}{128,128,0}");
var withPreamble = new TemmlOptions { Macros = preamble };Console.WriteLine( TemmlRenderer.RenderToString(@"\color{sortaGreen} \int \foo \, \d x", withPreamble));Built-in macros and symbols
Section titled “Built-in macros and symbols”DefineMacro and DefineSymbol change the tables that every render in the process uses. Call them once, at startup, before rendering. Prefer Macros for anything that belongs to one document or user.
// Adds a built-in macro for every later render in the process. Do this once, at startup.TemmlRenderer.DefineMacro(@"\QQ", @"\mathbb{Q}");
Console.WriteLine(TemmlRenderer.RenderToString(@"\sqrt{2} \notin \QQ"));// Adds a symbol to the built-in table, also for the whole process.TemmlRenderer.DefineSymbol(TemmlMode.Math, "mathord", "☺", @"\smiley");
Console.WriteLine(TemmlRenderer.RenderToString(@"x = \smiley"));Extensions
Section titled “Extensions”Upstream ships mhchem, physics, and texvc as extensions that its temml.cjs bundle includes. Here they are part of the Temml package and always available. There is nothing to load.
// mhchem, physics, and texvc are always available.Console.WriteLine(TemmlRenderer.RenderToString(@"\ce{2H2 + O2 -> 2H2O}"));Console.WriteLine(TemmlRenderer.RenderToString(@"\pdv{f}{x}"));Console.WriteLine(TemmlRenderer.RenderToString(@"\R^n"));| Extension | Provides |
|---|---|
| mhchem | \ce for chemical equations and \pu for physical units. |
| physics | Many commands of the LaTeX physics package, such as \dv, \pdv, and \bra. |
| texvc | Commands used on MediaWiki pages, such as \R. |
\ce{2H2 + O2 -> 2H2O}\pdv{f}{x} \qquad \braket{\phi}{\psi}Upstream’s copy-tex extension changes what a browser copies to the clipboard. It has no server equivalent and is not ported.
Which commands work
Section titled “Which commands work”Temml’s supported functions page lists them, and its support table sorts them alphabetically.
MIT · Copyright 2020 Ron Kok · unofficial community port of Temml