CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
binary10

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Gist: https://gist.github.com/binary10/20b632dc8c3f5a3c9a1b7266aa016128
Views: 59

The problem

Cocalc exports notebooks to LaTeX using a default provided by nbconvert when File > PDF via LaTeX is clicked in the menu.

I wanted to be able to customize the default LaTeX settings (found at /ext/jupyter/nbconvert/templates/latex), however this contains read-only files on the system. So, I created a local config, but they do not automatically override the system settings. After interpreting the docs, I found how to override the system default.

The recipe

  1. First, copy the folder /ext/jupyter/nbconvert/templates/latex to /home/user/.local/share/jupyter/nbconvert/templates/latex.

mkdir -p /home/user/.local/share/jupyter/nbconvert/templates/ cp -r /ext/jupyter/nbconvert/templates/latex /home/user/.local/share/jupyter/nbconvert/templates/
  1. Create a config file at .jupyter/jupyter_nbconvert_config.json with the following contents:

"version": 1, "Exporter": { "template_path": [ "/home/user/.local/share/jupyter", "/home/user/.nbconvert", "." ], "template_paths": ["/home/user/.local/share/jupyter/nbconvert/templates/latex"], "preprocessors": [ "jupyter_contrib_nbextensions.nbconvert_support.CodeFoldingPreprocessor", "jupyter_contrib_nbextensions.nbconvert_support.PyMarkdownPreprocessor" ] } }

The result

Now you will be able to edit the config files for LaTeX documents in /home/user/.local/share/jupyter/nbconvert/templates/latex and the cocalc system will use those settings when you click File > PDF via LaTeX. It also appears that defaults for other export types are not broken by this process, only the LaTeX export is changed.