git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Jupyter Notebook -> PDF with A4 pages?


Martin Sch??n <martin.schoon at gmail.com> writes:

> Is there a way to do "Download as PDF" and get A4 pages instead
> of Letter? Yes, I know I can do "Download as LaTeX" and edit the
> result to get A4 but if there is a setting I have missed I save
> work and time.
>
> Yes, I have looked through the documentation and searched the
> Internet but so far to no avail.
>

Make a directory ~/.jupyter/templates and put a file A4article.tplx inside it:

#############
((=- Default to the notebook output style -=))
((* if not cell_style is defined *))
    ((* set cell_style = 'style_jupyter.tplx' *))
((* endif *))

((=- Inherit from the specified cell style. -=))
((* extends cell_style *))

%===============================================================================
% Latex Article
%===============================================================================

((* block docclass *))
\documentclass[a4paper,11pt]{article}
((* endblock docclass *))
#############

Make a file ~/.jupyter/jupyter_notebook_config.py

##############
import os
custom_path = os.path.expanduser("~/.jupyter/templates")

c = get_config()
c.TemplateExporter.template_path.append(custom_path)
c.LatexExporter.template_file = 'A4article'
c.PDFExporter.latex_count = 3
c.PDFExporter.template_file = 'A4article'
c.PDFExporter.latex_command = ['pdflatex', '{filename}']
#############
Replace 'pdflatex' with 'xelatex' if you prefer that.
You can leave out the c.LatexExporter.template_file line if you don't want the LaTeX exporter to generate A4.

-- 
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]