Stream: jupyterlab-hub

Topic: Exporting notebook to PDF


view this post on Zulip Danica Lombardozzi (Dec 15 2020 at 21:34):

Does anyone have experience exporting Jupyter notebooks to PDF? I found information to do this (https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex), although it seems to require the use of 'sudo' (sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-generic-recommended), which I believe we are not encouraged (or allowed?) to do on Cheyenne or Casper.

view this post on Zulip Deepak Cherian (Dec 15 2020 at 22:00):

you could sync to your local machine and do it there. I haven't done it on CISL systems

view this post on Zulip Michael Levy (Dec 15 2020 at 22:04):

Alternatively, it looks like texlive is on conda: https://anaconda.org/conda-forge/texlive-core so

$ conda install -c conda-forge texlive-core

might be enough (I'm not familiar with it, so I don't know if xetex and those fonts are needed... if so, there's a chance they're included in -core on conda)

view this post on Zulip Michael Levy (Dec 15 2020 at 22:06):

I think you'd want to install that package in a new environment rather than the one you run the notebook in, so maybe

$ conda create -c conda-forge --name nb_to_pdf texlive-core

would be a better suggestion

view this post on Zulip Danica Lombardozzi (Dec 15 2020 at 22:55):

Thanks @Michael Levy ! I installed the new environment as suggested, but I can't figure out how to use it. I typically use JupyterHub and restarted my session but don't see it available as a kernel. I can activate it on Cheyenne, but I'm not sure how to open and convert a notebook from the command line. Any suggestions?

view this post on Zulip Danica Lombardozzi (Dec 15 2020 at 23:00):

A quick follow up: I did try jupyter nbconvert --to pdf notebook.ipynb, but got an error message that I need to install xelatex (OSError: xelatex not found on PATH, if you have not installed xelatex you may need to do so.). You had mentioned that they may be in -core on conda, but I'm not sure how to check and potentially use this.

view this post on Zulip Michael Levy (Dec 15 2020 at 23:32):

It looks like there's a texlive-selected package: https://anaconda.org/pkgw/texlive-selected that might include xetex but I can't find any documentation on it (also, I don't know what the pkgw/label/superseded channel is)

$  conda install -c pkgw/label/superseded texlive-selected

view this post on Zulip Michael Levy (Dec 15 2020 at 23:35):

Hmm, pkgw might be a person, and he says

The set of Texlive packages in my texlive-selected recipe has enough to run nbconvert

https://github.com/conda-forge/texlive-core-feedstock/issues/3#issuecomment-227024540

but that's pretty vague...

view this post on Zulip Michael Levy (Dec 15 2020 at 23:36):

I'm beginning to think that my suggestion to bring in texlive via conda was a bad one, sorry

view this post on Zulip Michael Levy (Dec 15 2020 at 23:37):

Have you tried the texlive module that CISL is maintaining? Does it have xelatex?

$ module spider texlive

--------------------------------------------------------------------------------------------------------
  texlive: texlive/2018
--------------------------------------------------------------------------------------------------------

    This module can be loaded directly: module load texlive/2018

view this post on Zulip Anderson Banihirwe (Dec 15 2020 at 23:47):

@Danica Lombardozzi, in case the PDF creation via Latex option doesn't work, you may find the notebook-as-pdf package to be an easier alternative. It doesn't require Latex and is easy to set up:

conda create -c conda-forge --name nb_to_pdf jupyterlab pip
conda activate nb_to_pdf
conda install -c conda-forge jupyterlab pip
python -m pip install -U notebook-as-pdf
pyppeteer-install
jupyter-nbconvert --to PDFviaHTML mynotebook.ipynb

view this post on Zulip Danica Lombardozzi (Dec 16 2020 at 00:10):

Thanks @Anderson Banihirwe ! That did the trick! I appreciate all the help from both you and @Michael Levy !

view this post on Zulip Anderson Banihirwe (Dec 16 2020 at 00:12):

Of course! Glad it was successful


Last updated: May 16 2025 at 17:14 UTC