Martin Schöön <martin.sch...@gmail.com> writes: > Hello all, > > Some years ago I asked about exporting notebooks to pdf in > A4 rather than US Letter. I got help, rather detailed > instructions from you in general and Piet von Oostrum in > particular. Following the advice helped and I was happy. > > Now it does not work any longer: > > nbconvert failed: A4article > > I am stumped. I have not changed anything and all > looks OK. > > Today I tried up-dating all things Python and Jupyter > but that did not help. > > I have also tried removing the A4 stuff and after > restarting Jupyter I can export to PDF and get US Letter > paper format. > > A quick and (obviously) not very clever internet search > yielded nothing helpful.
The template system has changed in nbconvert version 6, so the original templates don't work anymore. And they still haven't supplied standard provisions for A4 paper (like an option or so). Probably a mild case of cultural blindness. I found out how to do it in the new template system, however, there is a bug that gives some troubles. To get all your latex (and therefore also PDF) output in A4 format: Find out where nbconvert expects user templates. Issue the shell command: bash-3.2$ jupyter --paths Look up the data part: ... data: /Users/pieter/Library/Jupyter ... The first one is your personal directory in my case ~/Library/Jupyter. In this directory create the directory nbconvert/templates/latex In this directory create these two files: conf.json
{ "base_template": "latex", "mimetypes": { "text/latex": true, "text/tex": true, "application/pdf": true } }
index.tex.j2
((=- Default to the notebook output style -=)) ((*- if not cell_style is defined -*)) ((* set cell_style = 'style_jupyter.tex.j2' *)) ((*- endif -*)) ((=- Inherit from the specified cell style. -=)) ((* extends cell_style *)) %=============================================================================== % Latex Article %=============================================================================== ((*- block docclass -*)) \documentclass[a4paper,12pt]{article} ((*- endblock docclass -*))
Now jupyter nbconvert --to latex my_nb.ipynb will generate latex with a4paper. If you don't want this to be the default, but you want a special template, let's say A4article, to do this, place these files in a directory .../nbconvert/templates/A4article rather than .../nbconvert/templates/latex. Then you would use jupyter nbconvert --to latex --template A4article my_nb.ipynb However, due to a bug this won't work unless you patch the nbconvert export code. This is a simple one-line patch. See https://github.com/jupyter/nbconvert/pull/1496/commits/a61a2241a87912005720d3412ccd7ef7b5fce6dd -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4]
-- https://mail.python.org/mailman/listinfo/python-list