cdelker / ziamath

MIT License
20 stars 1 forks source link

\begin{aligned}...\end{aligned} extra blank line and aligning with & #50

Open pozitron57 opened 1 year ago

pozitron57 commented 1 year ago
  1. \left[
    \begin{aligned}
    F = mg\sin\alpha,  \mu \geqslant \tg\alpha \\
    F = \mu mg\cos\alpha, \mu < \tg\alpha
    \end{aligned}
    \right.

Ziamath adds an extra blank line: image

Xelatex: image

  1. Aligning with &
\left[
\begin{aligned}
  F &= mg\sin\alpha,  &\mu \geqslant \tg\alpha \\
  F &= \mu mg\cos\alpha, &\mu < \tg\alpha
\end{aligned}
\right.

Xelatex: image

Ziamath:

Traceback (most recent call last):
  File "/Users/slisakov/Yandex.Disk.localized/documents/1514/physics/phys.pro/zm.py", li
ne 13, in <module>
    eq=zm.Math.fromlatex(formula).svg()
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/slisakov/Library/Python/3.11/lib/python/site-packages/ziamath/zmath.py",
line 125, in fromlatex
    return cls(mathml, size, font)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/slisakov/Library/Python/3.11/lib/python/site-packages/ziamath/zmath.py",
line 95, in __init__
    mathml = ET.fromstring(mathml)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/l
ib/python3.11/xml/etree/ElementTree.py", line 1338, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 151

shell returned 1
cdelker commented 1 year ago

The aligned environment seems to be ignored by latex2mathml, but it understands array, which fixes the exception and vertical shift. Adding {lll} after \begin{array} left-aligns the array columns. So one workaround is this:

\left[ \begin{array}{lll} F &= mg\sin\alpha, &\mu \geqslant \tg\alpha \ F &= \mu mg\cos\alpha, &\mu < \tg\alpha \end{array} \right.

image

cdelker commented 1 year ago

The \begin{align*} environment also seems to work correctly:

image

pozitron57 commented 1 year ago

Thanks, but note the extra space before the = sign. In this particular case one can just omit the & symbol before =, but space should not be there. Xelatex doesn't add it in aligned environment.

cdelker commented 1 week ago

b2d6a7bf2f58c69bf9df4c53e6c27b6d9fe89bec and c87b32c5dfd12ed3831460a00f03e5cb7e09cb6a should address the issues in this one.