0

Sorry if that's a silly question, but it really confuses me.

I want to use nbconvert in Jupyter Notebook to export PDF and HTML file for sharing. I must keep the output cell (mostly matplotlib subplots) and hide the input cell (code). However, I cannot hide the output of using nbconvert command.

For example, if I command: !jupyter nbconvert --to pdf --no-input grmd4203.ipynb And it will get:

[NbConvertApp] WARNING | Config option `dpi` not recognized by `PDFExporter`.
[NbConvertApp] Converting notebook grmd4203.ipynb to pdf
[NbConvertApp] Support files will be in grmd4203_files\
[NbConvertApp] Making directory .\grmd4203_files
[NbConvertApp] Making directory .\grmd4203_files
[NbConvertApp] Making directory .\grmd4203_files
[NbConvertApp] Making directory .\grmd4203_files
[NbConvertApp] Writing 25260 bytes to notebook.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running xelatex 1 time: ['xelatex', 'notebook.tex', '-quiet']
[NbConvertApp] Running bibtex 1 time: ['bibtex', 'notebook']
[NbConvertApp] WARNING | b had problems, most likely because there were no citations
[NbConvertApp] PDF successfully created
[NbConvertApp] Writing 922426 bytes to grmd4203.pdf

at the end of the page.

Can I hide this part even if I want to keep my graphs visible? I can manually delete them in pdf file but I cannot remove them in the created HTML file. That's really sad.

  • If you really wanted to leave that `!jupyter nbconvert` in at the end if you notebook and it is a separate cell from your plot, you can put `%%capture` on the line just above it and it will capture the output that includes the `[NbConvertApp]` lines and by doing that suppress the output. Typically, you wouldn't run that inside the notebook you are acting on. Open a new notebook in the same directory as `grmd4203.ipynb` and run that command or execute it on the command line. I suspect if you edited the HTML correctly, you could also delete the extra lines by hand in the created HTML. – Wayne Jan 27 '23 at 20:15
  • The source for the `%%capture` approach comes from [an answer to 'How do you suppress output in Jupyter running IPython?'](https://stackoverflow.com/a/23692951/8508004). Keep in mind that it is a cell magic command so `%%capture` has to be the first line of a cell. I was assuming your `!jupyter nbconvert` was the only line in a cell when I wrote what I did above. – Wayne Jan 27 '23 at 20:16
  • Many thanks! It works after removing --execute in my initial command. – George Cheng Feb 02 '23 at 05:19
  • Your original post didn't have that flag, and so I hadn't tested it. It makes sense though you couldn't include that flag when using it inside the same notebook because it would be like an infinite loop. – Wayne Feb 02 '23 at 13:22

0 Answers0