jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.73k stars 564 forks source link

Generating with --template report removes verbatim code background #1147

Open dabljues opened 4 years ago

dabljues commented 4 years ago

As in the title, calling ipython nbconvert --to pdf [...] --template report removes the colored background from Python3 code cells. Going with a default template (so article) works fine.

  1. Create a notebook.
  2. Do some work in it
  3. Convert with ipython nbconvert --to pdf python_cheatsheet.ipynb --template report

article version: (ipython nbconvert --to pdf python_cheatsheet.ipynb)

image

report version: (ipython nbconvert --to pdf python_cheatsheet.ipynb --template report)

image

Is there any way to fix that?

MSeal commented 4 years ago

So the report template uses the ipython style instead of the jupyter style at the top of the template. I'm not sure the history of that choice but you can easily change that by copying report.tplx, changing line 4's style_ipython to style_jupyter, saving that as a new file (jupyter-report.tplx) and referencing it as the template to use: --template=jupyter-report. If there's difficulty finding the file you can do --TemplateExporter.template_file=/path/to/jupyter-report.tplx.

In theory those templates look like they could have the style set via a config option, but I couldn't find how to set that. I suspect it was never fully implemented but I could be wrong.

dabljues commented 4 years ago

@MSeal thank you, that fixed the code listings! I would like to ask another question. Cuz now the code listings are fine, but the output is just plain black on white and I guess I don't want that. I mean, on jupyter lab it's nicely coloured (e.g. red if it's an exception). Is there a way to somehow beautify it, or should I just stick with it?

t-makaro commented 4 years ago

@dabljues I'm fairly sure that we don't make any attempt to colour the output text. In theory, we could with a similar technique used for the code, but that would require some extra metadata for lexers that I don't know if we have.

@MSeal I don't think the cell style has a config option to change it. Only though the template.