brucemiller / LaTeXML

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

Spacing in AMS alignments #2438

Closed phkonzen closed 1 day ago

phkonzen commented 3 days ago

Spacing (\quad, \qquad, ~) at the beginning of the equations are been lost after latexml conversion to HTML.

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\begin{document}
\begin{equation}
  \begin{aligned}
    &x = y + z \\
    &\qquad x^2 + x - r + \exp(x) 
  \end{aligned}
\end{equation}

\begin{align}
    &x = y + z \nonumber\\
    &\qquad x^2 + x - r + \exp(x) 
\end{align}

\begin{align}
  &x = y + z \nonumber\\
  &\text{}\qquad x^2 + x - r + \exp(x) 
\end{align}
\end{document}
latexmlc main.tex \
        --format=html5 --pmml \
        --javascript=LaTeXML-maybeMathJax.js \
        --dest=main.html -

The last \align starting with \text{} produce the expected output. Is there another way to get the output with the correct spacing?

dginev commented 3 days ago

@phkonzen as you have noticed latexml tends to trim leading/trailing whitespace in equations as non-meaningful.

The usual technique is to fine-tune the alignment markers to have them aligning at the exact position you want to maintain vertically, rather than adding horizontal space to an imprecise alignment.

So this rephrasing could be an improvement:

\begin{equation}
  \begin{aligned}
    x=& y + z \\
      & x^2 + x - r + \exp(x) 
  \end{aligned}
\end{equation}
phkonzen commented 3 days ago

@dginev , thanks for your comment. The fine-tune of alignment markers is not always possible. But sure, many cases can be solved just doing it.

dginev commented 2 days ago

@phkonzen Does that resolve your issue here? As the spaces are stylistic and no actual content is getting discarded, we can simply call this a "latexml quirk" and resolve.

Alternatively, there is a possible discussion whether the math-specific space trimming should be moving the spaces out into text mode, instead of discarding them completely. But I would need to check what side-effects that may have with alignments...

phkonzen commented 1 day ago

Yeah sure! There are suitable workarounds and no info are lost with this "latexml quirk".