Skip to content

Instantly share code, notes, and snippets.

@juhasch
Last active June 26, 2017 16:36
Show Gist options
  • Save juhasch/38c60e098665761a392f to your computer and use it in GitHub Desktop.
Save juhasch/38c60e098665761a392f to your computer and use it in GitHub Desktop.
Template for generating PDF output from nbconvert (via latex)
((= IPython input/output style =))
((*- extends 'base.tplx' -*))
%===============================================================================
% Custom definitions
%===============================================================================
((* block definitions *))
((( super() )))
% Pygments definitions
((( resources.latex.pygments_definitions )))
% Exact colors from NB
\definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
% Don't number sections
\renewcommand{\thesection}{\hspace*{-0.5em}}
\renewcommand{\thesubsection}{\hspace*{-0.5em}}
((* endblock definitions *))
% No title
((* block maketitle *))((* endblock maketitle *))
%===============================================================================
% Input
%===============================================================================
((* block input scoped *))
((( '\n' )))
((*- if cell.metadata.hide_input -*))
((*- else -*))
((( add_prompt(cell.source | highlight_code(strip_verbatim=True), cell, '', 'incolor') )))
((*- endif -*))
((* endblock input *))
%===============================================================================
% Output
%===============================================================================
((* block execute_result scoped *))
((( '\n' )))
((*- if cell.metadata.hide_output -*))
((*- else -*))
((( super() )))
((*- endif -*))
((* endblock execute_result *))
%==============================================================================
% Support Macros
%==============================================================================
% Name: draw_prompt
% Purpose: Renders an output/input prompt
((* macro add_prompt(text, cell, prompt, prompt_color) -*))
((*- if cell.execution_count is defined -*))
((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*))
((*- else -*))
((*- set execution_count = " " -*))
((*- endif -*))
((*- set indention = " " * (execution_count | length + 4) -*))
\begin{Verbatim}[commandchars=\\\{\}]
((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
\end{Verbatim}
((*- endmacro *))
%===============================================================================
% Latex Article
%===============================================================================
((* block docclass *))
% !TeX spellcheck = de_DE
% !TeX encoding = UTF-8
\documentclass{scrreprt}
\usepackage{ngerman}
((* endblock docclass *))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment