Some long statements are cut off. Also, I use statsmodels's logistic regression and the pdf cannot show all the summary() of the training result. How can I change the property(eg. margin) of the pdf? I have no idea about Latex.
This is a problem with how Verbatim blocks are defined. It's designed for representing text (including line breaks as they are passed in). If we wrapped lines when they run off the page, it wouldn't be a verbatim.
If you just want this to fix for one case, then I would recommend converting to LaTeX and manually changing the \begin{Verbatim}…\end{Verbatim} environment to not be a Verbatim environment.
If you want it to wrap, and be reproducible without manual intervention, you'll need to either write a custom template. The simplest solution would be to rewrite the style_ipython.tplx prompt drawing and saving it as a new template. You would accomplish this by removing the \begin{Verbatim} and \end{Verbatim} seen line 55 and line 57 in (for example) my_cell_style.tplx. Then, you would need to modify article.tplx or report.tplx templates (depending on which one you wanted to use), to point to your my_cell_style.tplx as (for examples) my_article.tplx and my_report.tplx. Then you would tell nbconvert to use that template for PDF export (probably using a config file or using the command line argument (for example) --PDFExporter.template_file=my_article.tplx.
There _are_ ways to make this nicer – so that you don't lose the nice prompt formatting in other cases – using custom tags, but try the above solution first, then I can walk you through the improved solution.
For now I'm closing this as having been addressed.
Idea for a shell script to_pdf.sh that customizes the .pdf output. You can use it to decrease the margin, this might be helpful for long statements.
jupyter nbconvert --to latex $1.ipynb
sed -r -i 's/documentclass\[11pt\]\{article\}/documentclass[8pt]{extarticle}/' $1.tex
sed -r -i 's/geometry\{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}/geometry{verbose,tmargin=0.5in,bmargin=0.5in,lmargin=0.2in,rmargin=0.2in}/' $1.tex
pdflatex $1
rm $1.tex; rm $1.out; rm $1.aux; rm $1.log
On Linux, call the script with the filename of the .ipynb file _without the extension_.
In the same ballpark as @hoogenm's comment above, I find that adding fontsize=\footnotesize to the arguments for Verbatim is normally sufficient to avoid clipping. Either by changing the template as @mpacer suggests, or simply by running
sed -i '/\\begin{Verbatim/ s/\]/,fontsize=\\footnotesize]/g' $1.tex
post-conversion.
I tried solutions with footnotesize, but the lines where so long that that didn't help. I found an acceptable alternative with template that adds wraps http://www.markus-beuckelmann.de/blog/customizing-nbconvert-pdf.html
@vors thanks so much! it worked 👍
If you want line breaks in your PDF, you could try using https://nbsphinx.readthedocs.io/, which breaks lines by default.
Apart from line breaks, you can also control many details like margins, font sizes etc., see https://www.sphinx-doc.org/en/master/latex.html.
@mgeier oh that looks promising, thank you for sharing!
@vors the link you shared worked perfectly! Thank you.
This should be fully fixed in nbconvert 5.5.0 by #992
I tried solutions with
footnotesize, but the lines where so long that that didn't help. I found an acceptable alternative with template that adds wraps http://www.markus-beuckelmann.de/blog/customizing-nbconvert-pdf.html
Although i only change wrap_text , it works! this link is really useful,thanks.
Most helpful comment
I tried solutions with
footnotesize, but the lines where so long that that didn't help. I found an acceptable alternative with template that adds wraps http://www.markus-beuckelmann.de/blog/customizing-nbconvert-pdf.html