chrisjsewell / ipypublish

A workflow for creating and editing publication ready scientific reports and presentations, from one or more Jupyter Notebooks, without leaving the browser!
http://ipypublish.readthedocs.io
BSD 3-Clause "New" or "Revised" License
224 stars 37 forks source link

Complex/Multiline Equations do not render properly in html_ipypublish_main #104

Closed netzdoktor closed 5 years ago

netzdoktor commented 5 years ago

Bug Report

Description

The ipypublish pipeline parses MathJax + Markdown in a different way than Jupyter, which means that more complex formulas do not render.

To Reproduce

Use the minimal notebook provided below and run nbpublish -f html_ipypublish_main multiline-equation.ipynb --outpath=$(pwd)/

Minimal Notebook Example

multiline-equation.ipynb.txt

Expected Behaviour

I would expect that the formula renders nicely, much like it does in Jupyter.

Runtime Information

chrisjsewell commented 5 years ago

Hey @Darneas thanks for the report.

Looking at the output HTML, it seems that for some reason it is removing the \begin{array} and \end{array}.

I'll try and get round to looking at this, but I would note, as I've recently discussed with @parmentelat (see https://github.com/chrisjsewell/ipypublish/issues/91#issuecomment-514423122 and https://github.com/chrisjsewell/ipypublish/issues/101#issuecomment-522299874), that in essence I have deprecated the HTML converter, in favor of using the ipypublish.sphinx.notebook extension. So I would encourage you to have a look at this approach.

I've just committed a fix for the sphinx approach in 909f3c30ae848435a9b31e7db218825f91752edd v0.10.9 (which I'm in the process of releasing), so that you can essentially achieve the same conversion using:

nbpublish -f sphinx_ipypublish_main.run -lb multiline-equation.ipynb

and the formula is rendered correctly.

netzdoktor commented 5 years ago

Hey @chrisjsewell,

thanks for the quick reply. I also recognized that this gets stripped, but I don't know why your ipypublish+Pandoc is different from what Jupyter Notebook/Lab does to render the math.

In Sphinx it works, but various other things do not work (e.g. intra- and cross-notebook navigation). I am basically adapting Prof. Zeller's work (https://www.fuzzingbook.org/) to our needs (http://www.nt.uni-saarland.de/). I especially like the html conversion to a webpage with proper navigation. I have tried the last hours to get a cross-notebook navigation working with Sphinx, but couldn't.

Unfortunately, we have a lot of complex formulas that do not render properly. So I would actually prefer to have a plain HTML conversion.

chrisjsewell commented 5 years ago

The fault lies in: https://github.com/chrisjsewell/ipypublish/blob/28ff4b3b2ca986e1c697f2f45f5d83f76d894abe/ipypublish/preprocessors/latextags_to_html.py#L40

which strips latex tags it cannot convert, but should obviously ignore any found within math enclosures ($$...$$, \\[...\\], \\(...\\), $...$).

If you copy html_ipypublish_main.json and remove:

https://github.com/chrisjsewell/ipypublish/blob/28ff4b3b2ca986e1c697f2f45f5d83f76d894abe/ipypublish/export_plugins/html_ipypublish_main.json#L35-L38

you can use this as the conversion format, and the array tags will not be stripped.

nbpublish -f path/to/html_ipypublish_main.json multiline-equation.ipynb --outpath=$(pwd)/

In Sphinx it works, but various other things do not work (e.g. intra- and cross-notebook navigation)

Can you give me an example of what you mean by intra/cross-notebook navigation? To my mind, this is generally what Sphinx excels at

netzdoktor commented 5 years ago

Thanks. Removing that converter solved my problem (also an pre-v0.7 py-plugin over here: https://github.com/uds-se/fuzzingbook/blob/master/ipypublish_plugins/html_ipypublish_chapter.py). I will consider migrating to 0.7 in the near future.

Regarding Sphinx: When I ran the command you provided (sphinx_ipypublish_main.run) it did not fill the sidebar nicely. Maybe I got something wrong and need more configuration. I will follow up somewhere else when I need it).