hide code in jupyter notebook

后端 未结 4 1326
时光取名叫无心
时光取名叫无心 2021-01-06 22:23

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 22:49

    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

提交回复
热议问题