dexplo / jupyter_to_medium

Python package for publishing Jupyter Notebooks as Medium blogposts
https://dexplo.org/jupyter_to_medium
MIT License
147 stars 14 forks source link

No support for LaTex #16

Closed kurtispykes closed 3 years ago

kurtispykes commented 4 years ago

When deployed to Medium, LaTex text is not parsed as an image.

Result given when deployed to Medium

latex
tdpetrou commented 4 years ago

Thanks for adding this. Will add to the roadmap and get to it at a later time.

rparraca commented 4 years ago

Thank you @kurtispykes for adding this... I was going to add the same issue.

@tdpetrou I'd be happy to take a look at it and help if help is needed/welcomed =)

mjam03 commented 3 years ago

I had a go yesterday at doing this and it turns out it's:

I tried various solutions like this one - identify latex then use matplotlib to .png it then embed as image but this will only really work for a cell completely occupied by latex.

It's not going to work for cells where I talk about '$x$' or '$y$' and want the latex to be embedded with the text. I haven't yet found a solution that beats unfortunately using the medium editor and screenshot-ing the rendered latex from a notebook. Even this method prevents the ability to mix latex and text in a single markdown cell.

Have you seen anywhere else in the last 6 months that handles this well or can point me to any stuff? Would be happy to do some more research and try to implement.

martinlarsalbert commented 3 years ago

Building on the idea from @mjam03 I used Matplotlib to render the LaTeX so that it will be saved as inline figures in the notebook, and will consequently be send to Medium. Here is an example.

This means that you will need to modify your notebook to get this to work, which is not ideal, but still easier than the manual work in generating the equations as images. And as mentioned above this will not work for the markdown inline equations.

I don't know if there is some elegant way to automate something like this in the present package (which I find great by the way! :)

mjam03 commented 3 years ago

I've had another look at this one and think I can manage it. The idea will be modest at first and will only work for cells which are pure Latex i.e. not '$x$' embedded in amongst other text but a cell which contains only '$$mathjax_latex_code$$'. Will see if I can sort it tomorrow but will be doing the following:

I'll give it a go and see how it turns out - if it works well then it's a nice way to avoid having to amend the notebook to have inline figure as @martinlarsalbert has suggested. If not then I'll explore if we can merge that idea in as having support for latex would be really nice.

mjam03 commented 3 years ago

I think I've managed it. It's limited in scope but it seems to work pretty well. The following is what I did (I'll write some documentation for it and do a proper release to PyPI this week):