Looking for a way to "Download as PDF via Latex" with no page-breaks

Hello! :slight_smile:

I am looking for a, preferably jupyter-notebook native, way to download my .ipynb as a pdf (it also contains latex) with no page-breaks. While googling I stumbled upon 馃悰 FIX: Export Notebook as HTML with no page-breaks by AakashGfude 路 Pull Request #903 路 executablebooks/jupyter-book 路 GitHub which is for jupyter-book, but I tried it anyway (I built a book containing my .ipynb etc). That didn鈥檛 work either.

In any case, what I am looking for is something I can change in config files or add in my notebook, that will disable page-breaks when selecting 鈥淒ownload as PDF via Latex鈥. I know that pdfs have a max inch limit, but mine is a few pages long so probably won鈥檛 be problem.

Thank you !

GitHub - betatim/notebook-as-pdf: Save Jupyter Notebooks as PDF gives you PDFs without page breaks (until you hit the max length of a PDF page). However it doesn鈥檛 use LaTeX so maybe it doesn鈥檛 solve your problem/isn鈥檛 a solution for you.

1 Like

EDIT: betatim, I actually just tried your extension for the first time and it works great! I just interpreted the 鈥渢his extension does not require LaTex鈥 feature as 鈥渢his won鈥檛 run latex鈥 for some reason. Another question (even though probably out of context), how could I have my ToC list nested 鈥渃hapters鈥 (currently only lists those starting with a #). Thank you!

Hey @betatim, thanks for your reply :slight_smile: I 've actually found your extension before (great job btw) while looking for a solution for my use case. Unfortunately, I don鈥檛 think it will work for me as I have a lot of (mostly) inline latex in my notebook.
To be honest, I 've spent too much time trying to solve this issue, and I 've found two 鈥渉ackish鈥 ways to do what I want which I am leaving here for future reference:

  1. (Tested on Firefox) -> From an open notebook tab, Print the page (ctrl + p) and then 鈥淧age Setup鈥 -> 鈥淧aper Size鈥 -> Set a custom size which fits your notebook.

  2. Build your project as a jupyter-book and then print as pdf. (this actually turned out to work).

Unfortunately, neither of these solutions have a nice, auto-generated ToC as the 鈥淒ownload as PDF via Latex鈥 has, but at least no page breaks.

I think the reason the inline LaTeX works is because the notebook contains JavaScript that takes care of rendering it (I think it is MathJax?).

The reason the TOC only includes 鈥渓evel one headings鈥 is because I haven鈥檛 spent enough time to figure out how to also do lower level ones, make nice to navigate (not too much folding/unfolding) TOC, etc.

It feels like you should have a limit at some level of headings. Just level 1 is not enough but maybe including 1, 2 and 3 would be? Or maybe we should ignore level 1 completely because that is often used for the heading/title and nothing else?

If you have some notebooks you could donate to the project for experimenting and getting a feel what is the right trade off that would be cool. Or even better some time to help build the support for more levels in the TOC.

nbconvert v6 has a webpdf output format that has no page breaks. Using the command line, for example in a jupyterhub shell or using a shell magic, one can generate a pdf using:

jupyter nbconvert /path/to/notebook.ipynb  --to webpdf