Math equations do not render
awmp1 opened this issue · 4 comments
Description of problem
Using math, it appears that there is a problem with the way that the string is processed within the function math_flowable.py.
I haven't been able to work out what the issue is (my Python isn't that great) but it has to do with the $ sign as far as I can tell.
ParseException: Expected end of text, found '$' (at char 0), (line:1, col:1)
[ERROR] math_flowable.py:109 Math error:
$\frac{q}{\sqrt{g H_{m 0}^{3}}}=0.011\left(\frac{H_{m 0}}{h
Have tried several math equations but none seem to render. They do render if they are marked for in-line.
🖥 Versions
0.101
python -V3.11.6
Thanks @awmp1 for the bug report. Can you give an example of a simple source file that produces this problem? The math support is far from perfect but we can take a look.
Hi @awmp1, I was looking for a similar issue with the equations not rendering in the newer versions of rst2pdf, but then I realized that I when I upgraded Python version recently, I didn't install matplotlib. Make sure you have it by running
pip install matplotlib
Also, when writing LaTeX equations in ReStructured Text, they do not start with the dollar sign, for example:
.. class:: center
.. math::
P = \sqrt {s * (s - a) * (s - b) * (s - c)}
I add the center class for my equations to be centered. If that's not what you want, you can ignore the first line.
Has this been fixed ? I am not able to render math equation. Will there be multiline support in future?
This a math directive
---------------------
.. math::
\begin{align}
a + b &= c \\
d + e &= f \\
g + h &= i
\end{align}
[ERROR] math_flowable.py:58 rst2pdf's math directive does not support multiple lines'
[ERROR] math_flowable.py:68 Math error in wrap:
$\\\begin{align}
^
ParseException: Expected end of text, found '$' (at char 0), (line:1, col:1)
[ERROR] math_flowable.py:109 Math error:
$\\\begin{align}
^
ParseException: Expected end of text, found '$' (at char 0), (line:1, col:1)
[ERROR] math_flowable.py:110 Math error!
Traceback (most recent call last):
File "C:\Users\Sandeep\Downloads\rst2pdf\rst\Lib\site-packages\rst2pdf\math_flowable.py", line 89, in drawOn
(width, height, descent, glyphs, rects,) = self.parser.parse(
^^^^^^^^^^^^^^^^^^
File "C:\Users\Sandeep\Downloads\rst2pdf\rst\Lib\site-packages\matplotlib\mathtext.py", line 79, in parse
return self._parse_cached(s, dpi, prop, antialiased)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Sandeep\Downloads\rst2pdf\rst\Lib\site-packages\matplotlib\mathtext.py", line 100, in _parse_cached
box = self._parser.parse(s, fontset, fontsize, dpi)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Sandeep\Downloads\rst2pdf\rst\Lib\site-packages\matplotlib\_mathtext.py", line 2173, in parse
raise ValueError("\n" + ParseException.explain(err, 0)) from None
ValueError:
$\\\begin{align}
^
ParseException: Expected end of text, found '$' (at char 0), (line:1, col:1)
Thanks for sharing your experience. We'd be happy to review a pull request to add improvements in this area.