Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython Jupyter Notebook Latex newpage

How do I insert a newpage/pagebreak into the pdf output of a Jupyter Notebook using the IPython.display.Latex function?

nbconvert is used:

nbconvert --to=pdf

A latex cell works fine:

%%latex
\newpage

but this doesn't do anything:

Latex(r"\newpage")
like image 347
Tom Malkin Avatar asked Oct 19 '25 04:10

Tom Malkin


2 Answers

unless it's the last line of the cell (that's why it works when it's in its own cell), it should be:

display(Latex(r"\newpage"))
like image 58
Julio Avatar answered Oct 21 '25 17:10

Julio


Further elaborating on the answer of @Julio, what you need to incorporate some latex code into a Code cell is:

from IPython.display import display, Math, Latex

then you can procedurally add Latex syntax or Math in any code cell like:

display(Latex(r"\newpage"))

for math formulas, swap Latex with Math.

This will work for scenarios where, e.g., you want to add one line break for each iteration of a for loop.

like image 28
alelom Avatar answered Oct 21 '25 16:10

alelom