LaTeXML
LaTeXML copied to clipboard
siunitx fails in mathmode with --mathsvg
trafficstars
Example:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
$a=\SI{10}{\angstrom}$
\end{document}
What I expect to happen: a = 10 Å
rendered as an svg. As these macros are supposed to work in both math and text modes https://texdoc.org/serve/siunitx/0
What happens instead: Throws with
Error:shell:latex LaTeX command 'latex ltxmlimg > ltxmlimg.ltxoutput' failed
returned code 256 (!= 0):
See /tmp/LaTeXML2GNr2d/ltxmlimg.log
In Post::MathImages[@0x58af857f0020] ->generateImages
! LaTeX Error: \mathrm allowed only in math mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.63 \beginINLINE a=$10\text{\,}\mathrm
{\SIUnitSymbolAngstrom}$\endINLINE\cl...
You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
The relevant line from latexmlimg.tex
\beginINLINE a=$10\text{\,}\mathrm{\SIUnitSymbolAngstrom}$\endINLINE\clearpage
A better mapping would be to some kind of \ensuremath
Great example and diagnostic - thank you for the report. Please feel welcome to file other similar cases when you encounter them.
Workaround:
\let\oldsi\si
\renewcommand{\si}[1]{\text{\oldsi{#1}}}
\let\oldSI\SI
\renewcommand{\SI}[2]{\text{\oldSI{#1}{#2}}}
in the preamble.