I am using nbconvert programmatically to export a jupyter notebook file to pdf:
import nbformat
from nbconvert.exporters import PDFExporter
from nbconvert.preprocessors import TagRemovePreprocessor
from traitlets.config import Config
c = Config()
c.TagRemovePreprocessor.remove_cell_tags = ("remove_cell",)
c.PDFExporter.preprocessors = ["nbconvert.preprocessors.TagRemovePreprocessor"]
c.PDFExporter.exclude_input_prompt = True
c.PDFExporter.exclude_output_prompt = True
c.PDFExporter.exclude_input = True
exporter = PDFExporter(config=c)
exporter.register_preprocessor(TagRemovePreprocessor(config=c),True)
with open("example.ipynb") as f:
nb = nbformat.read(f, as_version=4)
pdf_data, _ = exporter.from_notebook_node(nb)
with open("example.pdf", "wb") as f:
f.write(pdf_data)
This works, however today's date gets inserted in the document under the title.
This date is misleading in the context of what I am producing.
My attempt at removing it involved editing share\jupyter\nbconvert\templates\latex\base.tex.j2
:
\renewcommand{\TeX}{\textrm{\Oldtex}}
\renewcommand{\LaTeX}{\textrm{\Oldlatex}}
% Document parameters
% Document title
((* block title -*))
((*- set nb_title = nb.metadata.get('title', '') or resources['metadata']['name'] -*))
\title{((( nb_title | escape_latex )))}
((*- endblock title *))
((* block date *))((* endblock date *))
((* block author *))
((* if 'authors' in nb.metadata *))
\author{((( nb.metadata.authors | join(', ', attribute='name') )))}
((* endif *))
((* endblock author *))
and removing the line ((* block date *))((* endblock date *))
but this seems to have no effect.
I know that file is being used in the export process because if I insert jibberish into it then the export fails.
Any ideas where the date is coming from?
By default the date is set to \date{\today}
, you can overwrite it by setting it to something else, e.g. with an empty argument:
\date{}