To include the mhchem
package you need to create a custom template. Moreover it is necessary to handle the \require
mathjax command which is not available in pdflatex.
A possible template (chemtempl.tplx
) could look like
((*- extends 'article.tplx' -*))
((* block packages *))
((( super() )))
\usepackage{mhchem}
((* endblock packages *))
((* block commands *))
((( super() )))
% disable require command
\newcommand{\require}[1]{}
((* endblock commands *))
This template extends to default article template by overriding the package and commands block. The super
call is similar to the python command and includes the original block content.
The \require
command is tackled by defining a new command which takes one argument and does nothing -> this way it can remain in the notebook.
The template is used like
jupyter nbconvert --template chemtempl.tplx --to pdf notebook.ipynb
if you are using IPython 3.x just replace jupyter
with ipython
.
To use the template also with the download as pdf feature in the notebook,
a config file has to be used. To this end create a config file (.ipython/profile_default/ipython_config.py
for IPython 3.x or .jupyter/jupyter_notebook_config.py
for IPython 4.x (Jupyter)) with the following content:
c = get_config()
c.LatexExporter.template_path = ['/home/path/to/template/']
c.LatexExporter.template_file = 'chemtempl.tplx'
After restarting Jupyter the new config should be loaded and the template be used.
(I guess for IPython 3.x the file could also be named ipython_notebook_config.py
but currently I have no 3.x version to test this.)