Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math equations do not render #1185

Open
awmp1 opened this issue Jan 6, 2024 · 4 comments
Open

Math equations do not render #1185

awmp1 opened this issue Jan 6, 2024 · 4 comments

Comments

@awmp1
Copy link

awmp1 commented Jan 6, 2024

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

@awmp1 awmp1 changed the title Math formular that are not inline do not render Math equations do not render Jan 6, 2024
@lornajane
Copy link
Contributor

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.

@RadeKornjaca
Copy link

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.

@sandeep026
Copy link

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)

@lornajane
Copy link
Contributor

Thanks for sharing your experience. We'd be happy to review a pull request to add improvements in this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants