jupyter
in ipython
and check for possible file name mismatches. To generate PDF, we use either the command line ( jupyter nbconvert --to pdf myfile.ipynb
) or the button from the Download as -> PDF web interface via LaTeX.jupyter nbconvert --to latex myfile.ipynb
, open the resulting TeX source and append the missing packages. Compile the source ( pdflatex myfile.tex
or whatever you like), the goal is achieved. jupyter nbconvert --to pdf --template mytemplate.tplx myfile.ipynb
mytemplate.tplx
successfully located only in the directory from which nbconvert
launched, through the web interface it is not clear how to write a template is not clear.nbconvert
is a file with Python code. How to specify the settings file when invoking the converter: jupyter nbconvert --to pdf --config cfg.py myfile.ipynb
c = get_config() c.NbConvertApp.export_format = 'pdf' c.TemplateExporter.template_path = ['.'] c.Exporter.template_file = 'article'
export_format
is the default value for - to, template_path
is a list of directories with templates, here it says that template files should be searched in the directory from which nbconvert is launched, template_file
means that, if not specified otherwise, you need to use the article.tplx
template .jupyter notebook --config cfg.py
, then all the settings for the conversion will be taken first from the configuration file, which is what we need. If you want these settings to be the default every time nbconvert
run nbconvert
this user, you need to put them in the file ~/.jupyter/jupyter_nbconvert_config.py
. Accordingly, for notebook
general settings file is ~/.jupyter/jupyter_notebook_config.py
.{
replaced by ((
, others {
by (
, with back brackets mirrored). The default set of templates is in NBCONVERT_INSTALLATION_DIR/nbconvert/templates/latex/
. They are well documented, it makes sense to inherit from them when creating your templates. More examples of templates are in the nbconvert-examples repository on Github . Screenshots of various design options can be viewed in the readme to one of the sections of this repository.mytemplate.tplx
, in which to write a few necessary things. % Default to the notebook output style ((* set cell_style = 'style_notebook.tplx' *)) % Inherit from the specified cell style. ((* extends cell_style *))
style_notebook.tplx
template, which is not standard, but lies in nbconvert-examples . This template is also written, apparently, for the old version of nbconvert, so it will need to change the line ((* extends 'latex_base.tplx' *))
to ((* extends 'base.tplx' *))
.\documentclass
future LaTeX file and do not make a header (you can instead write code that takes a header from the metadata of the .ipynb
file or from somewhere else): ((* block docclass *)) \documentclass{article} ((* endblock docclass *)) ((* block maketitle *))((* endblock maketitle *))
((* block packages *)) ((( super() ))) % load all other packages \usepackage[T2A]{fontenc} \usepackage[english, russian]{babel} \usepackage{mathtools} ((* endblock packages *))
nbconvert/templates/latex/skeleton/null.tplx
and nbconvert/templates/latex/base.tplx
(and these are also GitHub links).~/.jupyter/templates/
and change the corresponding line in the settings file (thanks to spitty for noting that the relative paths are just will not work): import os c.TemplateExporter.template_path = ['.', os.path.expanduser('~/.jupyter/templates/')]
Source: https://habr.com/ru/post/279601/
All Articles