Skip to content

Instantly share code, notes, and snippets.

@macoj
Last active December 17, 2020 15:20
Show Gist options
  • Save macoj/f588bdfdf7474838f765b419c15b7960 to your computer and use it in GitHub Desktop.
Save macoj/f588bdfdf7474838f765b419c15b7960 to your computer and use it in GitHub Desktop.
Hiding code when exporting jupyter notebook to pdf

From here: https://ga7g08.github.io/2015/06/25/ipython-nbconvert-latex-template-to-hide-code/

  1. Create a file named hidecode.tplx in the directory of your notebook with the following content:
((*- extends 'article.tplx' -*))

((* block input_group *))
    ((*- if cell.metadata.get('nbconvert', {}).get('show_code', False) -*))
        ((( super() )))
    ((*- endif -*))
((* endblock input_group *))
  1. Export your jupyter notebook to pdf using the template:
$ jupyter nbconvert --to pdf --template hidecode Notebook.ipynb
@NicolasMontes
Copy link

Hello,
It's not working for me. Code is still there in pdf doc.

Hello,
The problem is that you need to place hidecode.tplx in the same directory as article.tplx

@Kabongosalomon
Copy link

Working with me, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment