This tutorial assumes you have already installed MacTex, nbconvert, and pip/Anaconda onto your Mac.

Command to convert

Finally, you’ll run a command to convert the notebook into a PDF.

  1. Open up the Terminal app on your Macbook. (simply search for “Terminal” in Spotlight Search)
  2. Navigate to the location of your notebook. You can tell where your notebook is located by navigating back to the root of the Jupyter session. Your file path location will be something like: http://localhost:8837/tree/rest/of/filepath/here"
  3. cd into the directory containing your notebook. For example, if your notebook is in on your Desktop, you might type: cd Desktop. For more detailed instructions on how to change directories in the Terminal app, see this Macworld post.
  4. Within the directory that your notebook is in, type this command:
    • jupyter nbconvert --to pdf filename.ipynb - where you replace “filename.ipynb” with the name of the Jupyter notebook that you are trying to convert.
    • TIP: type this part of the command above: jupyter nbconvert --to pdf in the terminal. Then type the first few letters of the file you are trying to convert. After typing a few letters (3-4 should be enough) click the Tab button on your keyboard. The rest of the filename will auto-populate.
  5. Click Enter on your keyboard to run the command. You may see output such as the following:
[NbConvertApp] Converting notebook filename.ipynb to pdf  
[NbConvertApp] Writing 25817 bytes to notebook.tex  
[NbConvertApp] Building PDF  
[NbConvertApp] Running xelatex 3 times: ['xelatex', 'notebook.tex', '-quiet']  
[NbConvertApp] Running bibtex 1 time: ['bibtex', 'notebook']  
[NbConvertApp] WARNING | bibtex had problems, most likely because there were no citations  
[NbConvertApp] PDF successfully created  
[NbConvertApp] Writing 34935 bytes to filename.pdf  
(base) computer-name$ jupyter nbconvert --to pdf filename.ipynb   
[NbConvertApp] Converting notebook filename.ipynb to pdf  
[NbConvertApp] Writing 25817 bytes to notebook.tex  
[NbConvertApp] Building PDF  
[NbConvertApp] Running xelatex 3 times: ['xelatex', 'notebook.tex', '-quiet']  
[NbConvertApp] Running bibtex 1 time: ['bibtex', 'notebook']  
[NbConvertApp] WARNING | bibtex had problems, most likely because there were no citations  
[NbConvertApp] PDF successfully created  
[NbConvertApp] Writing 34940 bytes to filename.pdf  
  1. Using Finder, check the folder where your Jupyter notebook is located. You will now see a PDF has been generated and deposited to this folder.
  2. If you make an update to the Jupyter notebook, simply save the notebook and then run the command in Terminal again. It will overwrite the previously generated PDF.