Differences from KaTeX
Where val_latex's output differs from KaTeX on purpose, what it accepts that KaTeX rejects, and the choices it makes for input LaTeX would reject.
val_latex aims at KaTeX’s coverage, but it is a TeX layout engine with its
own fonts, not a port. Most visible differences come from the font: val_latex
uses Latin Modern Math with its OpenType MATH table, KaTeX its own KaTeX
fonts with TeX metrics. Same design, slightly different glyph sizes, so
heights and widths differ by small amounts per construct.
Deliberate differences
Section titled “Deliberate differences”| Construct | KaTeX | val_latex | Why |
|---|---|---|---|
| Fractions as atoms | ord | inner (TeX rule 15e) | TeX adds a thin space in 2\frac12; KaTeX does not. |
\mathop{\star}_a^b in display |
limits beside | limits above and below | In TeX, \mathop atoms take \displaylimits by default. |
\surd |
text-font √ | the math font’s radical | As TeX’s cmsy radical. |
\vdots |
TeX \vbox |
the font’s ⋮ glyph | Visually tighter. |
Top-level \\ |
a line break in the text flow | stacked lines | Needed for wrapping. |
\tag, align, gather, equation, multline, CD in inline math |
parse error | rendered | val_latex does not refuse valid LaTeX. |
| Script-size glyphs | text-size glyphs scaled down | the font’s script-size designs (ssty), as TeX uses cmr7/cmr5 |
LayoutOptions(scriptSizeGlyphs: false) matches KaTeX. |
CD diagrams |
not vertically centred | centred on the math axis, as amscd does | |
\xtofrom |
a custom double arrow | the font’s ⇄ assembly, slightly taller |
Accepted here, rejected by KaTeX
Section titled “Accepted here, rejected by KaTeX”multline; \multicolumn; \cline; @{…} and *{n}{…} column specs;
\DeclareMathOperator; \newcommand with an optional argument; \sideset;
\prescript; \cancelto; \color[rgb]{…} and the RGB, HTML, gray
and cmyk models; \textsc; \mbox, \hbox; \bfseries and the other
LaTeX 2e switches; \root … \of; \displaylimits; text tables (tabular,
tabularx, longtable, table with \caption, booktabs rules,
\multirow); siunitx; physics; lists (itemize, enumerate,
description); \intertext; subequations; tikzcd and prooftree.
mhchem is on by default here; in KaTeX it is an extension to load. val_latex’s
\ce is written from mhchem’s documented syntax, not ported, so rare
constructs may render differently.
Every command KaTeX 0.19 and flutter_math_fork define is defined here too —
including names that are theirs rather than LaTeX’s, such as KaTeX’s Khan
Academy colours (\blue{x}, \redA…) and the MediaWiki names (\plusmn,
\Dagger, \lrarr…) — except flutter_math_fork’s \cursor.
Decisions
Section titled “Decisions”Where val_latex chose a behaviour that another engine, or a literal reading of LaTeX, does differently:
| Input | val_latex | Why |
|---|---|---|
\color{red}{x} + y |
colours x + y, as LaTeX, KaTeX and MathJax do |
\color is a switch; \textcolor{red}{x} colours only x. |
x^10 |
x^1 0, as TeX and every engine |
Changing it would change valid LaTeX. |
a &= b \\ &= c with no environment |
laid out as aligned, warning implicitAlignment |
LaTeX errors; the intent is clear and models write it often. |
\\frac{a}{b} (doubled by JSON) |
read as \frac, warning doubledBackslashes |
Only when every backslash run in the formula is even and a \\ precedes a known command. |
x^2' |
{x^2}', warning |
LaTeX: “Double superscript”. x^2^3 and x_1_2 stay errors, drawn nested. |
| A blank line in math | a line break, warning paragraphInMath |
LaTeX: “Missing $”. |
\[…\], $…$ inside a formula |
display or inline math, with a warning | LaTeX would end math mode. |
\multicolumn{99} past the last column |
clamped to the columns left, error multicolumnTooWide |
Keeps the rest of the table. |
Lengths past \maxdimen |
clamped, error dimensionTooLarge |
As TeX. |
\widehat over long bases |
keeps growing | TeX stops at the font’s largest size; KaTeX grows. |
Lowercase \mathcal/\mathscr |
from STIX Two | Latin Modern has no lowercase script letters. |
Green, Orange, Purple, Gray |
xcolor’s dvips values; lowercase names stay CSS | dvips names are case-sensitive in xcolor. |
\pdv{f}{x,y} with physics off |
the derivative package’s form | physics’ forms apply with the physics extension on. |
$ x + y $ in MathScanner |
text, unless spacedDollars: true |
Pandoc’s rule keeps prices as text; KaTeX’s auto-render takes it as math. |
It costs $5 while $x$ |
finds only x |
Auto-render pairs $5 while $. |
Markdown code in MathText |
skipped, also while streaming | Auto-render does not know Markdown. |
[ x^2 ], ( \frac{a}{b} ) with the backslashes lost |
text | Not LaTeX, and brackets are common in prose. |
Other behaviour by design
Section titled “Other behaviour by design”- Trust:
\url,\href,\includegraphicsand\htmlClassneedParseOptions.trust, as in KaTeX. - Tables:
\captionis a row of the table, not a float, numbered only withParseOptions.captionLabel; a\labelin it is resolved by the app (LayoutOptions.labels). - Lists are a two-column table of labels and items, wrapping only when a width is given.
- Fills:
\hfilland\hfilfill a table cell or an\hbox to; elsewhere they are a quad, since a formula has no line to fill. - Line breaking: a single symbol or unbreakable box wider than the line overflows it.
- Names no package defines (
\given,\indep,\ceil,\defeq…) stay undefined: adding them would invent meanings. - Selection is by atom, not by glyph within a symbol; a selection across groups copies whole structures, so the copied source parses.