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’t 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 “Download as PDF via Latex”. I know that pdfs have a max inch limit, but mine is a few pages long so probably won’t 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’t use LaTeX so maybe it doesn’t solve your problem/isn’t 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 “this extension does not require LaTex” feature as “this won’t run latex” for some reason. Another question (even though probably out of context), how could I have my ToC list nested “chapters” (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’t 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 “hackish” 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 “Page Setup” -> “Paper 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 “Download 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 “level one headings” is because I haven’t 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