NBConvert to PDF: works from command line, doesn't work from Notebook Interface



I’m trying to get the notebook -> LaTeX -> PDF conversion to work on a Windows 10 environment with

  • Jupyter 4.4.0 with
    • nbconvert 5.4.1; and
    • nbextensions 0.5.1
  • Pandoc
  • Anaconda 4.6.14
  • Python 3.7.3
  • MiKTeX 2.9

I was able to get it to work on the command line ( jupyter nbconvert notebook.ipynb --to pdf). At first I received an error saying xelatex was not on the PATH. After some investigation, I determined that the issue was with my MiKTeX path, which has a Unicode character on it. In order to solve that, I

  1. set up a directory junction C:\Users\example (no Unicode chars) to point to C:\Users\exãmple; and
  2. used ~\.jupyter\jupyter_nbconvert_config.py to point to the non-Unicode paths:
    c.PDFExporter.latex_command = [ r'C:\Users\example\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\xelatex.exe', '{filename}']
    c.PDFExporter.bib_command = [ r'C:\Users\example\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\bibtex.exe', '{filename}']

However, when converting from the Notebook interface (clicking on menu File -> Download as -> PDF via LaTeX), the conversion fails with a xelatex not on PATH error, the same as when initially trying to convert from the command line. So it seems as though nbconvert ignores the configuration file when called from the interface.

Do you guys have any tips on how to get the PDF conversion from the interface to work?



I have found this solution for me. This code snippet build a pdf file from the JupyterLab. If you use Docker you can take a look at my https://hub.docker.com/r/joergklein/jupyterhub repo. I will make an update in one hour with some additional Latex packages.


kable(alpha, format = "html", caption = "Caption", longtable = TRUE) %>%
kable_styling(c("striped", "bordered", "hover", "condensed", "responsive"), full_width = F, font_size = 12 ) %>%
save_kable(file = "alpha.html")
as.character() %>%

pandoc('alpha.html', format='latex')
1 Like