notebook_style.tplx
191 lines
| 7.3 KiB
| text/plain
|
TextLexer
Jonathan Frederic
|
r12666 | ((= Notebook input/output style =)) | ||
((* extends 'latex_base.tplx' *)) | ||||
% Custom packages | ||||
Jonathan Frederic
|
r12700 | ((* block packages *)) | ||
Jonathan Frederic
|
r12666 | ((( super() ))) | ||
Jonathan Frederic
|
r12700 | \usepackage{tikz} % Needed to box output/input | ||
Jonathan Frederic
|
r12674 | \usepackage{scrextend} % Used to indent output | ||
Jonathan Frederic
|
r12677 | \usepackage{needspace} % Make prompts follow contents | ||
Jonathan Frederic
|
r12700 | \usepackage{framed} % Used to draw output that spans multiple pages | ||
Jonathan Frederic
|
r12666 | ((* endblock packages *)) | ||
% Custom definitions | ||||
((* block definitions *)) | ||||
((( super() ))) | ||||
Jonathan Frederic
|
r12688 | % Pygments definitions | ||
((( resources.latex.pygment_definitions ))) | ||||
Jonathan Frederic
|
r12666 | |||
Jonathan Frederic
|
r12700 | % NB prompt colors | ||
Jonathan Frederic
|
r12666 | \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867} | ||
\definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969} | ||||
\definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502} | ||||
\definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0} | ||||
Jonathan Frederic
|
r12700 | % NB prompt lengths | ||
\newlength{\inputpadding} | ||||
\setlength{\inputpadding}{0.5em} | ||||
\newlength{\cellleftmargin} | ||||
\setlength{\cellleftmargin}{0.15\linewidth} | ||||
\newlength{\borderthickness} | ||||
\setlength{\borderthickness}{0.4pt} | ||||
Jonathan Frederic
|
r12702 | \newlength{\smallerfontscale} | ||
\setlength{\smallerfontscale}{9.5pt} | ||||
% NB prompt font size | ||||
\def\smaller{\fontsize{\smallerfontscale}{\smallerfontscale}\selectfont} | ||||
Jonathan Frederic
|
r12700 | |||
% Define a background layer, in which the nb prompt shape is drawn | ||||
\pgfdeclarelayer{background} | ||||
\pgfsetlayers{background,main} | ||||
\usetikzlibrary{calc} | ||||
% define styles for the normal border and the torn border | ||||
\tikzset{ | ||||
normal border/.style={draw=nbframe-border, fill=nbframe-bg, | ||||
rectangle, rounded corners=2.5pt, line width=\borderthickness}, | ||||
torn border/.style={draw=white, fill=white, line width=\borderthickness}} | ||||
% Macro to draw the shape behind the text, when it fits completly in the | ||||
% page | ||||
\def\notebookcellframe#1{% | ||||
\tikz{% | ||||
\node[inner sep=\inputpadding] (A) {#1};% Draw the text of the node | ||||
\begin{pgfonlayer}{background}% Draw the shape behind | ||||
\fill[normal border]% | ||||
(A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | ||||
($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | ||||
\end{pgfonlayer}}}% | ||||
% Macro to draw the shape, when the text will continue in next page | ||||
\def\notebookcellframetop#1{% | ||||
\tikz{% | ||||
\node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node | ||||
\begin{pgfonlayer}{background} | ||||
\fill[normal border] % Draw the ``complete shape'' behind | ||||
(A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | ||||
($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | ||||
\fill[torn border] % Add the torn lower border | ||||
($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) -- | ||||
($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle; | ||||
\end{pgfonlayer}}} | ||||
% Macro to draw the shape, when the text continues from previous page | ||||
\def\notebookcellframebottom#1{% | ||||
\tikz{% | ||||
\node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node | ||||
\begin{pgfonlayer}{background} | ||||
\fill[normal border] % Draw the ``complete shape'' behind | ||||
(A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | ||||
($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | ||||
\fill[torn border] % Add the torn upper border | ||||
($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) -- | ||||
($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle; | ||||
\end{pgfonlayer}}} | ||||
% Macro to draw the shape, when both the text continues from previous page | ||||
% and it will continue in next page | ||||
\def\notebookcellframemiddle#1{% | ||||
\tikz{% | ||||
\node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node | ||||
\begin{pgfonlayer}{background} | ||||
\fill[normal border] % Draw the ``complete shape'' behind | ||||
(A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | ||||
($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | ||||
\fill[torn border] % Add the torn lower border | ||||
($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) -- | ||||
($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle; | ||||
\fill[torn border] % Add the torn upper border | ||||
($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) -- | ||||
($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle; | ||||
\end{pgfonlayer}}} | ||||
% Define the environment which puts the frame | ||||
% In this case, the environment also accepts an argument with an optional | ||||
% title (which defaults to ``Example'', which is typeset in a box overlaid | ||||
% on the top border | ||||
\newenvironment{notebookcell}[1][0]{% | ||||
\def\FrameCommand{\notebookcellframe}% | ||||
\def\FirstFrameCommand{\notebookcellframetop}% | ||||
\def\LastFrameCommand{\notebookcellframebottom}% | ||||
\def\MidFrameCommand{\notebookcellframemiddle}% | ||||
Jonathan Frederic
|
r12702 | \par\vspace{1\baselineskip}% | ||
Jonathan Frederic
|
r12700 | \MakeFramed {\FrameRestore}% | ||
\noindent\tikz\node[inner sep=0em] at ($(A.north west)-(0,0)$) {% | ||||
((( draw_prompt("In ", "#1", "nbframe-in-prompt", "2pt") )))% | ||||
Jonathan Frederic
|
r12702 | }; \par}% | ||
Jonathan Frederic
|
r12700 | {\endMakeFramed} | ||
Jonathan Frederic
|
r12666 | |||
((* endblock definitions *)) | ||||
Jonathan Frederic
|
r12700 | |||
Jonathan Frederic
|
r12666 | %=============================================================================== | ||
% Input | ||||
%=============================================================================== | ||||
((* block input scoped *)) | ||||
% Add contents below. | ||||
Jonathan Frederic
|
r12688 | |||
Jonathan Frederic
|
r12702 | {\par% | ||
Jonathan Frederic
|
r12700 | \vspace{-1\baselineskip}% | ||
Jonathan Frederic
|
r12702 | \needspace{4\baselineskip}}% | ||
Jonathan Frederic
|
r12700 | \begin{notebookcell}[((( cell.prompt_number )))]% | ||
\begin{addmargin}[\cellleftmargin]{0em}% left, right | ||||
Jonathan Frederic
|
r12702 | {\smaller% | ||
\par% | ||||
((* block extra_input_spacing *))((* endblock extra_input_spacing *))% | ||||
\vspace{-1\smallerfontscale}% | ||||
Jonathan Frederic
|
r12688 | ((( cell.input | highlight2latex )))% | ||
Jonathan Frederic
|
r12702 | \par% | ||
\vspace{-1\smallerfontscale}}% | ||||
Jonathan Frederic
|
r12700 | \end{addmargin} | ||
\end{notebookcell} | ||||
Jonathan Frederic
|
r12686 | |||
Jonathan Frederic
|
r12666 | ((* endblock input *)) | ||
%=============================================================================== | ||||
% Output | ||||
%=============================================================================== | ||||
Jonathan Frederic
|
r12702 | ((* block output -*)) | ||
\par\vspace{1\smallerfontscale}% | ||||
Jonathan Frederic
|
r12666 | % Only render the prompt if the cell is pyout. Note, the outputs prompt | ||
% block isn't used since we need to check each indiviual output and only | ||||
% add prompts to the pyout ones. | ||||
((* if output.output_type in ['pyout'] *)) | ||||
Jonathan Frederic
|
r12702 | {\par% | ||
\vspace{-1\smallerfontscale}% | ||||
Jonathan Frederic
|
r12700 | \noindent% | ||
((( draw_prompt("Out", cell.prompt_number, "nbframe-out-prompt", "0em") )))% | ||||
Jonathan Frederic
|
r12702 | ((* block extra_output_spacing *))((* endblock extra_output_spacing *))}% | ||
Jonathan Frederic
|
r12700 | ((* endif *))% | ||
% | ||||
\begin{addmargin}[\cellleftmargin]{0em}% left, right | ||||
Jonathan Frederic
|
r12702 | {\smaller% | ||
\vspace{-1\smallerfontscale}% | ||||
((( super() )))}% | ||||
\end{addmargin}% | ||||
((*- endblock output *)) | ||||
Jonathan Frederic
|
r12666 | |||
%============================================================================== | ||||
% Support Macros | ||||
%============================================================================== | ||||
% Name: draw_prompt | ||||
Jonathan Frederic
|
r12700 | % Purpose: Renders an output/input prompt for notebook style pdfs | ||
((* macro draw_prompt(prompt, number, color, space) -*)) | ||||
Jonathan Frederic
|
r12702 | \begin{minipage}{\cellleftmargin}% | ||
\hfill% | ||||
{\smaller% | ||||
Jonathan Frederic
|
r12700 | \tt% | ||
\color{(((color)))}% | ||||
Jonathan Frederic
|
r12702 | (((prompt)))[(((number)))]:}% | ||
Jonathan Frederic
|
r12700 | \hspace{\inputpadding}% | ||
\hspace{(((space)))}% | ||||
\hspace{3pt}% | ||||
Jonathan Frederic
|
r12702 | \end{minipage}% | ||
Jonathan Frederic
|
r12700 | ((*- endmacro *)) | ||
Jonathan Frederic
|
r12702 | |||