I have a jupyter notebook that is a mixture of markdown and code. In the end I want to render it out as a pdf report and hide the code. I still want to see the output of t
I'm sure you figured this out by now, but you can simply add in the comment at the top of the cell:
# @hidden_cell
Please read How to print out from Jupyter Notebook without code blocks.
Basically you need to add CSS.
If you want to print out with code use @media print{}
. If you want it on the screen, you need to take it out and just run it.
Paste the following in a cell and run it. Then print it out from a browser File > Print. All codes and output blocks should be gone.
%%html
<style>
@media print {
div.input {
display: none;
padding: 0;
}
div.output_prompt {
display: none;
padding: 0;
}
div.text_cell_render {
padding: 1pt;
}
div#notebook p,
div#notebook,
div#notebook li,
p {
font-size: 11pt;
line-height: 135%;
margin: 0;
}
.rendered_html h1,
.rendered_html h1:first-child {
font-size: 16pt;
margin: 7pt 0;
}
.rendered_html h2,
.rendered_html h2:first-child {
font-size: 14pt;
margin: 6pt 0;
}
.rendered_html h3,
.rendered_html h3:first-child {
font-size: 13pt;
margin: 6pt 0;
}
div.output_subarea {
padding: 0;
}
}
@page {
size: A4;
}
</style>
If you don't fancy writing your own template, and you're not bothered about outputs, you could use the hide_input_all nbextension, which is provided as part of the jupyter contrib nbextensions package. This provides buttons to hide the inputs (though not outputs) of all code cells, as well as setting metadata items that allow you to export with hidden inputs to html, latex or pdf using templates provided by the package:
jupyter nbconvert --template=nbextensions --to=html my_notebook.ipynb
You can easily achieve what you want by creating a custom nbconvert template. This means that your live notebook can still have the input visible but that when you convert to pdf it hides the input.
Create a template file that extends the standard latex template article.tplx
(latex template is used for pdf convert too)
custom.tplx:
% Inherit from the article.tplx
((* extends 'article.tplx' *))
% remove inputs
((* block input_group *))
((* endblock input_group *))
Then convert your notebook using the following command
jupyter nbconvert --template=custom.tplx --to=pdf your_notebook.ipynb
Here's the docs on using custom templates: http://nbconvert.readthedocs.io/en/latest/customizing.html#Custom-Templates