5

I have different ANCIENT templates to convert a Jupyter notebook to a PDF, but starting from version 5.0 jupyter-nbconvert (at least, this is the name of the binary on Debian) uses XeLaTeX by default and, as it happens, some of those templates are fine when used with XeLaTeX, others still require pdfLaTeX.

I can use jupyter-nbconvert --to latex --template old_template MyNotebook and later run pdflatex from the CLI, and this is what I've done until now, but I wonder if there is a way to tell Jupyter that I want to use pdflatex.

I know that NBConvert has a configuration option,

PDFExporter.latex_command : List
Default: ['xelatex', '{filename}', '-quiet']

Shell command used to compile latex.

but I'd prefer something on the command line, so that I can define aliases to use a different TeX engine for different use cases.

gboffi
  • 22,939
  • 8
  • 54
  • 85
  • https://nbconvert.readthedocs.io/en/latest/config_options.html says "Configuration options may be set in a file, `~/.jupyter/jupyter_nbconvert_config.py`, _or at the command line when starting nbconvert, i.e. `jupyter nbconvert --Application.log_level=10`._" – Pranav Hosangadi Apr 09 '21 at 15:04
  • It looks like you can also specify a config file on the CLI (https://nbconvert.readthedocs.io/en/latest/config_options.html#cli-flags-and-aliases) Maybe you could define the `PDFExporter.latex_command` in a config file that you specify on the CLI just like you specify the template? – Pranav Hosangadi Apr 09 '21 at 15:07
  • @PranavHosangadi I'm reasonably confused about jupyter-related configuration, and I need a detailed, step-by-step, verifiable answer... Wouldn't you mind to provide such an answer? – gboffi Apr 10 '21 at 10:46

1 Answers1

3

PDFExporter.latex_command is indeed what you want; it corresponds to the command line option --PDFExporter.latex_command.

So, as converting TeX to a PDF using pdfLaTeX is done with the command pdflatex <file>, the list option PDFExporter.latex_command will need to be set to ['pdflatex', '{filename}']. This can be done from the command line by specifying the option twice:

jupyter-nbconvert \
    --to pdf \
    --PDFExporter.latex_command pdflatex \
    --PDFExporter.latex_command {filename} \
    MyNotebook.ipynb

The configuration system for jupyter-nbconvert (and other IPython / Jupyter tools) comes from a library called traitlets whose command line syntax is detailed here.

Josh Brobst
  • 1,772
  • 10
  • 16