jupyter-book
jupyter-book copied to clipboard
IPython.display with LaTeX does not render in book
Describe the bug
If I have a page with the following code:
# test
```{python}
from IPython.display import display, Markdown
display(Markdown('$y$'))
```
It renders correctly in the Jupyter notebook, with the $y$ rendered as LaTeX, but in the book, it renders as literal $y$. Should I expect this output not to render as LaTeX? Is there any workaround?
Reproduce the bug
git clone https://github.com/matthew-brett/minjb/
cd minjb
make
Inspect _build/html/test.html
List your environment
$ jupyter-book --version
Jupyter Book : 0.15.1
External ToC : 0.3.1
MyST-Parser : 0.18.1
MyST-NB : 0.17.2
Sphinx Book Theme : 1.0.1
Jupyter-Cache : 0.6.1
NbClient : 0.7.4
MacOS M2 Sonoma 14.0
To handle dollarmath (as this bug is about), I've found the following workaround:
import re
from latex2mathml.converter import convert
from IPython.display import display, Markdown
def handle_dollarmath(text):
replace_latex = lambda match: convert(match.group(1))
return re.sub(r'\$(.*?)\$', replace_latex, text)
display(Markdown(handle_dollarmath("*my markdown* $x^2$")))
Ideally, I think the markdown code inside a "display(Markdown" should be reinterpreted as MyST markdown during website compilation. This would allow the use of the same markdown syntax including admonitions and roles, but that would require a change in Jupyter book.