Nbconvert Jupyter - Latex

431 views
Skip to first unread message

Thales Maia

unread,
Mar 21, 2017, 4:17:07 PM3/21/17
to Project Jupyter
Hi,

I'm intending to use jupyter for all my writing needs, but I'm having lot of trouble exporting to latex for my students.
I've made a tplx (jinja2) template to export my notebook and is working, but I'm having trouble to cross-reference my figures when exporting.

I need to set \label{fig:x} so latex can found it. Can someone please point a doc where I can found a solution?
I also have the same problem with equation and reference.

Mike Pacer

unread,
Mar 22, 2017, 1:36:06 PM3/22/17
to jup...@googlegroups.com
Hi Thales,

I've been thinking about this and the best solution I can think of would be to save the figures to disk, and explicitly invoke them with the traditional 

\begin{figure}
… 
\caption{ \label{fig:your-label} your caption.}}
\end{figure} 

I think should be able to do this with a simple markdown LaTeX invocation, but it may require using a nbconvert raw cell.

Note: this won't look good in the browser itself, but it will work on export. 

Other than that, this is something that we've been talking about how to implement for a while. The current thought is that we might want to create a new IPython Figure class that allows you to programmatically set this kind of metadata so that it is attached directly to your outputs. 

In terms of equations, you should be able to specify a label inside the equation \begin{equation} \label{eq:your-label} … \end{equation}. However, specifying a ref in line is somewhat more challenging. The problem is that MathJax (what we use in the notebook browser to display maths) only (ostensibly) surfaces math mode via its commands. As a result of that, everything that is captured by LaTeX that isn't a `\begin{blah}…\end{blah}` command is automatically assumed to be in math mode, and I do not believe that `\ref` (or better `\autoref` since we use the `hyperref` package in the default template) work inside math mode. I'll try to think about a better way to solve this…maybe using something like the data-attribute trick we use for citations (e.g., <a data-cite="pacer2015">(Pacer, 2015)</a>), because this should be possible.

Cheers,
M


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/79c2cdaf-a076-4a7e-a28c-f44a4d285e4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jfbercher

unread,
Mar 22, 2017, 7:45:55 PM3/22/17
to Project Jupyter
Hi, 
Perhaps that the jupyter_latex_envs extension can help. Its features include interpreting the figure environment in markdown cells, automatic numbering (of equations, figures, theorems like environments), support for figures labels and cross references documentwide. A figcaption function is also provided which enables to define a caption and label for generated figures, and use that when converting to LaTeX (a dedicated exporter is available). A documentation is available here: https://rawgit.com/jfbercher/jupyter_latex_envs/master/src/latex_envs/static/doc/latex_env_doc.html

Thales Maia

unread,
Mar 23, 2017, 5:03:56 PM3/23/17
to Project Jupyter
I appreciate your concern!

I found this old blog which tries to workaround this problem editing cell metadata, which I think not to be a problem.
http://blog.juliusschulz.de/blog/ultimate-ipython-notebook

The problem is that it doesn't work and I can't find a good reference to build jinja2 template for nbconvert and fix it!
I will try your suggestion and reply with the results.

Thanks


Em quarta-feira, 22 de março de 2017 14:36:06 UTC-3, Mike Pacer escreveu:
Hi Thales,

I've been thinking about this and the best solution I can think of would be to save the figures to disk, and explicitly invoke them with the traditional 

\begin{figure}
… 
\caption{ \label{fig:your-label} your caption.}}
\end{figure} 

I think should be able to do this with a simple markdown LaTeX invocation, but it may require using a nbconvert raw cell.

Note: this won't look good in the browser itself, but it will work on export. 

Other than that, this is something that we've been talking about how to implement for a while. The current thought is that we might want to create a new IPython Figure class that allows you to programmatically set this kind of metadata so that it is attached directly to your outputs. 

In terms of equations, you should be able to specify a label inside the equation \begin{equation} \label{eq:your-label} … \end{equation}. However, specifying a ref in line is somewhat more challenging. The problem is that MathJax (what we use in the notebook browser to display maths) only (ostensibly) surfaces math mode via its commands. As a result of that, everything that is captured by LaTeX that isn't a `\begin{blah}…\end{blah}` command is automatically assumed to be in math mode, and I do not believe that `\ref` (or better `\autoref` since we use the `hyperref` package in the default template) work inside math mode. I'll try to think about a better way to solve this…maybe using something like the data-attribute trick we use for citations (e.g., <a data-cite="pacer2015">(Pacer, 2015)</a>), because this should be possible.

Cheers,
M

On Tue, Mar 21, 2017 at 1:17 PM, Thales Maia <thale...@gmail.com> wrote:
Hi,

I'm intending to use jupyter for all my writing needs, but I'm having lot of trouble exporting to latex for my students.
I've made a tplx (jinja2) template to export my notebook and is working, but I'm having trouble to cross-reference my figures when exporting.

I need to set \label{fig:x} so latex can found it. Can someone please point a doc where I can found a solution?
I also have the same problem with equation and reference.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
Message has been deleted

Chris Sewell

unread,
Jul 10, 2017, 4:24:15 PM7/10/17
to Project Jupyter
FYI I've implemented this approach at https://github.com/chrisjsewell/ipypublish#latex-metadata-tags :)

Sean

unread,
Jan 11, 2018, 11:37:48 AM1/11/18
to Project Jupyter
I second the request for a link to some documentation about how to create Jinja2 templates for use with nbconvert

Thomas Kluyver

unread,
Jan 11, 2018, 11:48:52 AM1/11/18
to Project Jupyter
If you can use some of that to improve the nbconvert docs, go for it.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages