jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.72k stars 566 forks source link

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

Open ttimbers opened 4 years ago

ttimbers commented 4 years ago

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 commented 4 years ago

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.

kirelagin commented 2 years ago

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

yuvipanda commented 11 months ago

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.