I have figured out how to suppress large code blocks from showing up in final NB convert (PDF) output.
By putting the LaTex command in a "raw cell before the code I don't want to have in the final output
\iffalse
Followed By this at the end In a raw cell
\fi
But That still leaves me with some ugly code when I need to show figures and the like and while the base purpose of the notebook is to show code with results, sometimes for a non tech audience we only need the output.. Any Ideas?
Somewhat related if anyone is inspired.. any way to include python variables in the markdown cells so one could have dynamic text with calculated result? Sorry for a second issue but I'm not sure I want to ask this one separately for some strange reason.
Corrections to the answer above:
1) Correct document class name in the latex file above
You should change the line
2) Add local directory to nbconvert config as
sudo gedit /usr/local/lib/python2.7/dist-packages/jupyter_core/tests/dotipython/profile_default/ipython_nbconvert_config.py
add a line
c.TemplateExporter.template_path = ['.']
to the file3) Call the converter as
ipython nbconvert --to=pdf --template=latex_nocode.tplx tested_notebook.ipynb
or if you want to execute all cells for a report for example:
ipython nbconvert --to=pdf --template=latex_nocode.tplx --ExecutePreprocessor.enabled=True tested_notebook.ipynb
To suppress the code cells (only input) a custom template can be used. Similar as discussed in this question, a template e.g. latex_nocode.tplx has to be created (in the working directory) with the following content (for IPython 1.x)
use this template like
ipython nbconvert --to=latex --template=latex_nocode.tplx --post=pdf file.ipynb
Maybe I should add that this way the input block is simply replaced by a blank block (actually a latex comment that input cells are disabled).
When checking the predefined latex templates, the individual blocks (code, markdown, heading, etc) can be identified and a respective custom templates can be set-up to style the output as desired.
Edit
as user1248490 pointed out since IPython 2.0 the latex templates to be extended are called
article.tplx
,report.tplx
orbase.tplx
. Hence the example from above should look likeIf you've stumbled here from IPython 3.2.0 on Windows on Anaconda (I can't see why this wouldn't work on unix systems or on a regular ipython install, but I have not tested those scenarios myself) - this method is what's worked for me. Use TorokLev's latex template (say pdf_nocode.tplx) and then create a python file (say pdf_nocode.py) and paste the following:
Finally, your command will be:
This will also generate the images as support files, if you want to suppress that output (I use mostly plots so this may not work for everyone), you can either modify
by adding this code:
or by subclassing PDFExporter from pdf.py and adding your exporter in exporter_map to:
If you subclass it does have a side benefit of you being able to add your own entry to the notebook menu in: