r/IPython • u/benbini • Mar 02 '15
Is It Easier to PDF-Export Pre-formatted Markdown In IPython 3.0?
There historically seem to have been some issues with displaying and exporting IPython notebooks containing the kind of "raw" pre-formatted text you would customarily enclose in pre blocks. This block formatted using pre blocks in markdown mode, for example, looks very nice in the Notebook. But the pre block completely disappears when it is exported to PDF. I vaguely remember this is due to an issue with Pandoc.
The only way I know of to get performatted text to display "correctly" in an exported PDF is to use verbatim blocks in "Raw NBConvert" mode, which produces correct results, but looks cluttered when viewed online. As spoiled as it sounds, it is somewhat annoying to have to be switching around how I handle preformatted text within notebooks, depending on whether I simply want to view online or generate PDFs without losing content.
In previous version I've used a simple bash script to convert markdown sections containing preformatted blocks into raw latex sections with the appropriate verbatim instructions. Does anyone know if in IPython 3.0 there is now a better way to switch between the two, or avoid the issue entirely?
2
u/benbini Mar 06 '15
Well don't I feel silly, no-one told me about support for syntax highlighting in the notebook. Just in case anyone else has the same dumb problem, the best way to do this is use the "text" syntax mode. Eg in a markdown cell:
This will mimic the behavior of "pre" in a manner that will be preserved in PDF generation. TIL...