Jupyter notebook: typeset formulas in pdf-export

190 views
Skip to first unread message

Daniel Krenn

unread,
Mar 22, 2017, 7:32:10 AM3/22/17
to sage-...@googlegroups.com
In a Jupyter notebook, when I do
File --> Download as --> PDF via LaTeX
then typeset formulas (displayed via show(...) command) are not typeset
anymore, but displayed as their plain text output in the pdf.

Is this a problem of our SageMath-LaTeX typesetting or a problem of the
jupyter notebook?

Best

Daniel

Eric Gourgoulhon

unread,
Mar 22, 2017, 8:52:00 AM3/22/17
to sage-devel
Hi,

This is a long standing problem, see e.g. this sage-support post. I have no clue how to fix it, but it would be highly desirable to have a solution in Sage 8.0, when Jupyter is becoming the default notebook.

Best wishes,

Eric.
 

Nils Bruin

unread,
Mar 22, 2017, 3:27:15 PM3/22/17
to sage-devel

I think it's the latter, although perhaps one should blame how we supply our info. By the time you're selecting that option, I think you're just running jupyter-nbconvert, which just works with the ipynb file; there's no kernel/state to query otherwise.

For instance, "show(x^2)" leads to this json fragment:

   "outputs": [
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}x^{2}</script></html>"
      ],
      "text/plain": [
       "x^2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "show(x^2)"
   ]

As you can see, the output is available in two representations: text/plain and text/html. It doesn't surprise me that ipynb-to-latex conversion doesn't try to untangle HTML.

The %%latex special inserts a "text/latex" mimetype entry. This does get rendered properly in html in my browser and it makes export->PDF produce an error because "pandoc" is not installed. So this seems to be a route that may make cells more latex-friendly. I don't know what the protocol is exactly, but I suspect our kernel can respond with various mimetypes when reporting back output. Using "text/latex" rather than "text/html" might lead to better results sometimes?

Eric Gourgoulhon

unread,
Jun 27, 2017, 10:33:31 AM6/27/17
to sage-devel
Hi,

As Jupyter is becoming the default notebook in Sage 8.0, I guess it would be nice to fix this, otherwise many users could be quite disappointed when getting such a bad pdf export of their notebooks.
I've opened the ticket
https://trac.sagemath.org/ticket/23330
although I've no clue how to proceed. According to Nils' explanation, this could be on the Jupyter side...

kcrisman

unread,
Jun 28, 2017, 8:06:16 AM6/28/17
to sage-devel


As Jupyter is becoming the default notebook in Sage 8.0,

Though as Jeroen points out, technically the default is the export functionality from sagenb to Jupyter ...
Reply all
Reply to author
Forward
0 new messages