Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimum Tex package install for converting Jupyter notebooks to PDFs #1328

Open
ttimbers opened this issue Jul 17, 2020 · 3 comments
Open

Minimum Tex package install for converting Jupyter notebooks to PDFs #1328

ttimbers opened this issue Jul 17, 2020 · 3 comments
Labels

Comments

@ttimbers
Copy link

My students and I are constantly going back and forth between R & Python, and Jupyter and RStudio for our work. We have found that there is an excellent project, TinyTex that gives enough TeX packages to render from .md/.Rmd to .pdf and is only 150Mb in size! This serves us very well in our RStudio work, and I have started to use this with Jupyter as well. However, there are ~ 16 additional packages that I have found needed for this to work, in addition to the TinyTex base install (listed below).

Here, in the TinyTex repo, I am suggesting that I will submit a PR to create a helper function/file to make these 16 additional packages easy to install. However, before I do this, the TinyTex team and myself want to know if somewhere there already exists a minimum set of required TeX packages to render a Jupyter notebook to PDF?

Also, once we incorporate this PR into TinyTex, perhaps nbconvert might want to consider using the TinyTex install for Tex packages for CI instead of installing all of Tex Live? Just an idea I thought I would toss out.

Packages that need to be installed in addition to TinyTex for it to work with Jupyter:

tlmgr install adjustbox \
  caption \
  collectbox \
  enumitem \
  environ \
eurosym \
  jknapltx \
  parskip \
  pgf \
  rsfs \
  tcolorbox \
  titling \
  trimspaces \
  ucs \
  ulem \
  upquote 
@t-makaro
Copy link
Contributor

We don't install LaTeX automatically as a dependency since is it so large, and many users have their own preferences. I personally use MikTeX because I like the on-the-fly package installation.

However, I would absolutely welcome a PR updating our documentation here: https://github.com/jupyter/nbconvert/blob/master/docs/source/install.rst for how to install LaTeX using TinyTex.

There is not a minimum spec listed. You'd have to look directly at the different templates to find them all, and it is subject to change. For example, the ucharclasses package might be added if I manage to figure out how to use it to improve our unicode support.

@t-makaro t-makaro added the docs label Jul 28, 2020
@kirelagin
Copy link

I guess an actionable point here is to have a complete list of TeX packages required.

@yuvipanda
Copy link
Contributor

Here's the minimum list needed now:

tlmgr install adjustbox caption collectbox enumitem environ eurosym etoolbox jknapltx parskip \
      pdfcol pgf rsfs tcolorbox titling trimspaces ucs ulem upquote \
      ltxcmds infwarerr iftex kvoptions kvsetkeys float geometry amsmath fontspec \
      unicode-math fancyvrb grffile hyperref booktabs soul ec

I wrote this janky script to help me:

import sys
import subprocess

outfile = open("packages", "a")

while True:
    convert = subprocess.run(["jupyter", "nbconvert", "--to", "pdf", "Untitled.ipynb"], capture_output=True)
    if convert.returncode == 0:
        break
    print(convert.stdout)
    print(convert.stderr)
    for l in convert.stderr.decode().split("\n"):
        if not l.startswith('! LaTeX Error: File'):
            continue
        missing = l.split(' ')[4]
        missing = missing.strip("'").strip("`")
        missing = missing.split(".")[0]
        outfile.write(f"{missing}\n")
        subprocess.check_call(["tlmgr", "install", missing])

It won't work for everything (it didn't catch ec) but otherwise it tries to convert a .ipynb file, finds the missing package, installs it, keeps a note of the installed package, and tries again.

yuvipanda added a commit to yuvipanda/rocker-versioned2 that referenced this issue Oct 18, 2023
Per jupyter/nbconvert#1328, these
are the packages needed for Jupyter to be able to convert
to PDF. Without it, you get unfriendly errors like [this]
(2i2c-org/infrastructure#3188 (comment)).

Given that the binder image includes jupyter, and texlive is included
in the base, I hope it would be reasonable for the binder image
to include enough texlive packages for PDF conversion to work.
Otherwise, it works in RStudio but not in Jupyter.
yuvipanda added a commit to yuvipanda/rocker-versioned2 that referenced this issue Oct 18, 2023
Per jupyter/nbconvert#1328, these
are the packages needed for Jupyter to be able to convert
to PDF. Without it, you get unfriendly errors like [this]
(2i2c-org/infrastructure#3188 (comment)).

Given that the binder image includes jupyter, and texlive is included
in the base, I hope it would be reasonable for the binder image
to include enough texlive packages for PDF conversion to work.
Otherwise, it works in RStudio but not in Jupyter.
yuvipanda added a commit to yuvipanda/rocker-versioned2 that referenced this issue Oct 18, 2023
Per jupyter/nbconvert#1328, these
are the packages needed for Jupyter to be able to convert
to PDF. Without it, you get unfriendly errors like [this]
(2i2c-org/infrastructure#3188 (comment)).

Given that the binder image includes jupyter, and texlive is included
in the base, I hope it would be reasonable for the binder image
to include enough texlive packages for PDF conversion to work.
Otherwise, it works in RStudio but not in Jupyter.
eitsupi added a commit to rocker-org/rocker-versioned2 that referenced this issue Oct 20, 2023
Per jupyter/nbconvert#1328, these are the
packages needed for Jupyter to be able to convert to PDF. Without it,
you get unfriendly errors like [this]
(2i2c-org/infrastructure#3188 (comment)).

Given that the binder image includes jupyter, and texlive is included in
the base, I hope it would be reasonable for the binder image to include
enough texlive packages for PDF conversion to work. Otherwise, it works
in RStudio but not in Jupyter.

---------

Co-authored-by: eitsupi <50911393+eitsupi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants