LaTeXML icon indicating copy to clipboard operation
LaTeXML copied to clipboard

/align Has a lot of whitespace in rendered mathml output

Open orbita2d opened this issue 1 year ago • 5 comments

\begin{align}
A &=& \cos\theta &+& \sin\theta \\
  &=& D &+& F
\end{align}

renders like capture2024-08-10T14:52:51

because of LaTeXML.css:133

table.ltx_eqn_align tr.ltx_equation td.ltx_align_left + td.ltx_align_right { padding-left:3em; }

I'm not sure what it's trying to do.

orbita2d avatar Aug 10 '24 13:08 orbita2d

Note for any passers by with the same issue, it's straightforward to add a css stylesheet where you override this with a smaller padding.

https://math.nist.gov/~BMiller/LaTeXML/manual/usage/post/

orbita2d avatar Aug 10 '24 14:08 orbita2d

We may want to make the rule a little more context-aware than 3em. The tricky bit is - to which context? We can expect variable viewport width and variable number of aligned columns, which makes this a bit guessy...

A simple starting point is upgrading to a clamp targeting a percentage of the viewport (vw units). Something like:

padding-left: clamp(0.5em,1vw,3em);

dginev avatar Aug 10 '24 14:08 dginev

I'm not sure it needs padding at all in the cases where I use it (to align segments of equations as per example).

orbita2d avatar Aug 10 '24 15:08 orbita2d

I think LaTeXML is doing the right thing here, since the spacing you show is pretty consistent with what you'd get in a pdf with latex. The issue is that amsmath's align environment is designed to display multiple equations with each given as a pair of columns (lhs,rhs). Thus the alignment is like {rlrl...} but with a bit of extra horizontal space separating the "equations" (every 2nd column). A typical align would look like:

\begin{align}
  a &=b & b &=c \\
  c &=d & d &=e
\end{align}

You're kinda using an eqnarray-style, but with extra columns (which eqnarray sadly doesn't accept). I'm not sure what the ideal environment would be, depending on whether you want lines numbered, etc., but you'd get something somewhat presentable with:

\begin{equation}
\begin{array}{lcrcr}
  a &=& \cos\theta &+& \sin\theta \\
    &=& D &+& F\\
\end{array}
\end{equation}

brucemiller avatar Aug 10 '24 18:08 brucemiller

hmm, sorry about that, I tried to produce a minimal example and failed.

The difference I noticed was vs the alignat environment

\begin{alignat}{2}
A =& \cos\theta &+& \sin\theta \\
  =& D &+& F
\end{alignat}

Which behaves as I describe above (in pdflatex). The horizontal spacing rules are different between the two cases and I didn't confirm my understanding before posting, my mistake.

@brucemiller I can close this issue and reopen a new one if that's easier for tracking?

orbita2d avatar Aug 10 '24 21:08 orbita2d