On dealing documents with images using Jupyter Notebook, we can easily find that the default export to PDF selection will produce the PDF without any images. While as on the GitHub Issue page many suggest the method of exporting to Tex first and then convert it to PDF with xelatex manually, simply exporting to Tex and compile it to PDF without any modification will not work.

In this article I would like to share a working solution that works for me.

Let’s first talk about the error on generating those PDFs.

In the Tex version of export, the images are rendered as the following line:

\includegraphics{https://i.loli.net/2018/11/12/5be9911b5d95a.png}

Compiling with the file like this will most likely to produce the problem as below:

LaTeX Warning: File https://i.loli.net/2018/11/12/5be9911b5d95a.png' not found
on input line 407.

! Unable to load picture or PDF file 'https://i.loli.net/2018/11/12/5be9911b5d9
5a.png'.
}
l.407 .../i.loli.net/2018/11/12/5be9911b5d95a.png}

Importing Images in Jupyter Notebook

Looks good in Jupyter Notebook, but will still meet errors in compile stage.

LaTeX Warning: File attachment:1c8573bf621ef3a18687ad4aeb50df32.jpg.png' not f
ound on input line 409.

32.jpg.png'.
}

Current Solution

The current solution that works for me is to export the Notebook to Tex, then manually dealing with the images (and document title, author, date as well) in the Tex file, as an example, I place the image in the path ./images/enron.jpg to the exported Tex file, then replace the wrong image path generated by Jupyter Notebook to the form as below:

\begin{figure}
\centering
\includegraphics{images/enron}
\caption{Visualized Data of Enron Database.}
\end{figure}

Then use xelatex to compile the Tex file.

278 Words

2018-11-23 19:01 +0800