barrysteyn / pelican_plugin-render_math

A plugin for the pelican blog to allow it render mathematics in Latex.
67 stars 25 forks source link

MathJax javascript not inserted in translations #26

Closed lsandig closed 9 years ago

lsandig commented 9 years ago

Hello. When an article has a translation, the mathjax <script> will only be inserted in the original. You can test this with the following MWE (DEFAULT_LANG='de' in pelicanconf.py):

File "mj_test_de.rst"

MathJax Test
############

:slug: mj-test
:lang: de

Hallo Welt!

:math:`a^2+b^2=c^2`

File "mj_test_en.rst"

MathJax Test
############

:slug: mj-test
:lang: en

Hello World!

:math:`a^2+b^2=c^2`

In both cases the inline math will be wrapped in <math> tags, but only the "de" version gets the mathjax javascript and renders accordingly. The "en" translation just shows the LaTeX code.

barrysteyn commented 9 years ago

This seems like a problem with RST. Can you try the above with Markdown? If it produces a problem, then I can fix it.

But I suspect in this case, you will need to insert the mathjax script into the template manually. Look for one of the options (check the README) for what I mean.

I am going to close this issue, but if you have the same issue with Markdown, please re-open

lsandig commented 9 years ago

As you suspected it works with Markdown. I will try to work around this in my templates. Thanks for the quick reply!

barrysteyn commented 9 years ago

Hi @lsandig

Unfortunately, it is a deficiency in RST. If you like, try making contact with the makers of RST and ask them to fix this. Thanks for the info regarding the markdown, now I can breathe easier.

lsandig commented 9 years ago

Hi @barrysteyn I think I found a fix: In line 336 of math.py you are looping through all ArticlesGenerator.articles

for article in generator.articles:
    rst_add_mathjax(article)
    # [snip]

But this list only contains original language articles, translations are kept separately in ArticlesGenerator.translations Looping through both of them made it insert the mathjax_script also in translated articles for me:

for article in generator.articles + generator.translations:
    rst_add_mathjax(article)
    # [snip]

I hope this helps (although my knowledge of the pelican internals is limited).

barrysteyn commented 9 years ago

Hi @lsandig

Thanks for this. Why does it still work in Markdown though? If I roll out a fix, can you test it for me?

barrysteyn commented 9 years ago

@lsandig

I have made your requested change, can you look at it and tell me if things are kosher. If you are happy, I will submit it to the official pelican plugin repo.

lsandig commented 9 years ago

@barrysteyn I just tested your change and it works. Thanks again!