[IPython-dev] How to inject "dynamic" information into a Jinja template for IPython notebook conversion

Maximilian Albert maximilian.albert at gmail.com
Tue May 5 19:56:29 EDT 2015


Hi all,

Let me first give a bit of background before I can ask my question. I'm
doing a parameter study for which I need to execute the same analysis with
a bunch of different inputs.I keep an IPython notebook "template.ipynb"
containing un-executed code cells which serves as the template for my
analysis. For each parameter value that I'd like to explore (e.g. "foo=42")
I programmatically insert a code cell at the beginning of this notebook
that defines this parameter value, and subsequently execute the notebook
(using ExecutePreprocessor) so that the result now contains the analysis
for this particular parameter. I save the executed notebook to something
like "output_foo_42.ipynb" and run nbconvert over it, which generates a
nice PDF report. So far so good.

Here is my question. I'd like to be able to "dynamically" inject
information derived from the parameter value into the LaTeX output
generated by nbconvert (in the last step of the above workflow, just before
the actual conversion to PDF). For example, I'd like to be able to define a
custom document title that reports the parameter value. Also, I'd like to
be able to tweak the page numbers of each report so that I can combine all
individual PDF reports into a single long document with consecutive page
numbers.

I'm using a custom Jinja .tplx file with nbconvert to tweak the LaTeX
output (e.g. adjust page margins) but so far all my attempts to inject
"dynamic" information into it have failed. I saw that the "base.tplx"
template uses "resources.metadata.name", so I tried to somehow adjust the
notebook metadata (during the execution stage with ExecutePreprocessor),
alas to no avail. Any ideas how I can achieve this? Or am I barking up the
wrong tree and should be using a completely different approach?

Many thanks for any suggestions!
Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150506/23654fae/attachment.html>


More information about the IPython-dev mailing list