38

I am new to ipython notebook, and I would like to convert my ipynb to pdf. But I get the following error when I try to Download as PDF via LaTex.

nbconvert failed: pdflatex not found on PATH

There is no documentation anywhere how to add pdflatex to my PATH. I use windows. Thank you!

Thomas K
  • 39,200
  • 7
  • 84
  • 86
Christa
  • 643
  • 2
  • 10
  • 17
  • 3
    Do you have Latex installed? If not, you need to install it, in the form of something like [MikTex](http://miktex.org/). If you do have it, there are instructions on changing the path [here](http://www.computerhope.com/issues/ch000549.htm). – Thomas K Apr 29 '16 at 13:44
  • 1
    @ThomasK Thank you! You mean to add the path of where miktex was installed? – Christa Apr 29 '16 at 20:40
  • 1
    It should install somewhere a `pdflatex.exe` file. PATH needs to include the directory that contains that. – Thomas K Apr 30 '16 at 08:08
  • I get `xelatex` instead of `pdflatex` – Soerendip Oct 26 '18 at 21:04
  • 1
    when I go to download Latex it says download MikTex so, my .exe says basic-miktex-2.9.6850-x64 - I have this in the same path as where my ipynb file is but it still does not work? – 0004 Nov 08 '18 at 07:03

9 Answers9

46

A simple and surprisingly good solution is to print the notebook to pdf through the browser with ctrl+p. Just make sure your plots and figures are not on interactive mode otherwise they will not be displayed (set them to %matplotlib inline).

Exporting jupyter notebooks through latex is quite troublesome and takes a lot of tinkering to get something remotely close to publish ready. When I absolutely need publication quality I do it on a latex editor, but this tutorial goes in great length about doing it on jupyter.

A few useful tips to get better results:

Frâncio Rodrigues
  • 2,190
  • 3
  • 21
  • 30
17

For Mac OS X, the solution for me was to install MacTex first and then export the path to find it:

### TeX
export PATH="/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:$PATH"

You can add this to your .bash_profile or similar config file to load it every time.

See more here https://github.com/jupyter/nbconvert/issues/406

tsando
  • 4,557
  • 2
  • 33
  • 35
14

As said by Thomas K in the comments, you need to have Latex installed, and after add the path to the directory containing pdflatex.exe file to the PATH variable of your system.

I have looked for a lightweight distribution and tried installing TeXworks, but I didn't find any pdflatex.exe file.
So I have tried TeX Live, which worked fine creating the pdflatex.exe file under the target installation directory. This path should be like C:\...\texlive\2016\bin\win32.
Finally, you should just add this path to the PATH environment variable of your system (you can use the link shared by Thomas K).

As said here, you need to quit jupyter notebook and open a new command prompt after making any path changes, in order for jupyter to find the newly added item to the PATH.

Then, in Jupyter, you can check your environment variables by running the following (refer to this link for details):

    import os
    os.environ['PATH'].split(';')

and check if it contains the path to pdflatex.exe file.

If you get some trouble when exporting your notebook to pdf due to missing files/packages (this happened to me), refer to this link to search and install them under TeX Live.

Ferd
  • 1,273
  • 14
  • 16
jmeloc
  • 198
  • 2
  • 10
12

For Linux, the reported error is due to the lack of XeLatex, part of the texlive-xetex package.

Installation in ubuntu will be: sudo apt install texlive-xetex

calocedrus
  • 2,430
  • 20
  • 25
7

Instead of using nbconvert what you can do is :

  1. Download your ipynb file as HTML from File option.
  2. Right-click and select print or use Ctrl+P.
  3. Save as PDF

Easy.

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
Aditya Agarkar
  • 119
  • 1
  • 4
3

Here is the full solution that worked for me (for Mac).

brew cask install mactex

$ cd ~/

$ touch .bash_profile

This will open the bash profile on TextEditor

$ open -e .bash_profile

Paste the following to the top and save

export PATH="/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:$PATH" 

Close any notebook you have and reopen it

Here is the notebook explaining it step by step: https://github.com/ybaktir/notes/blob/master/Convert%20Jupyter%20Notebook%20to%20Pdf.ipynb

1__
  • 1,511
  • 2
  • 9
  • 21
1

I agree that latex installation (at least on windows) is painful and the result in my case was not a great looking document. The ctrl-p method alone doesn't work great if you're running in JupyterLab, but if you export the notebook to HTML, then print from the browser, choosing PDF, the result is quite good.

CheapSquier
  • 427
  • 4
  • 4
1

I know my solution is not at a level. But it works !!

in your browser of notebook tab, simply do "ctrl + p" to get download in pdf

Qbert
  • 326
  • 3
  • 5
1

First export the notebook file to HTML (available through File> Download as..).
If you are using JupyterLab, then this is available under File > Export Notebook As....
Use (any) free online converters to convert html file to a pdf file. (One such free online converter is sejda (https://www.sejda.com/html-to-pdf)

Note, there are many such converters are available online.