How to remove date from pdf produced from ipynb with nbconvert

Question:

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.

enter image description here

This date is misleading in the context of what I am producing.

My attempt at removing it involved editing sharejupyternbconverttemplateslatexbase.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?

Asked By: Riley

||

Answers:

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{}

Here’s a solution to remove the date.
Install the classic pdf template

https://stackoverflow.com/a/52575599/9161828

Answered By: ebenezer agbozo
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.