Show More
@@ -1,74 +1,74 b'' | |||||
1 | """Module that allows latex output notebooks to be conditioned before |
|
1 | """Module that allows latex output notebooks to be conditioned before | |
2 | they are converted. |
|
2 | they are converted. | |
3 | """ |
|
3 | """ | |
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | # Copyright (c) 2013, the IPython Development Team. |
|
5 | # Copyright (c) 2013, the IPython Development Team. | |
6 | # |
|
6 | # | |
7 | # Distributed under the terms of the Modified BSD License. |
|
7 | # Distributed under the terms of the Modified BSD License. | |
8 | # |
|
8 | # | |
9 | # The full license is in the file COPYING.txt, distributed with this software. |
|
9 | # The full license is in the file COPYING.txt, distributed with this software. | |
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
11 |
|
11 | |||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | from __future__ import print_function, absolute_import |
|
16 | from __future__ import print_function, absolute_import | |
17 | import os |
|
17 | import os | |
18 |
|
18 | |||
19 | # Third-party import, needed for Pygments latex definitions. |
|
19 | # Third-party import, needed for Pygments latex definitions. | |
20 | from pygments.formatters import LatexFormatter |
|
20 | from pygments.formatters import LatexFormatter | |
21 |
|
21 | |||
22 | # ipy imports |
|
22 | # ipy imports | |
23 | from .base import (Preprocessor) |
|
23 | from .base import (Preprocessor) | |
24 | from IPython.nbconvert import filters |
|
24 | from IPython.nbconvert import filters | |
25 |
|
25 | |||
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
27 | # Classes |
|
27 | # Classes | |
28 | #----------------------------------------------------------------------------- |
|
28 | #----------------------------------------------------------------------------- | |
29 |
|
29 | |||
30 | class LatexPreprocessor(Preprocessor): |
|
30 | class LatexPreprocessor(Preprocessor): | |
31 | """ |
|
31 | """ | |
32 | Converter for latex destined documents. |
|
32 | Converter for latex destined documents. | |
33 | """ |
|
33 | """ | |
34 |
|
34 | |||
35 | def preprocess(self, nb, resources): |
|
35 | def preprocess(self, nb, resources): | |
36 | """ |
|
36 | """ | |
37 | Preprocessing to apply on each notebook. |
|
37 | Preprocessing to apply on each notebook. | |
38 |
|
38 | |||
39 | Parameters |
|
39 | Parameters | |
40 | ---------- |
|
40 | ---------- | |
41 | nb : NotebookNode |
|
41 | nb : NotebookNode | |
42 | Notebook being converted |
|
42 | Notebook being converted | |
43 | resources : dictionary |
|
43 | resources : dictionary | |
44 | Additional resources used in the conversion process. Allows |
|
44 | Additional resources used in the conversion process. Allows | |
45 | preprocessors to pass variables into the Jinja engine. |
|
45 | preprocessors to pass variables into the Jinja engine. | |
46 | """ |
|
46 | """ | |
47 | # Generate Pygments definitions for Latex |
|
47 | # Generate Pygments definitions for Latex | |
48 | resources["latex"] = {} |
|
48 | resources["latex"] = {} | |
49 | resources["latex"]["pygment_definitions"] = LatexFormatter().get_style_defs() |
|
49 | resources["latex"]["pygments_definitions"] = LatexFormatter().get_style_defs() | |
50 | return super(LatexPreprocessor, self).preprocess(nb, resources) |
|
50 | return super(LatexPreprocessor, self).preprocess(nb, resources) | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | def preprocess_cell(self, cell, resources, index): |
|
53 | def preprocess_cell(self, cell, resources, index): | |
54 | """ |
|
54 | """ | |
55 | Apply a transformation on each cell, |
|
55 | Apply a transformation on each cell, | |
56 |
|
56 | |||
57 | Parameters |
|
57 | Parameters | |
58 | ---------- |
|
58 | ---------- | |
59 | cell : NotebookNode cell |
|
59 | cell : NotebookNode cell | |
60 | Notebook cell being processed |
|
60 | Notebook cell being processed | |
61 | resources : dictionary |
|
61 | resources : dictionary | |
62 | Additional resources used in the conversion process. Allows |
|
62 | Additional resources used in the conversion process. Allows | |
63 | preprocessors to pass variables into the Jinja engine. |
|
63 | preprocessors to pass variables into the Jinja engine. | |
64 | index : int |
|
64 | index : int | |
65 | Modified index of the cell being processed (see base.py) |
|
65 | Modified index of the cell being processed (see base.py) | |
66 | """ |
|
66 | """ | |
67 |
|
67 | |||
68 | #If the cell is a markdown cell, preprocess the ampersands used to |
|
68 | #If the cell is a markdown cell, preprocess the ampersands used to | |
69 | #remove the space between them and their contents. Latex will complain |
|
69 | #remove the space between them and their contents. Latex will complain | |
70 | #if spaces exist between the ampersands and the math content. |
|
70 | #if spaces exist between the ampersands and the math content. | |
71 | #See filters.latex.rm_math_space for more information. |
|
71 | #See filters.latex.rm_math_space for more information. | |
72 | if hasattr(cell, "source") and cell.cell_type == "markdown": |
|
72 | if hasattr(cell, "source") and cell.cell_type == "markdown": | |
73 | cell.source = filters.strip_math_space(cell.source) |
|
73 | cell.source = filters.strip_math_space(cell.source) | |
74 | return cell, resources |
|
74 | return cell, resources |
@@ -1,54 +1,54 b'' | |||||
1 | ((= IPython input/output style =)) |
|
1 | ((= IPython input/output style =)) | |
2 |
|
2 | |||
3 | ((*- extends 'latex_base.tplx' -*)) |
|
3 | ((*- extends 'latex_base.tplx' -*)) | |
4 |
|
4 | |||
5 | % Custom definitions |
|
5 | % Custom definitions | |
6 | ((* block definitions *)) |
|
6 | ((* block definitions *)) | |
7 | ((( super() ))) |
|
7 | ((( super() ))) | |
8 |
|
8 | |||
9 | % Pygments definitions |
|
9 | % Pygments definitions | |
10 | ((( resources.latex.pygment_definitions ))) |
|
10 | ((( resources.latex.pygments_definitions ))) | |
11 |
|
11 | |||
12 | % Exact colors from NB |
|
12 | % Exact colors from NB | |
13 | \definecolor{incolor}{rgb}{0.0, 0.0, 0.5} |
|
13 | \definecolor{incolor}{rgb}{0.0, 0.0, 0.5} | |
14 | \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0} |
|
14 | \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0} | |
15 |
|
15 | |||
16 | ((* endblock definitions *)) |
|
16 | ((* endblock definitions *)) | |
17 |
|
17 | |||
18 | %=============================================================================== |
|
18 | %=============================================================================== | |
19 | % Input |
|
19 | % Input | |
20 | %=============================================================================== |
|
20 | %=============================================================================== | |
21 |
|
21 | |||
22 | ((* block input scoped *)) |
|
22 | ((* block input scoped *)) | |
23 | ((( add_prompt(cell.input | highlight2latex(strip_verbatim=True), cell, 'In ', 'incolor') ))) |
|
23 | ((( add_prompt(cell.input | highlight2latex(strip_verbatim=True), cell, 'In ', 'incolor') ))) | |
24 | ((* endblock input *)) |
|
24 | ((* endblock input *)) | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | %=============================================================================== |
|
27 | %=============================================================================== | |
28 | % Output |
|
28 | % Output | |
29 | %=============================================================================== |
|
29 | %=============================================================================== | |
30 |
|
30 | |||
31 | ((* block pyout scoped *)) |
|
31 | ((* block pyout scoped *)) | |
32 | ((*- for type in output | filter_data_type -*)) |
|
32 | ((*- for type in output | filter_data_type -*)) | |
33 | ((*- if type in ['text']*)) |
|
33 | ((*- if type in ['text']*)) | |
34 | ((( add_prompt(output.text | escape_latex, cell, 'Out', 'outcolor') ))) |
|
34 | ((( add_prompt(output.text | escape_latex, cell, 'Out', 'outcolor') ))) | |
35 | ((* else -*)) |
|
35 | ((* else -*)) | |
36 | \texttt{\color{outcolor}Out[{\color{outcolor}((( cell.prompt_number )))}]:}((( super() ))) |
|
36 | \texttt{\color{outcolor}Out[{\color{outcolor}((( cell.prompt_number )))}]:}((( super() ))) | |
37 | ((*- endif -*)) |
|
37 | ((*- endif -*)) | |
38 | ((*- endfor -*)) |
|
38 | ((*- endfor -*)) | |
39 | ((* endblock pyout *)) |
|
39 | ((* endblock pyout *)) | |
40 |
|
40 | |||
41 |
|
41 | |||
42 | %============================================================================== |
|
42 | %============================================================================== | |
43 | % Support Macros |
|
43 | % Support Macros | |
44 | %============================================================================== |
|
44 | %============================================================================== | |
45 |
|
45 | |||
46 | % Name: draw_prompt |
|
46 | % Name: draw_prompt | |
47 | % Purpose: Renders an output/input prompt |
|
47 | % Purpose: Renders an output/input prompt | |
48 | ((* macro add_prompt(text, cell, prompt, prompt_color) -*)) |
|
48 | ((* macro add_prompt(text, cell, prompt, prompt_color) -*)) | |
49 | ((*- set prompt_number = "" ~ cell.prompt_number -*)) |
|
49 | ((*- set prompt_number = "" ~ cell.prompt_number -*)) | |
50 | ((*- set indention = " " * (prompt_number | length + 7) -*)) |
|
50 | ((*- set indention = " " * (prompt_number | length + 7) -*)) | |
51 | \begin{Verbatim}[commandchars=\\\{\}] |
|
51 | \begin{Verbatim}[commandchars=\\\{\}] | |
52 | ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) ))) |
|
52 | ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) ))) | |
53 | \end{Verbatim} |
|
53 | \end{Verbatim} | |
54 | ((*- endmacro *)) |
|
54 | ((*- endmacro *)) |
@@ -1,191 +1,191 b'' | |||||
1 | ((= Notebook input/output style =)) |
|
1 | ((= Notebook input/output style =)) | |
2 |
|
2 | |||
3 | ((* extends 'latex_base.tplx' *)) |
|
3 | ((* extends 'latex_base.tplx' *)) | |
4 |
|
4 | |||
5 | % Custom packages |
|
5 | % Custom packages | |
6 | ((* block packages *)) |
|
6 | ((* block packages *)) | |
7 | ((( super() ))) |
|
7 | ((( super() ))) | |
8 |
|
8 | |||
9 | \usepackage{tikz} % Needed to box output/input |
|
9 | \usepackage{tikz} % Needed to box output/input | |
10 | \usepackage{scrextend} % Used to indent output |
|
10 | \usepackage{scrextend} % Used to indent output | |
11 | \usepackage{needspace} % Make prompts follow contents |
|
11 | \usepackage{needspace} % Make prompts follow contents | |
12 | \usepackage{framed} % Used to draw output that spans multiple pages |
|
12 | \usepackage{framed} % Used to draw output that spans multiple pages | |
13 | ((* endblock packages *)) |
|
13 | ((* endblock packages *)) | |
14 |
|
14 | |||
15 | % Custom definitions |
|
15 | % Custom definitions | |
16 | ((* block definitions *)) |
|
16 | ((* block definitions *)) | |
17 | ((( super() ))) |
|
17 | ((( super() ))) | |
18 |
|
18 | |||
19 | % Pygments definitions |
|
19 | % Pygments definitions | |
20 | ((( resources.latex.pygment_definitions ))) |
|
20 | ((( resources.latex.pygments_definitions ))) | |
21 |
|
21 | |||
22 | % NB prompt colors |
|
22 | % NB prompt colors | |
23 | \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867} |
|
23 | \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867} | |
24 | \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969} |
|
24 | \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969} | |
25 | \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502} |
|
25 | \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502} | |
26 | \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0} |
|
26 | \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0} | |
27 |
|
27 | |||
28 | % NB prompt lengths |
|
28 | % NB prompt lengths | |
29 | \newlength{\inputpadding} |
|
29 | \newlength{\inputpadding} | |
30 | \setlength{\inputpadding}{0.5em} |
|
30 | \setlength{\inputpadding}{0.5em} | |
31 | \newlength{\cellleftmargin} |
|
31 | \newlength{\cellleftmargin} | |
32 | \setlength{\cellleftmargin}{0.15\linewidth} |
|
32 | \setlength{\cellleftmargin}{0.15\linewidth} | |
33 | \newlength{\borderthickness} |
|
33 | \newlength{\borderthickness} | |
34 | \setlength{\borderthickness}{0.4pt} |
|
34 | \setlength{\borderthickness}{0.4pt} | |
35 | \newlength{\smallerfontscale} |
|
35 | \newlength{\smallerfontscale} | |
36 | \setlength{\smallerfontscale}{9.5pt} |
|
36 | \setlength{\smallerfontscale}{9.5pt} | |
37 |
|
37 | |||
38 | % NB prompt font size |
|
38 | % NB prompt font size | |
39 | \def\smaller{\fontsize{\smallerfontscale}{\smallerfontscale}\selectfont} |
|
39 | \def\smaller{\fontsize{\smallerfontscale}{\smallerfontscale}\selectfont} | |
40 |
|
40 | |||
41 | % Define a background layer, in which the nb prompt shape is drawn |
|
41 | % Define a background layer, in which the nb prompt shape is drawn | |
42 | \pgfdeclarelayer{background} |
|
42 | \pgfdeclarelayer{background} | |
43 | \pgfsetlayers{background,main} |
|
43 | \pgfsetlayers{background,main} | |
44 | \usetikzlibrary{calc} |
|
44 | \usetikzlibrary{calc} | |
45 |
|
45 | |||
46 | % define styles for the normal border and the torn border |
|
46 | % define styles for the normal border and the torn border | |
47 | \tikzset{ |
|
47 | \tikzset{ | |
48 | normal border/.style={draw=nbframe-border, fill=nbframe-bg, |
|
48 | normal border/.style={draw=nbframe-border, fill=nbframe-bg, | |
49 | rectangle, rounded corners=2.5pt, line width=\borderthickness}, |
|
49 | rectangle, rounded corners=2.5pt, line width=\borderthickness}, | |
50 | torn border/.style={draw=white, fill=white, line width=\borderthickness}} |
|
50 | torn border/.style={draw=white, fill=white, line width=\borderthickness}} | |
51 |
|
51 | |||
52 | % Macro to draw the shape behind the text, when it fits completly in the |
|
52 | % Macro to draw the shape behind the text, when it fits completly in the | |
53 | % page |
|
53 | % page | |
54 | \def\notebookcellframe#1{% |
|
54 | \def\notebookcellframe#1{% | |
55 | \tikz{% |
|
55 | \tikz{% | |
56 | \node[inner sep=\inputpadding] (A) {#1};% Draw the text of the node |
|
56 | \node[inner sep=\inputpadding] (A) {#1};% Draw the text of the node | |
57 | \begin{pgfonlayer}{background}% Draw the shape behind |
|
57 | \begin{pgfonlayer}{background}% Draw the shape behind | |
58 | \fill[normal border]% |
|
58 | \fill[normal border]% | |
59 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- |
|
59 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | |
60 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; |
|
60 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | |
61 | \end{pgfonlayer}}}% |
|
61 | \end{pgfonlayer}}}% | |
62 |
|
62 | |||
63 | % Macro to draw the shape, when the text will continue in next page |
|
63 | % Macro to draw the shape, when the text will continue in next page | |
64 | \def\notebookcellframetop#1{% |
|
64 | \def\notebookcellframetop#1{% | |
65 | \tikz{% |
|
65 | \tikz{% | |
66 | \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node |
|
66 | \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node | |
67 | \begin{pgfonlayer}{background} |
|
67 | \begin{pgfonlayer}{background} | |
68 | \fill[normal border] % Draw the ``complete shape'' behind |
|
68 | \fill[normal border] % Draw the ``complete shape'' behind | |
69 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- |
|
69 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | |
70 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; |
|
70 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | |
71 | \fill[torn border] % Add the torn lower border |
|
71 | \fill[torn border] % Add the torn lower border | |
72 | ($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) -- |
|
72 | ($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) -- | |
73 | ($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle; |
|
73 | ($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle; | |
74 | \end{pgfonlayer}}} |
|
74 | \end{pgfonlayer}}} | |
75 |
|
75 | |||
76 | % Macro to draw the shape, when the text continues from previous page |
|
76 | % Macro to draw the shape, when the text continues from previous page | |
77 | \def\notebookcellframebottom#1{% |
|
77 | \def\notebookcellframebottom#1{% | |
78 | \tikz{% |
|
78 | \tikz{% | |
79 | \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node |
|
79 | \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node | |
80 | \begin{pgfonlayer}{background} |
|
80 | \begin{pgfonlayer}{background} | |
81 | \fill[normal border] % Draw the ``complete shape'' behind |
|
81 | \fill[normal border] % Draw the ``complete shape'' behind | |
82 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- |
|
82 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | |
83 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; |
|
83 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | |
84 | \fill[torn border] % Add the torn upper border |
|
84 | \fill[torn border] % Add the torn upper border | |
85 | ($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) -- |
|
85 | ($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) -- | |
86 | ($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle; |
|
86 | ($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle; | |
87 | \end{pgfonlayer}}} |
|
87 | \end{pgfonlayer}}} | |
88 |
|
88 | |||
89 | % Macro to draw the shape, when both the text continues from previous page |
|
89 | % Macro to draw the shape, when both the text continues from previous page | |
90 | % and it will continue in next page |
|
90 | % and it will continue in next page | |
91 | \def\notebookcellframemiddle#1{% |
|
91 | \def\notebookcellframemiddle#1{% | |
92 | \tikz{% |
|
92 | \tikz{% | |
93 | \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node |
|
93 | \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node | |
94 | \begin{pgfonlayer}{background} |
|
94 | \begin{pgfonlayer}{background} | |
95 | \fill[normal border] % Draw the ``complete shape'' behind |
|
95 | \fill[normal border] % Draw the ``complete shape'' behind | |
96 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- |
|
96 | (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) -- | |
97 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; |
|
97 | ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle; | |
98 | \fill[torn border] % Add the torn lower border |
|
98 | \fill[torn border] % Add the torn lower border | |
99 | ($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) -- |
|
99 | ($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) -- | |
100 | ($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle; |
|
100 | ($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle; | |
101 | \fill[torn border] % Add the torn upper border |
|
101 | \fill[torn border] % Add the torn upper border | |
102 | ($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) -- |
|
102 | ($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) -- | |
103 | ($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle; |
|
103 | ($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle; | |
104 | \end{pgfonlayer}}} |
|
104 | \end{pgfonlayer}}} | |
105 |
|
105 | |||
106 | % Define the environment which puts the frame |
|
106 | % Define the environment which puts the frame | |
107 | % In this case, the environment also accepts an argument with an optional |
|
107 | % In this case, the environment also accepts an argument with an optional | |
108 | % title (which defaults to ``Example'', which is typeset in a box overlaid |
|
108 | % title (which defaults to ``Example'', which is typeset in a box overlaid | |
109 | % on the top border |
|
109 | % on the top border | |
110 | \newenvironment{notebookcell}[1][0]{% |
|
110 | \newenvironment{notebookcell}[1][0]{% | |
111 | \def\FrameCommand{\notebookcellframe}% |
|
111 | \def\FrameCommand{\notebookcellframe}% | |
112 | \def\FirstFrameCommand{\notebookcellframetop}% |
|
112 | \def\FirstFrameCommand{\notebookcellframetop}% | |
113 | \def\LastFrameCommand{\notebookcellframebottom}% |
|
113 | \def\LastFrameCommand{\notebookcellframebottom}% | |
114 | \def\MidFrameCommand{\notebookcellframemiddle}% |
|
114 | \def\MidFrameCommand{\notebookcellframemiddle}% | |
115 | \par\vspace{1\baselineskip}% |
|
115 | \par\vspace{1\baselineskip}% | |
116 | \MakeFramed {\FrameRestore}% |
|
116 | \MakeFramed {\FrameRestore}% | |
117 | \noindent\tikz\node[inner sep=0em] at ($(A.north west)-(0,0)$) {% |
|
117 | \noindent\tikz\node[inner sep=0em] at ($(A.north west)-(0,0)$) {% | |
118 | ((( draw_prompt("In", "#1", "nbframe-in-prompt", "2pt") )))% |
|
118 | ((( draw_prompt("In", "#1", "nbframe-in-prompt", "2pt") )))% | |
119 | }; \par}% |
|
119 | }; \par}% | |
120 | {\endMakeFramed} |
|
120 | {\endMakeFramed} | |
121 |
|
121 | |||
122 | ((* endblock definitions *)) |
|
122 | ((* endblock definitions *)) | |
123 |
|
123 | |||
124 | %=============================================================================== |
|
124 | %=============================================================================== | |
125 | % Input |
|
125 | % Input | |
126 | %=============================================================================== |
|
126 | %=============================================================================== | |
127 |
|
127 | |||
128 | ((* block input scoped *)) |
|
128 | ((* block input scoped *)) | |
129 | % Add contents below. |
|
129 | % Add contents below. | |
130 |
|
130 | |||
131 | {\par% |
|
131 | {\par% | |
132 | \vspace{-1\baselineskip}% |
|
132 | \vspace{-1\baselineskip}% | |
133 | \needspace{4\baselineskip}}% |
|
133 | \needspace{4\baselineskip}}% | |
134 | \begin{notebookcell}[((( cell.prompt_number )))]% |
|
134 | \begin{notebookcell}[((( cell.prompt_number )))]% | |
135 | \begin{addmargin}[\cellleftmargin]{0em}% left, right |
|
135 | \begin{addmargin}[\cellleftmargin]{0em}% left, right | |
136 | {\smaller% |
|
136 | {\smaller% | |
137 | \par% |
|
137 | \par% | |
138 | ((* block extra_input_spacing *))((* endblock extra_input_spacing *))% |
|
138 | ((* block extra_input_spacing *))((* endblock extra_input_spacing *))% | |
139 | \vspace{-1\smallerfontscale}% |
|
139 | \vspace{-1\smallerfontscale}% | |
140 | ((( cell.input | highlight2latex )))% |
|
140 | ((( cell.input | highlight2latex )))% | |
141 | \par% |
|
141 | \par% | |
142 | \vspace{-1\smallerfontscale}}% |
|
142 | \vspace{-1\smallerfontscale}}% | |
143 | \end{addmargin} |
|
143 | \end{addmargin} | |
144 | \end{notebookcell} |
|
144 | \end{notebookcell} | |
145 |
|
145 | |||
146 | ((* endblock input *)) |
|
146 | ((* endblock input *)) | |
147 |
|
147 | |||
148 | %=============================================================================== |
|
148 | %=============================================================================== | |
149 | % Output |
|
149 | % Output | |
150 | %=============================================================================== |
|
150 | %=============================================================================== | |
151 |
|
151 | |||
152 | ((* block output -*)) |
|
152 | ((* block output -*)) | |
153 | \par\vspace{1\smallerfontscale}% |
|
153 | \par\vspace{1\smallerfontscale}% | |
154 | \needspace{4\baselineskip}% |
|
154 | \needspace{4\baselineskip}% | |
155 | % Only render the prompt if the cell is pyout. Note, the outputs prompt |
|
155 | % Only render the prompt if the cell is pyout. Note, the outputs prompt | |
156 | % block isn't used since we need to check each indiviual output and only |
|
156 | % block isn't used since we need to check each indiviual output and only | |
157 | % add prompts to the pyout ones. |
|
157 | % add prompts to the pyout ones. | |
158 | ((* if output.output_type in ['pyout'] *)) |
|
158 | ((* if output.output_type in ['pyout'] *)) | |
159 | {\par% |
|
159 | {\par% | |
160 | \vspace{-1\smallerfontscale}% |
|
160 | \vspace{-1\smallerfontscale}% | |
161 | \noindent% |
|
161 | \noindent% | |
162 | ((( draw_prompt("Out", cell.prompt_number, "nbframe-out-prompt", "0em") )))% |
|
162 | ((( draw_prompt("Out", cell.prompt_number, "nbframe-out-prompt", "0em") )))% | |
163 | ((* block extra_output_spacing *))((* endblock extra_output_spacing *))}% |
|
163 | ((* block extra_output_spacing *))((* endblock extra_output_spacing *))}% | |
164 | ((* endif *))% |
|
164 | ((* endif *))% | |
165 | % |
|
165 | % | |
166 | \begin{addmargin}[\cellleftmargin]{0em}% left, right |
|
166 | \begin{addmargin}[\cellleftmargin]{0em}% left, right | |
167 | {\smaller% |
|
167 | {\smaller% | |
168 | \vspace{-1\smallerfontscale}% |
|
168 | \vspace{-1\smallerfontscale}% | |
169 | ((( super() )))}% |
|
169 | ((( super() )))}% | |
170 | \end{addmargin}% |
|
170 | \end{addmargin}% | |
171 | ((*- endblock output *)) |
|
171 | ((*- endblock output *)) | |
172 |
|
172 | |||
173 | %============================================================================== |
|
173 | %============================================================================== | |
174 | % Support Macros |
|
174 | % Support Macros | |
175 | %============================================================================== |
|
175 | %============================================================================== | |
176 |
|
176 | |||
177 | % Name: draw_prompt |
|
177 | % Name: draw_prompt | |
178 | % Purpose: Renders an output/input prompt for notebook style pdfs |
|
178 | % Purpose: Renders an output/input prompt for notebook style pdfs | |
179 | ((* macro draw_prompt(prompt, number, color, space) -*)) |
|
179 | ((* macro draw_prompt(prompt, number, color, space) -*)) | |
180 | \begin{minipage}{\cellleftmargin}% |
|
180 | \begin{minipage}{\cellleftmargin}% | |
181 | \hfill% |
|
181 | \hfill% | |
182 | {\smaller% |
|
182 | {\smaller% | |
183 | \tt% |
|
183 | \tt% | |
184 | \color{(((color)))}% |
|
184 | \color{(((color)))}% | |
185 | (((prompt)))[(((number)))]:}% |
|
185 | (((prompt)))[(((number)))]:}% | |
186 | \hspace{\inputpadding}% |
|
186 | \hspace{\inputpadding}% | |
187 | \hspace{(((space)))}% |
|
187 | \hspace{(((space)))}% | |
188 | \hspace{3pt}% |
|
188 | \hspace{3pt}% | |
189 | \end{minipage}% |
|
189 | \end{minipage}% | |
190 | ((*- endmacro *)) |
|
190 | ((*- endmacro *)) | |
191 |
|
191 |
@@ -1,21 +1,21 b'' | |||||
1 | ((= Python input/output style =)) |
|
1 | ((= Python input/output style =)) | |
2 |
|
2 | |||
3 | ((*- extends 'latex_base.tplx' -*)) |
|
3 | ((*- extends 'latex_base.tplx' -*)) | |
4 |
|
4 | |||
5 | % Custom definitions |
|
5 | % Custom definitions | |
6 | ((* block definitions *)) |
|
6 | ((* block definitions *)) | |
7 | ((( super() ))) |
|
7 | ((( super() ))) | |
8 |
|
8 | |||
9 | % Pygments definitions |
|
9 | % Pygments definitions | |
10 | ((( resources.latex.pygment_definitions ))) |
|
10 | ((( resources.latex.pygments_definitions ))) | |
11 | ((* endblock definitions *)) |
|
11 | ((* endblock definitions *)) | |
12 |
|
12 | |||
13 | %=============================================================================== |
|
13 | %=============================================================================== | |
14 | % Input |
|
14 | % Input | |
15 | %=============================================================================== |
|
15 | %=============================================================================== | |
16 |
|
16 | |||
17 | ((* block input scoped *)) |
|
17 | ((* block input scoped *)) | |
18 | \begin{Verbatim}[commandchars=\\\{\}] |
|
18 | \begin{Verbatim}[commandchars=\\\{\}] | |
19 | ((( cell.input | highlight2latex(strip_verbatim=True) | add_prompts ))) |
|
19 | ((( cell.input | highlight2latex(strip_verbatim=True) | add_prompts ))) | |
20 | \end{Verbatim} |
|
20 | \end{Verbatim} | |
21 | ((* endblock input *)) |
|
21 | ((* endblock input *)) |
@@ -1,68 +1,68 b'' | |||||
1 | ((= Simple input/output style =)) |
|
1 | ((= Simple input/output style =)) | |
2 |
|
2 | |||
3 | ((*- extends 'latex_base.tplx' -*)) |
|
3 | ((*- extends 'latex_base.tplx' -*)) | |
4 |
|
4 | |||
5 | % Custom packages |
|
5 | % Custom packages | |
6 | ((* block packages *)) |
|
6 | ((* block packages *)) | |
7 | ((( super() ))) |
|
7 | ((( super() ))) | |
8 |
|
8 | |||
9 | \usepackage{needspace} % Make prompts follow contents |
|
9 | \usepackage{needspace} % Make prompts follow contents | |
10 | ((* endblock packages *)) |
|
10 | ((* endblock packages *)) | |
11 |
|
11 | |||
12 | % Custom definitions |
|
12 | % Custom definitions | |
13 | ((* block definitions *)) |
|
13 | ((* block definitions *)) | |
14 | ((( super() ))) |
|
14 | ((( super() ))) | |
15 |
|
15 | |||
16 | % Pygments definitions |
|
16 | % Pygments definitions | |
17 | ((( resources.latex.pygment_definitions ))) |
|
17 | ((( resources.latex.pygments_definitions ))) | |
18 |
|
18 | |||
19 | \newlength{\promptspace} |
|
19 | \newlength{\promptspace} | |
20 | \setlength{\promptspace}{4\baselineskip} % Space needed to start a new |
|
20 | \setlength{\promptspace}{4\baselineskip} % Space needed to start a new | |
21 | % input/output |
|
21 | % input/output | |
22 | ((* endblock definitions *)) |
|
22 | ((* endblock definitions *)) | |
23 | %=============================================================================== |
|
23 | %=============================================================================== | |
24 | % Input |
|
24 | % Input | |
25 | %=============================================================================== |
|
25 | %=============================================================================== | |
26 |
|
26 | |||
27 | ((*- block in_prompt scoped -*)) |
|
27 | ((*- block in_prompt scoped -*)) | |
28 | \par\vspace{-1\baselineskip} |
|
28 | \par\vspace{-1\baselineskip} | |
29 | ((( draw_prompt('Input') ))) |
|
29 | ((( draw_prompt('Input') ))) | |
30 | ((*- endblock in_prompt -*)) |
|
30 | ((*- endblock in_prompt -*)) | |
31 |
|
31 | |||
32 | ((*- block input_group scoped -*)) |
|
32 | ((*- block input_group scoped -*)) | |
33 | (((- super() ))) |
|
33 | (((- super() ))) | |
34 | \par\vspace{-2\baselineskip} |
|
34 | \par\vspace{-2\baselineskip} | |
35 | ((* endblock input_group -*)) |
|
35 | ((* endblock input_group -*)) | |
36 |
|
36 | |||
37 | ((* block input scoped *)) |
|
37 | ((* block input scoped *)) | |
38 | ((( cell.input | highlight2latex ))) |
|
38 | ((( cell.input | highlight2latex ))) | |
39 | ((* endblock input *)) |
|
39 | ((* endblock input *)) | |
40 |
|
40 | |||
41 | %=============================================================================== |
|
41 | %=============================================================================== | |
42 | % Output |
|
42 | % Output | |
43 | %=============================================================================== |
|
43 | %=============================================================================== | |
44 |
|
44 | |||
45 | ((*- block output_prompt scoped -*)) |
|
45 | ((*- block output_prompt scoped -*)) | |
46 | ((( draw_prompt('Output') ))) |
|
46 | ((( draw_prompt('Output') ))) | |
47 | ((*- endblock output_prompt -*)) |
|
47 | ((*- endblock output_prompt -*)) | |
48 |
|
48 | |||
49 | ((*- block output_group scoped -*)) |
|
49 | ((*- block output_group scoped -*)) | |
50 | (((- super() ))) |
|
50 | (((- super() ))) | |
51 | \par\vspace{-1\baselineskip} |
|
51 | \par\vspace{-1\baselineskip} | |
52 | ((* endblock output_group -*)) |
|
52 | ((* endblock output_group -*)) | |
53 |
|
53 | |||
54 | %============================================================================== |
|
54 | %============================================================================== | |
55 | % Support Macros |
|
55 | % Support Macros | |
56 | %============================================================================== |
|
56 | %============================================================================== | |
57 |
|
57 | |||
58 | % Name: draw_prompt |
|
58 | % Name: draw_prompt | |
59 | % Purpose: Renders an output/input prompt for notebook style pdfs |
|
59 | % Purpose: Renders an output/input prompt for notebook style pdfs | |
60 | ((* macro draw_prompt(prompt) *)) |
|
60 | ((* macro draw_prompt(prompt) *)) | |
61 | % Add a horizantal break, along with break title. |
|
61 | % Add a horizantal break, along with break title. | |
62 | \needspace{\promptspace} |
|
62 | \needspace{\promptspace} | |
63 | \br\br |
|
63 | \br\br | |
64 | {\scriptsize ((( prompt )))} |
|
64 | {\scriptsize ((( prompt )))} | |
65 | \br |
|
65 | \br | |
66 | \rule[10pt]{\linewidth}{0.5pt} |
|
66 | \rule[10pt]{\linewidth}{0.5pt} | |
67 | \vspace{-2.5em} |
|
67 | \vspace{-2.5em} | |
68 | ((* endmacro *)) |
|
68 | ((* endmacro *)) |
General Comments 0
You need to be logged in to leave comments.
Login now