##// END OF EJS Templates
Localized code into jinja macros.
Localized code into jinja macros.

File last commit:

r9925:90d97d8b
r9925:90d97d8b
Show More
latex_sphinx_base.tplx
313 lines | 11.3 KiB | text/plain | TextLexer
/ templates / tex / latex_sphinx_base.tplx
((= NBConvert Sphinx-Latex Template
Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the
template is derived directly from Sphinx source.
Inheritance: null>display_priority>latex_base
Note: For best display, use latex syntax highlighting. =))
((*- extends 'display_priority.tplx' -*))
%==============================================================================
% Declarations
%==============================================================================
% In order to make sure that the input/output header follows the code it
% preceeds, we have to use a minipage environment. This causes problems
% for large blocks of input and output. If there is a large input/output
% block, we don't want to minipage the whole thing since it will break
% the line wrapping. The solution is to split the input/output line by
% line before we minipage which allows us to minipage the first X lines
% preceeding the input/output bar. That way, a select amount of lines
% force the input/output bar to follow it around.
((*- set min_header_lines = 3 -*))
% This is the number of characters that are permitted per line. It's
% important that this limit is set so characters do not run off the
% edges of latex pages (since latex does not always seem smart enough
% to prevent this.)
((*- set wrap_size = 87 -*))
% Global variable used to determine whether or not a header bar has been
% applied to the group of input/output blocks already
((*- set needs_header = False -*))
%==============================================================================
% Header
%==============================================================================
((* block header *))
% Header, overrides base
% Make sure that the sphinx doc style knows who it inherits from.
\def\sphinxdocclass{(((parentdocumentclass)))}
% Declare the document class
\documentclass[letterpaper,10pt,english]{((( resources.sphinx_texinputs )))/sphinx(((documentclass)))}
% Imports
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\\nobreakspace}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage{import}
\usepackage[((( resources.sphinx_chapterstyle )))]{((( resources.sphinx_texinputs )))/fncychap}
\usepackage{longtable}
\usepackage{((( resources.sphinx_texinputs )))/sphinx}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ucs}
\usepackage{enumerate}
% Pygments requirements
\usepackage{fancyvrb}
\usepackage{color}
% Used to load and display graphics
\usepackage{graphicx}
\graphicspath{ {figs/} }
% For formatting output while also word wrapping.
\usepackage{listings}
\lstset{breaklines=true}
\lstset{basicstyle=\small\ttfamily}
%Pygments definitions
((( resources.pygment_definitions )))
% Help prevent overflowing lines due to urls and other hard-to-break
% entities. This doesn't catch everything...
\sloppy
% Document level variables
\title{((( nb.metadata.name | escape_tex )))}
\date{((( nb.metadata._draft.date | escape_tex )))}
\release{((( nb.metadata._draft.version | escape_tex )))}
\author{((( nb.metadata._draft.author | escape_tex )))}
\renewcommand{\releasename}{((( nb.metadata._draft.release | escape_tex )))}
% TODO: Add option for the user to specify a logo for his/her export.
\newcommand{\sphinxlogo}{}
% Make the index page of the document.
\makeindex
% Import sphinx document type specifics.
((* block sphinxheader *))((* endblock sphinxheader *))
((* endblock header *))
%==============================================================================
% Body
%==============================================================================
((* block body *))
((* block bodyBegin *))
% Body
% Start of the document
\begin{document}
\maketitle
\tableofcontents
((* endblock bodyBegin *))((( super() )))((* block bodyEnd *))
\renewcommand{\indexname}{Index}
\printindex
% End of document
\end{document}
((* endblock bodyEnd *))
((* endblock body *))
%==============================================================================
% Footer
%==============================================================================
((* block footer *))
((* endblock footer *))
%==============================================================================
% Headings
%
% Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx
% style that is active, this will change. Thus sphinx styles will
% override the values here.
%==============================================================================
((* block headingcell -*))
\ ((= This backslash IS significant, do not delete =))
((*- if cell.level == 1 -*))
((* block h1 -*))part((* endblock h1 -*))
((*- elif cell.level == 2 -*))
((* block h2 -*))chapter((* endblock h2 -*))
((*- elif cell.level == 3 -*))
((* block h3 -*))section((* endblock h3 -*))
((*- elif cell.level == 4 -*))
((* block h4 -*))subsection((* endblock h4 -*))
((*- elif cell.level == 5 -*))
((* block h5 -*))subsubsection((* endblock h5 -*))
((*- elif cell.level == 6 -*))
((* block h6 -*))paragraph((* endblock h6 -*))
((= It's important to make sure that underscores (which tend to be common
in IPYNB file titles) do not make their way into latex. Sometimes this
causes latex to barf. =))
((*- endif -*)){((( escapeUnderscores(cell.source | markdown2latex ) )))}
((*- endblock headingcell *))
%==============================================================================
% Markdown
%
% Purpose: Convert markdown to latex. Here markdown2latex is explicitly
% called since we know we want latex output.
%==============================================================================
((*- block markdowncell scoped-*))
((( cell.source | markdown2latex )))
((*- endblock markdowncell -*))
%==============================================================================
% Rawcell
%
% Purpose: Raw text cells allow the user to manually inject document code that
% will not get touched by the templating system.
%==============================================================================
((*- block rawcell *))
((( cell.source | wrap(wrap_size) )))
((* endblock rawcell -*))
%==============================================================================
% Unknowncell
%
% Purpose: This is the catch anything unhandled. To display this data, we
% remove all possible latex conflicts and wrap the characters so they
% can't flow off of the page.
%==============================================================================
((* block unknowncell scoped*))
% Unsupported cell type, no formatting
((( cell.source | wrap | escape_tex )))
((* endblock unknowncell *))
%==============================================================================
% Input
%==============================================================================
((* block input *))
((= Global variable used to determine whether or not a header bar has been
applied to the group of output blocks already. We still need to set
it to true to make sure that the block bar gets rendered.=))
((*- set needs_header = true -*))
((* set text_begining = cell.input | wrap(wrap_size) | get_lines(end=min_header_lines) | highlight *))
((* set text_remainer = cell.input | wrap(wrap_size) | get_lines(start=min_header_lines) | highlight *))
((( inputBlock(text_begining, text_remainer) )))
((* endblock input *))
%==============================================================================
% Output_Group
%
% Purpose: Make sure that only one header bar only attaches to the output
% once. By keeping track of when an input group is started
%==============================================================================
((*- block output_group -*))
((= Global variable used to determine whether or not a header bar has been
applied to the group of output blocks already. =))
((*- set needs_header = true -*))
((( super() )))
((* endblock *))
%==============================================================================
% Output types
%==============================================================================
((* block pyout *))
((* block data_priority scoped -*))
((( inputBlock(super(),"") )))
((*- endblock *))
((* endblock pyout *))
((* block stream *))
((* set text_begining = output.text | wrap(wrap_size) | get_lines(end=min_header_lines) *))
((* set text_remainer = output.text | wrap(wrap_size) | get_lines(start=min_header_lines) *))
((( inputBlock(customVerbatim(text_begining), customVerbatim(text_remainer)) )))
((* endblock stream *))
((*- block display_data -*))
((( inputBlock(super(), "") )))
((*- endblock display_data -*))
((* block pyerr *))
((* set text_begining = super() | wrap(wrap_size) | get_lines(end=min_header_lines) *))
((* set text_remainer = super() | wrap(wrap_size) | get_lines(start=min_header_lines) *))
((( inputBlock(customVerbatim(text_begining), customVerbatim(text_remainer)) )))
((* endblock pyerr *))
%==============================================================================
% Additional formating
%==============================================================================
((* block data_text *))
((( customVerbatim(output.text | wrap(wrap_size)) )))
((* endblock *))
((* block traceback_line *))
((( line | wrap(wrap_size) |indent| rm_ansi )))
((* endblock traceback_line *))
%==============================================================================
% Supported image formats
%==============================================================================
((*- block data_png -*))
((( insertGraphics(output.key_png) )))
((*- endblock -*))
((*- block data_svg -*))
((( insertGraphics(output.key_svg) )))
((*- endblock -*))
%==============================================================================
% Support Macros
%==============================================================================
((* macro outputBlock(text_begining, text_remainer) -*))
((( nbconvertBlock("Output", text_begining, text_remainer) )))
((*- endmacro *))
((* macro inputBlock(text_begining, text_remainer) -*))
((( nbconvertBlock("Input", text_begining, text_remainer) )))
((*- endmacro *))
((* macro nbconvertBlock(blockTitle, text_begining, text_remainer) -*))
((*- if needs_header -*))
\vspace{10pt}
\begin{minipage}{\textwidth}
{\scriptsize (((blockTitle)))}\\*
\rule[10pt]{\linewidth}{0.5pt}
\vspace{-25pt}
((( text_begining )))
\end{minipage}((( text_remainer )))
((*- else -*))
((( text_begining )))
((( text_remainer )))
((*- endif -*))
((*- set needs_header = false -*))
((*- endmacro *))
((* macro customVerbatim(text) -*))
\begin{lstlisting}
((( text )))
\end{lstlisting}
((*- endmacro *))
((* macro insertGraphics(path) -*))
\begin{center}
\includegraphics[width=0.7\textwidth]{(((path)))}
\par
\end{center}
((*- endmacro *))
((* macro escapeUnderscores(text) -*))
((*- set text = text|replace("_","\\_") -*))
((( text )))
((*- endmacro *))