--template is broken since nbconvert 6.0
boileaum opened this issue · 0 comments
boileaum commented
Starting from nbconvert 6.0, trying to use a template.tex
file such as:
((* extends 'style_python.tex.j2' *))
((* block docclass *))
\documentclass[11pt]{book}
((* endblock docclass *))
by invoking the --template template.tex
option gives:
python -c "import nbconvert;print(nbconvert.__version__)"
6.0.7
python -m bookbook.latex --pdf --template template.tex
INFO:__main__:Combined 2 files
INFO:__main__:Converting to pdf
Traceback (most recent call last):
File "/Users/boileau/opt/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/boileau/opt/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/bookbook/latex.py", line 163, in <module>
main()
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/bookbook/latex.py", line 160, in main
combine_and_convert(args.source_dir, args.output_file, args.pdf, args.template)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/bookbook/latex.py", line 145, in combine_and_convert
export(combined_nb, output_file, pdf=pdf, template_file=template_file)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/bookbook/latex.py", line 139, in export
output, resources = exporter.from_notebook_node(combined_nb, resources)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/nbconvert/exporters/pdf.py", line 168, in from_notebook_node
latex, resources = super().from_notebook_node(
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/nbconvert/exporters/latex.py", line 77, in from_notebook_node
return super().from_notebook_node(nb, resources, **kw)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/nbconvert/exporters/templateexporter.py", line 384, in from_notebook_node
output = self.template.render(nb=nb_copy, resources=resources)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/nbconvert/exporters/templateexporter.py", line 148, in template
self._template_cached = self._load_template()
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/nbconvert/exporters/templateexporter.py", line 355, in _load_template
return self.environment.get_template(template_file)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 883, in get_template
return self._load_template(name, self.make_globals(globals))
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/jinja2/environment.py", line 857, in _load_template
template = self.loader.load(self, name, globals)
File "/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/jinja2/loaders.py", line 429, in load
raise TemplateNotFound(name)
jinja2.exceptions.TemplateNotFound: template.tex
While, with the equivalent template file for nbconvert < 6.0
((* extends 'style_python.tplx' *))
((* block docclass *))
\documentclass[11pt]{book}
((* endblock docclass *))
it is ok with nbconvert < 6.0 :
python -c "import nbconvert;print(nbconvert.__version__)"
5.6.1
python -m bookbook.latex --pdf --template template.tex
INFO:__main__:Combined 2 files
INFO:__main__:Converting to pdf
/Users/boileau/Documents/Git/Python/bookbook/.venv/lib/python3.8/site-packages/nbconvert/filters/highlight.py:138: UserWarning: IPython3 lexer unavailable, falling back on Python 3
warn("IPython3 lexer unavailable, falling back on Python 3")
INFO:traitlets:Writing 16279 bytes to ./notebook.tex
INFO:traitlets:Building PDF
INFO:traitlets:Running xelatex 3 times: ['xelatex', './notebook.tex', '-quiet']
INFO:traitlets:Running bibtex 1 time: ['bibtex', './notebook']
WARNING:traitlets:bibtex had problems, most likely because there were no citations
INFO:traitlets:PDF successfully created
INFO:traitlets:Writing 20361 bytes to ./combined.pdf
I will propose a PR soon!