brucemiller / LaTeXML

LaTeXML: a TeX and LaTeX to XML/HTML/ePub/MathML translator.
http://dlmf.nist.gov/LaTeXML/
Other
923 stars 98 forks source link

siunitx fails in mathmode with --mathsvg #2374

Open orbita2d opened 3 months ago

orbita2d commented 3 months ago

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
orbita2d commented 3 months ago

A better mapping would be to some kind of \ensuremath

dginev commented 3 months ago

Great example and diagnostic - thank you for the report. Please feel welcome to file other similar cases when you encounter them.

orbita2d commented 3 months ago

Workaround:

\let\oldsi\si
\renewcommand{\si}[1]{\text{\oldsi{#1}}}
\let\oldSI\SI
\renewcommand{\SI}[2]{\text{\oldSI{#1}{#2}}}

in the preamble.