简体   繁体   中英

How to prevent Jupyter Notebook download PDF from printing outside of margin?

In Jupyter Notebook, via "File- Download as - PDF via LaTeX (.pdf)", I downloaded my notebook as a pdf file. However, many of my code blocks get printed outside of the PDF page margins - ie for longer code lines, they get cut out at the pdf page right border. Any way to fix this so that I can have a readable PDF doc (other than manually add hard returns for each line or the way suggested in this post ? Thanks!

I was having the same problem. Ultimately, I found the answer at:

http://www.markus-beuckelmann.de/blog/customizing-nbconvert-pdf.html

Basically, it involves adding a custom latex template that wraps lines. He also adjusts some of the font sizes so that the need for wrapping is less.

I did find one bug. His code is missing the final end macro line:

((*- endmacro *))

I put the file in ~/anaconda2/lib/python2.7/site-packages/nbconvert/templates/latex . The location will vary depending on your installation. I'm using anaconda 4.3.1 (Jupyter 4.3.1 as well?)

Actually what I did was rename the existing article.tplx, changed the "extends 'article.tplx' " reflect the new name, and wrote the new template as article.tplx . That way I can change the templates without having to restart the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM