Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting ipython to pdf via Latex cut off contents #524

Closed
eeriee opened this issue Feb 1, 2017 · 10 comments
Closed

Converting ipython to pdf via Latex cut off contents #524

eeriee opened this issue Feb 1, 2017 · 10 comments

Comments

@eeriee
Copy link

eeriee commented Feb 1, 2017

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.

@mpacer
Copy link
Member

mpacer commented Apr 4, 2017

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.

@mpacer mpacer closed this as completed Apr 4, 2017
@hoogenm
Copy link

hoogenm commented Apr 16, 2017

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.

@fuglede
Copy link

fuglede commented Aug 12, 2017

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.

@vors
Copy link

vors commented Jan 15, 2018

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

@manashmandal
Copy link

@vors thanks so much! it worked 👍

@mgeier
Copy link
Contributor

mgeier commented Dec 15, 2018

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.

@vors
Copy link

vors commented Dec 16, 2018

@mgeier oh that looks promising, thank you for sharing!

@veenavijai
Copy link

@vors the link you shared worked perfectly! Thank you.

@t-makaro
Copy link
Contributor

This should be fully fixed in nbconvert 5.5.0 by #992

@guangwufengqi
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants