From ab7c2c43820faad724a982f13a0c9d7d14f3ea05 2013-09-23 17:33:00 From: Jonathan Frederic Date: 2013-09-23 17:33:00 Subject: [PATCH] Refactored latex basic template Now called latex base and must be inherited --- diff --git a/IPython/nbconvert/templates/latex/latex_base.tplx b/IPython/nbconvert/templates/latex/latex_base.tplx new file mode 100644 index 0000000..c3cd332 --- /dev/null +++ b/IPython/nbconvert/templates/latex/latex_base.tplx @@ -0,0 +1,179 @@ +((= Latex base template (must inherit) +This template builds upon the abstract template, adding common latex output +functions. Figures, data_text, +This template does not define a docclass, the inheriting class must define this.=)) + +((*- extends 'abstract.tplx' -*)) + +%=============================================================================== +% Abstract overrides +%=============================================================================== + +((* block packages *)) + \usepackage{graphicx} % Used to insert images + \usepackage{adjustbox} % Used to constrain images to a maximum size + \usepackage{color} % Allow colors to be defined + \usepackage{enumerate} % Needed for markdown enumerations to work + \usepackage{fancyvrb} % Needed to support color codes (tex) in verbatim blocks + \usepackage{geometry} % Used to adjust the document margins + \usepackage{amsmath} % Equations + \usepackage{amssymb} % Equations + \usepackage[utf8]{inputenc} % Allow utf-8 characters in the tex document + \usepackage{ucs} % Extended unicode (utf-8) support + \usepackage{grffile} % extends the file name processing of package graphics + %to support a larger range + + % The hyperref package gives us a pdf with properly built + % internal navigation ('pdf bookmarks' for the table of contents, + % internal cross-reference links, web links for URLs, etc.) + \usepackage{hyperref} +((* endblock packages *)) + +((* block definitions *)) + \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} + \definecolor{darkorange}{rgb}{.71,0.21,0.01} + \definecolor{darkgreen}{rgb}{.12,.54,.11} + \definecolor{myteal}{rgb}{.26, .44, .56} + \definecolor{gray}{gray}{0.45} + \definecolor{lightgray}{gray}{.95} + \definecolor{mediumgray}{gray}{.8} + \definecolor{inputbackground}{rgb}{.95, .95, .85} + \definecolor{outputbackground}{rgb}{.95, .95, .95} + \definecolor{traceback}{rgb}{1, .95, .95} + + % new ansi colors + \definecolor{brown}{rgb}{0.54,0.27,0.07} + \definecolor{purple}{rgb}{0.5,0.0,0.5} + \definecolor{darkgray}{gray}{0.25} + \definecolor{lightred}{rgb}{1.0,0.39,0.28} + \definecolor{lightgreen}{rgb}{0.48,0.99,0.0} + \definecolor{lightblue}{rgb}{0.53,0.81,0.92} + \definecolor{lightpurple}{rgb}{0.87,0.63,0.87} + \definecolor{lightcyan}{rgb}{0.5,1.0,0.83} + +((* endblock definitions *)) + +((* block commands *)) + \sloppy % Prevent overflowing lines due to hard-to-break entities + + % Setup hyperref package + \hypersetup{ + breaklinks=true, % so long urls are correctly broken across lines + colorlinks=true, + urlcolor=blue, + linkcolor=darkorange, + citecolor=darkgreen, + } + + % Slightly bigger margins than the latex defaults + \geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm} + + % Hardcode size of all verbatim environments to be a bit smaller + \makeatletter + \g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt + \makeatother +((* endblock commands *)) + +%=============================================================================== +% Support blocks +%=============================================================================== + +% Default output style -code cell style %Use filters ot do cell latex formating +((* block header scoped *)) +((( super() ))) +((* block output_style scoped *)) + ((* include 'simple_style.tplx' with context *)) +((* endblock output_style *)) +((* endblock header *)) + +% Displaying simple data text +((* block data_text *)) + \begin{verbatim} + ((( output.text | escape_latex ))) + \end{verbatim} +((* endblock data_text *)) + +% Display python error text as-is +((* block pyerr *)) + \begin{verbatim} + ((( super() ))) + \end{verbatim} +((* endblock pyerr *)) +((* block traceback_line *)) + ((( line | indent | strip_ansi | escape_latex ))) +((* endblock traceback_line *)) + +% Display stream ouput with coloring +((* block stream *)) + \begin{Verbatim}[commandchars=\\\{\}] + ((( output.text | ansi2latex ))) + \end{Verbatim} +((* endblock stream *)) + +% Display latex +((* block data_latex -*)) + ((*- if output.latex.startswith('$'): -*)) + ((= Replace $ symbols with more explicit, equation block. =)) + \begin{equation*} + ((( output.latex | strip_dollars ))) + \end{equation*} + ((*- else -*)) + ((( output.latex ))) + ((*- endif *)) +((* endblock data_latex *)) + +% Default mechanism for rendering figures +((*- block data_png -*))((( draw_figure(output.png_filename) )))((*- endblock -*)) +((*- block data_jpg -*))((( draw_figure(output.jpeg_filename) )))((*- endblock -*)) +((*- block data_svg -*))((( draw_figure(output.svg_filename) )))((*- endblock -*)) +((*- block data_pdf -*))((( draw_figure(output.pdf_filename) )))((*- endblock -*)) + +% Draw a figure using the graphicx package. +((* macro draw_figure(filename) -*)) +((* set filename = filename | posix_path *)) +((*- block figure scoped -*)) + \begin{center} + \adjustimage{max size={0.9\linewidth}{..}}{((( filename )))} + \par + \end{center} +((*- endblock figure -*)) +((*- endmacro *)) + +% Draw heading cell. Explicitly map different cell levels. +((* block headingcell scoped -*)) + ((*- if cell.level == 1 -*)) + ((* block h1 -*))\section((* endblock h1 -*)) + ((*- elif cell.level == 2 -*)) + ((* block h2 -*))\subsection((* endblock h2 -*)) + ((*- elif cell.level == 3 -*)) + ((* block h3 -*))\subsubsection((* endblock h3 -*)) + ((*- elif cell.level == 4 -*)) + ((* block h4 -*))\paragraph((* endblock h4 -*)) + ((*- elif cell.level == 5 -*)) + ((* block h5 -*))\subparagraph((* endblock h5 -*)) + ((*- elif cell.level == 6 -*)) + ((* block h6 -*))\\*\textit((* endblock h6 -*)) + ((*- endif -*)) + {((( cell.source | escape_latex )))} +((*- endblock headingcell *)) + +% Redirect pyout to display data priority. +((* block pyout scoped *)) + ((* block data_priority scoped *)) + ((( super() ))) + ((* endblock *)) +((* endblock pyout *)) + +% Render markdown +((* block markdowncell scoped *)) + ((( cell.source | markdown2latex ))) +((* endblock markdowncell *)) + +% Spit out the contents of raw cells unmodified +((* block rawcell scoped *)) + ((( cell.source ))) +((* endblock rawcell *)) + +% Don't display unknown types +((* block unknowncell scoped *)) +((* endblock unknowncell *)) diff --git a/IPython/nbconvert/templates/latex/latex_basic.tplx b/IPython/nbconvert/templates/latex/latex_basic.tplx deleted file mode 100644 index 8b1c9da..0000000 --- a/IPython/nbconvert/templates/latex/latex_basic.tplx +++ /dev/null @@ -1,274 +0,0 @@ -((*- extends 'display_priority.tplx' -*)) - - -\nonstopmode - -((* block in_prompt *)) -((* endblock in_prompt *)) - -((* block output_prompt *)) -((* endblock output_prompt *)) - -((* block codecell *)) -\begin{codecell} -((( super() ))) -\end{codecell} -((* endblock *)) - -((* block input *)) -\begin{codeinput} -\begin{lstlisting} -((( cell.input ))) -\end{lstlisting} -\end{codeinput} -((* endblock input *)) - -((= Those Two are for error displaying -even if the first one seem to do nothing, -it introduces a new line -=)) - -((* block pyerr *)) -\begin{traceback} -\begin{verbatim} -((( super() ))) -\end{verbatim} -\end{traceback} -((* endblock pyerr *)) - -((* block traceback_line *)) -((( line | indent | strip_ansi ))) -((* endblock traceback_line *)) -((= .... =)) - -((*- block output_group -*)) -\begin{codeoutput} -((( super() ))) -\end{codeoutput} -((* endblock *)) - -((*- block data_png -*)) -\begin{center} -\includegraphics[max size={0.7\textwidth}{0.9\textheight}]{((( output.png_filename | posix_path )))} -\par -\end{center} -((*- endblock -*)) - -((*- block data_jpg -*)) -\begin{center} -\includegraphics[max size={0.7\textwidth}{0.9\textheight}]{((( output.jpeg_filename | posix_path )))} -\par -\end{center} -((*- endblock -*)) - -((*- block data_svg -*)) -\begin{center} -\includegraphics[width=0.7\textwidth]{((( output.svg_filename | posix_path )))} -\par -\end{center} -((*- endblock -*)) - -((*- block data_pdf -*)) -\begin{center} -\includegraphics[width=0.7\textwidth]{((( output.pdf_filename | posix_path )))} -\par -\end{center} -((*- endblock -*)) - -((* block pyout *)) -((* block data_priority scoped *)) -((( super() ))) -((* endblock *)) -((* endblock pyout *)) - -((* block data_text *)) -\begin{verbatim} -((( output.text ))) -\end{verbatim} -((* endblock *)) - -((* block data_latex -*)) -((*- if output.latex.startswith('$'): -*)) \begin{equation*} - ((( output.latex | strip_dollars ))) - \end{equation*} -((*- else -*)) - ((( output.latex ))) -((*- endif *)) -((* endblock *)) - -((* block stream *)) -\begin{Verbatim}[commandchars=\\\{\}] -((( output.text | ansi2latex ))) -\end{Verbatim} -((* endblock stream *)) - -((* block markdowncell scoped *)) -((( cell.source | citation2latex | markdown2latex ))) -((* endblock markdowncell *)) - -((* block headingcell scoped -*)) -((( ('#' * cell.level + cell.source) | replace('\n', ' ') | citation2latex | markdown2latex ))) -((* endblock headingcell *)) - -((* block rawcell scoped *)) -((( cell.source | comment_lines ))) -((* endblock rawcell *)) - -((* block unknowncell scoped *)) -unknown type ((( cell.type ))) -((* endblock unknowncell *)) - -((* block body *)) - -((* block bodyBegin *)) -\begin{document} -((* endblock bodyBegin *)) - -((( super() ))) - -((* block bodyEnd *)) - -((* block bibliography *)) -((* endblock bibliography *)) - -\end{document} -((* endblock bodyEnd *)) -((* endblock body *)) - -((* block header *)) -%% This file was auto-generated by IPython. -%% Conversion from the original notebook file: -%% -\documentclass[11pt,english]{article} - -%% This is the automatic preamble used by IPython. Note that it does *not* -%% include a documentclass declaration, that is added at runtime to the overall -%% document. - -\usepackage{amsmath} -\usepackage{amssymb} -\usepackage{graphicx} -\usepackage{grffile} -\usepackage{ucs} -\usepackage[utf8x]{inputenc} - -% Scale down larger images -\usepackage[export]{adjustbox} - -%fancy verbatim -\usepackage{fancyvrb} -% needed for markdown enumerations to work -\usepackage{enumerate} - -% Slightly bigger margins than the latex defaults -\usepackage{geometry} -\geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm} - -% Define a few colors for use in code, links and cell shading -\usepackage{color} -\definecolor{orange}{cmyk}{0,0.4,0.8,0.2} -\definecolor{darkorange}{rgb}{.71,0.21,0.01} -\definecolor{darkgreen}{rgb}{.12,.54,.11} -\definecolor{myteal}{rgb}{.26, .44, .56} -\definecolor{gray}{gray}{0.45} -\definecolor{lightgray}{gray}{.95} -\definecolor{mediumgray}{gray}{.8} -\definecolor{inputbackground}{rgb}{.95, .95, .85} -\definecolor{outputbackground}{rgb}{.95, .95, .95} -\definecolor{traceback}{rgb}{1, .95, .95} - -% new ansi colors -\definecolor{brown}{rgb}{0.54,0.27,0.07} -\definecolor{purple}{rgb}{0.5,0.0,0.5} -\definecolor{darkgray}{gray}{0.25} -\definecolor{lightred}{rgb}{1.0,0.39,0.28} -\definecolor{lightgreen}{rgb}{0.48,0.99,0.0} -\definecolor{lightblue}{rgb}{0.53,0.81,0.92} -\definecolor{lightpurple}{rgb}{0.87,0.63,0.87} -\definecolor{lightcyan}{rgb}{0.5,1.0,0.83} - -% Framed environments for code cells (inputs, outputs, errors, ...). The -% various uses of \unskip (or not) at the end were fine-tuned by hand, so don't -% randomly change them unless you're sure of the effect it will have. -\usepackage{framed} - -% remove extraneous vertical space in boxes -\setlength\fboxsep{0pt} - -% codecell is the whole input+output set of blocks that a Code cell can -% generate. - -% TODO: unfortunately, it seems that using a framed codecell environment breaks -% the ability of the frames inside of it to be broken across pages. This -% causes at least the problem of having lots of empty space at the bottom of -% pages as new frames are moved to the next page, and if a single frame is too -% long to fit on a page, will completely stop latex from compiling the -% document. So unless we figure out a solution to this, we'll have to instead -% leave the codecell env. as empty. I'm keeping the original codecell -% definition here (a thin vertical bar) for reference, in case we find a -% solution to the page break issue. - -%% \newenvironment{codecell}{% -%% \def\FrameCommand{\color{mediumgray} \vrule width 1pt \hspace{5pt}}% -%% \MakeFramed{\vspace{-0.5em}}} -%% {\unskip\endMakeFramed} - -% For now, make this a no-op... -\newenvironment{codecell}{} - - \newenvironment{codeinput}{% - \def\FrameCommand{\colorbox{inputbackground}}% - \MakeFramed{\advance\hsize-\width \FrameRestore}} - {\unskip\endMakeFramed} - -\newenvironment{codeoutput}{% - \def\FrameCommand{\colorbox{outputbackground}}% - \vspace{-1.4em} - \MakeFramed{\advance\hsize-\width \FrameRestore}} - {\unskip\medskip\endMakeFramed} - -\newenvironment{traceback}{% - \def\FrameCommand{\colorbox{traceback}}% - \MakeFramed{\advance\hsize-\width \FrameRestore}} - {\endMakeFramed} - -% Use and configure listings package for nicely formatted code -\usepackage{listingsutf8} -\lstset{ - language=python, - inputencoding=utf8x, - extendedchars=\true, - aboveskip=\smallskipamount, - belowskip=\smallskipamount, - xleftmargin=2mm, - breaklines=true, - basicstyle=\small \ttfamily, - showstringspaces=false, - keywordstyle=\color{blue}\bfseries, - commentstyle=\color{myteal}, - stringstyle=\color{darkgreen}, - identifierstyle=\color{darkorange}, - columns=fullflexible, % tighter character kerning, like verb -} - -% The hyperref package gives us a pdf with properly built -% internal navigation ('pdf bookmarks' for the table of contents, -% internal cross-reference links, web links for URLs, etc.) -\usepackage{hyperref} -\hypersetup{ - breaklinks=true, % so long urls are correctly broken across lines - colorlinks=true, - urlcolor=blue, - linkcolor=darkorange, - citecolor=darkgreen, - } - -% hardcode size of all verbatim environments to be a bit smaller -\makeatletter -\g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt -\makeatother - -% Prevent overflowing lines due to urls and other hard-to-break entities. -\sloppy - -((* endblock *))