Errors
Error markup
Section titled “Error markup”By default, invalid TeX does not throw. The result is a span with the class temml-error that holds the source and the error text, colored with ErrorColor. The source is escaped.
// ThrowOnError is false by default: the result shows the source and the error.var markup = TemmlRenderer.RenderToString(@"\sqrt{", new TemmlOptions { ErrorColor = "#cc0000" });
Console.WriteLine(markup); // <span class="temml-error" ...>...</span>The markup for \sqrt{ looks like this:
<span class="temml-error" style="color:#cc0000;white-space:pre-line;">\sqrt{
ParseError: Expected '}', got 'EOF' at end of input: \sqrt{</span>An unsupported command inside otherwise valid TeX is different: the command name is shown in the error color and the rest of the expression renders.
x + \unknowncommand + yWith ThrowOnError, an unsupported command throws too.
Exceptions
Section titled “Exceptions”Set ThrowOnError to get a ParseError.
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}| Member | Value |
|---|---|
Message |
The message upstream Temml reports, including the position and the underlined context. |
RawMessage |
The description of the error without the position and context. |
Position |
The zero-based offset of the problem in the input, or null when the error has no location. The message counts from one. |
ThrowOnError only covers errors in the TeX. Any other exception propagates whatever the option says. A few malformed inputs, such as x^, make upstream Temml fail with a JavaScript TypeError. The port throws an InvalidOperationException for those, so catch it too when the TeX comes from users.
Finding bad input at build time
Section titled “Finding bad input at build time”When the TeX is yours, for example in a static site, set ThrowOnError so a mistake fails the build instead of reaching a page.
MIT · Copyright 2020 Ron Kok · unofficial community port of Temml