Custom LaTeX template, code is missing

I’m trying to create my first LaTeX template, using two files: cfg.py and mytemplate.tex.j2. The cfg.py is as follows:

c = get_config()
c.NbConvertApp.export_format = 'pdf'
c.TemplateExporter.extra_template_basedirs = ['.']
c.Exporter.template_file = 'mytemplate.tex.j2'

And the mytemplate.tex.j2 looks like this:

((*- extends 'latex/base.tex.j2' -*))

((*- block header -*))
    ((* block docclass *))
    ((( super() )))
    ((* endblock docclass *))

    ((* block packages *))
    \usepackage{polyglossia}
    \setmainlanguage{russian}
    \setotherlanguage{english}
    \setmainfont{Liberation Serif}
    \setmonofont{Liberation Mono}
    ((( super() ))) % load all other packages
    ((* endblock packages *))

    ((* block definitions *))
    ((( super() )))
    ((* endblock definitions *))

    ((* block commands *))
    ((( super() )))
    ((* endblock commands *))

((*- endblock header -*))


((* block body *))

((* block maketitle *))((* endblock maketitle *))
((( super() )))

((* endblock body *))

The problem is that after running jupyter nbconvert --to pdf --config cfg.py test.ipynb there are no code blocks in my .pdf document. Only markdown text and figures. What might be the problem here?

Seems like I’ve figured this out. I had to extend not the latex/base.tex.j2 but latex/style_ipython.tex.j2 or another styling template with code included.

1 Like