roniemartinez / latex2mathml

Pure Python library for LaTeX to MathML conversion
MIT License
183 stars 25 forks source link

bmatrix/Bmatrix/vmatrix/Vmatrix/cases render short symbol #296

Closed retsyo closed 2 years ago

retsyo commented 2 years ago
\begin{bmatrix}  1 & 2 & \cdots \\  67 & 95 & \cdots \\  \vdots & \vdots & \ddots \\ \end{bmatrix}

CodeCogsEqn

but it should be CodeCogsEqn

retsyo commented 2 years ago

\begin{vmatrix} 1 & 2& 3 \\ 4 & 5& 6\\ \end{vmatrix} is bad too CodeCogsEqn

retsyo commented 2 years ago

\begin{Bmatrix} 1 & 2\\ 3 & 4\\ 5 & 5\\ \end{Bmatrix}

\begin{Vmatrix} 1 & 2 & 3\\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \end{Vmatrix}

\left\{\begin{matrix} 1 & 2\\ 4 & 5\\ 6 & 7\\ \end{matrix}\right.

\left.\begin{matrix} 1 & 2\\ 3 & 4\\ 5 & 6\\ \end{matrix}\right|

all have short symbol

retsyo commented 2 years ago

and \begin{cases} x & \text{ if } x=1 \\ x+1 & \text{ if } x=2 \\ x+2 & \text{ if } x=3 \end{cases}

roniemartinez commented 2 years ago

It looks like all the rendering issue here like short brackets and spaces on accents are a problem with MS Word because all the outputs are working properly with Mathjax which is always my source of truth. I always try to compare the one generated by latex2mathml.

image

@retsyo can you also verify? I am both using Mathjax and Katex as reference for correct output. MS Word probably does not support these.

retsyo commented 2 years ago

then could you please give some suggestion on writing kinds of matrix in DOCX?

since I and some other users(like stated on https://github.com/python-openxml/python-docx/issues/320) use latex2mathml to write equation in DOCX.

roniemartinez commented 2 years ago

@retsyo Would it be an option to add SVG or PNG to docx files instead of raw MathML? There is a library that uses latex2mathml output and convert them to SVG/PNG called ziamath.

I would also try to take a look and find more options.

EDIT: Reference - https://ziamath.readthedocs.io/en/latest/usage.html#drawing-equations

retsyo commented 2 years ago

Thanks, to insert a pic is valid for DOCX, this is what I did if there is only few equation before. Then I found the metioned https://github.com/python-openxml/python-docx/issues/320 which try to convert latex equation string and insert as Ms Word equation

I tested https://ziamath.readthedocs.io/en/latest/, and found that

  1. https://ziamath.readthedocs.io/en/latest/ does not support some features missing in latex2mathml too, for example, \xleftarrow[abc]{hello}, \overbrace{1+2+\cdots+n}^{there are n} \qquad \underbrace{a+b+\cdots+z}_{26}, \left.\begin{matrix} 1 & 2\\ 3 & 4\\ 5 & 6\\ \end{matrix}\right|

  2. on my windows 10 64 bits, I can't make cairosvg runs on python 3.8, but it runs on python 3.6; however, https://ziamath.readthedocs.io/en/latest/ runs on python 3.8, but does not runs on python 3.6. So I use 2 versions of python to convert latex string to equation image

btw, to use a real equation could be still a better solution which has been requested many times on https://github.com/python-openxml/python-docx

roniemartinez commented 2 years ago

@retsyo

  1. Yes, because ziamath depends on latex2mathml. If the support is added here, it should be reflected in ziamath.
  2. That could be an issue. I am not sure any alternative or fix to cairosvg

Then I found the metioned https://github.com/python-openxml/python-docx/issues/320 which try to convert latex equation string and insert as Ms Word equation

Did you try the stylesheet used in the link? That will probably solve some of the rendering issues that you encountered.

roniemartinez commented 2 years ago

Did you try the stylesheet used in the link?

It looks like you did in https://github.com/roniemartinez/latex2mathml/issues/287#issuecomment-1085438838. I am not really sure of other solution other than using ziamath.

As for cairosvg, they have Python 3.6+ stated on their README. Maybe you can open a ticket in their project repo: https://github.com/Kozea/CairoSVG

roniemartinez commented 2 years ago

Closing this issue. Please read my comment in https://github.com/roniemartinez/latex2mathml/issues/287#issuecomment-1093470723