Show More
@@ -1,373 +1,379 b'' | |||||
1 | ((= NBConvert Sphinx-Latex Template |
|
1 | ((= NBConvert Sphinx-Latex Template | |
2 |
|
2 | |||
3 | Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the |
|
3 | Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the | |
4 | template is derived directly from Sphinx source. |
|
4 | template is derived directly from Sphinx source. | |
5 |
|
5 | |||
6 | Inheritance: null>display_priority>latex_base |
|
6 | Inheritance: null>display_priority>latex_base | |
7 |
|
7 | |||
8 | Note: For best display, use latex syntax highlighting. =)) |
|
8 | Note: For best display, use latex syntax highlighting. =)) | |
9 |
|
9 | |||
10 | ((*- extends 'display_priority.tplx' -*)) |
|
10 | ((*- extends 'display_priority.tplx' -*)) | |
11 |
|
11 | |||
12 | %============================================================================== |
|
12 | %============================================================================== | |
13 | % Declarations |
|
13 | % Declarations | |
14 | %============================================================================== |
|
14 | %============================================================================== | |
15 |
|
15 | |||
16 | % In order to make sure that the input/output header follows the code it |
|
16 | % In order to make sure that the input/output header follows the code it | |
17 | % preceeds, the needspace package is used to request that a certain |
|
17 | % preceeds, the needspace package is used to request that a certain | |
18 | % amount of lines (specified by this variable) are reserved. If those |
|
18 | % amount of lines (specified by this variable) are reserved. If those | |
19 | % lines aren't available on the current page, the documenter will break |
|
19 | % lines aren't available on the current page, the documenter will break | |
20 | % to the next page and the header along with accomanying lines will be |
|
20 | % to the next page and the header along with accomanying lines will be | |
21 | % rendered together. This value specifies the number of lines that |
|
21 | % rendered together. This value specifies the number of lines that | |
22 | % the header will be forced to group with without a page break. |
|
22 | % the header will be forced to group with without a page break. | |
23 | ((*- set min_header_lines = 4 -*)) |
|
23 | ((*- set min_header_lines = 4 -*)) | |
24 |
|
24 | |||
25 | % This is the number of characters that are permitted per line. It's |
|
25 | % This is the number of characters that are permitted per line. It's | |
26 | % important that this limit is set so characters do not run off the |
|
26 | % important that this limit is set so characters do not run off the | |
27 | % edges of latex pages (since latex does not always seem smart enough |
|
27 | % edges of latex pages (since latex does not always seem smart enough | |
28 | % to prevent this in some cases.) This is only applied to textual output |
|
28 | % to prevent this in some cases.) This is only applied to textual output | |
29 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
29 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |
30 | ((*- set wrap_size = 85 -*)) |
|
30 | ((*- set wrap_size = 85 -*)) | |
31 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
31 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
32 | ((*- set wrap_size = 70 -*)) |
|
32 | ((*- set wrap_size = 70 -*)) | |
33 | ((* endif *)) |
|
33 | ((* endif *)) | |
34 |
|
34 | |||
35 | %============================================================================== |
|
35 | %============================================================================== | |
36 | % Header |
|
36 | % Header | |
37 | %============================================================================== |
|
37 | %============================================================================== | |
38 | ((* block header *)) |
|
38 | ((* block header *)) | |
39 |
|
39 | |||
40 | % Header, overrides base |
|
40 | % Header, overrides base | |
41 |
|
41 | |||
42 | % Make sure that the sphinx doc style knows who it inherits from. |
|
42 | % Make sure that the sphinx doc style knows who it inherits from. | |
43 | \def\sphinxdocclass{(((parentdocumentclass)))} |
|
43 | \def\sphinxdocclass{(((parentdocumentclass)))} | |
44 |
|
44 | |||
45 | % Declare the document class |
|
45 | % Declare the document class | |
46 | \documentclass[letterpaper,10pt,english]{((( resources.sphinx.texinputs )))/sphinx(((documentclass)))} |
|
46 | \documentclass[letterpaper,10pt,english]{((( resources.sphinx.texinputs )))/sphinx(((documentclass)))} | |
47 |
|
47 | |||
48 | % Imports |
|
48 | % Imports | |
49 | \usepackage[utf8]{inputenc} |
|
49 | \usepackage[utf8]{inputenc} | |
50 | \DeclareUnicodeCharacter{00A0}{\\nobreakspace} |
|
50 | \DeclareUnicodeCharacter{00A0}{\\nobreakspace} | |
51 | \usepackage[T1]{fontenc} |
|
51 | \usepackage[T1]{fontenc} | |
52 | \usepackage{babel} |
|
52 | \usepackage{babel} | |
53 | \usepackage{times} |
|
53 | \usepackage{times} | |
54 | \usepackage{import} |
|
54 | \usepackage{import} | |
55 | \usepackage[((( resources.sphinx.chapterstyle )))]{((( resources.sphinx.texinputs )))/fncychap} |
|
55 | \usepackage[((( resources.sphinx.chapterstyle )))]{((( resources.sphinx.texinputs )))/fncychap} | |
56 | \usepackage{longtable} |
|
56 | \usepackage{longtable} | |
57 | \usepackage{((( resources.sphinx.texinputs )))/sphinx} |
|
57 | \usepackage{((( resources.sphinx.texinputs )))/sphinx} | |
58 | \usepackage{multirow} |
|
58 | \usepackage{multirow} | |
59 |
|
59 | |||
60 | \usepackage{amsmath} |
|
60 | \usepackage{amsmath} | |
61 | \usepackage{amssymb} |
|
61 | \usepackage{amssymb} | |
62 | \usepackage{ucs} |
|
62 | \usepackage{ucs} | |
63 | \usepackage{enumerate} |
|
63 | \usepackage{enumerate} | |
64 |
|
64 | |||
65 | % Used to make the Input/Output rules follow around the contents. |
|
65 | % Used to make the Input/Output rules follow around the contents. | |
66 | \usepackage{needspace} |
|
66 | \usepackage{needspace} | |
67 |
|
67 | |||
68 | % Pygments requirements |
|
68 | % Pygments requirements | |
69 | \usepackage{fancyvrb} |
|
69 | \usepackage{fancyvrb} | |
70 | \usepackage{color} |
|
70 | \usepackage{color} | |
71 |
|
71 | |||
72 | % Needed to box output/input |
|
72 | % Needed to box output/input | |
73 | \usepackage{mdframed} |
|
73 | \usepackage{mdframed} | |
74 | \usepackage{alltt} |
|
74 | \usepackage{alltt} | |
75 |
|
75 | |||
76 | % Used to load and display graphics |
|
76 | % Used to load and display graphics | |
77 | \usepackage{graphicx} |
|
77 | \usepackage{graphicx} | |
78 | \graphicspath{ {figs/} } |
|
78 | \graphicspath{ {figs/} } | |
79 | \usepackage[export]{adjustbox} % To resize |
|
79 | \usepackage[export]{adjustbox} % To resize | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | % For formatting output while also word wrapping. |
|
82 | % For formatting output while also word wrapping. | |
83 | \usepackage{listings} |
|
83 | \usepackage{listings} | |
84 | \lstset{breaklines=true} |
|
84 | \lstset{breaklines=true} | |
85 | \lstset{basicstyle=\small\ttfamily} |
|
85 | \lstset{basicstyle=\small\ttfamily} | |
86 |
|
86 | |||
87 | %Pygments definitions |
|
87 | %Pygments definitions | |
88 | ((( resources.sphinx.pygment_definitions ))) |
|
88 | ((( resources.sphinx.pygment_definitions ))) | |
89 |
|
89 | |||
90 | %Set pygments styles if needed... |
|
90 | %Set pygments styles if needed... | |
91 | ((* if resources.sphinx.outputstyle == 'notebook' *)) |
|
91 | ((* if resources.sphinx.outputstyle == 'notebook' *)) | |
92 | \definecolor{nbframe-border}{rgb}{0.8,0.8,0.8} |
|
92 | \definecolor{nbframe-border}{rgb}{0.8,0.8,0.8} | |
93 | \definecolor{nbframe-bg}{rgb}{0.95,0.95,0.95} |
|
93 | \definecolor{nbframe-bg}{rgb}{0.95,0.95,0.95} | |
|
94 | \definecolor{nbframe-prompt}{rgb}{0.05,0.05,0.3} | |||
94 |
|
95 | |||
95 | \newenvironment{ColorVerbatim} |
|
96 | \newenvironment{ColorVerbatim} | |
96 |
{\begin{mdframed}[backgroundcolor=nbframe-bg, |
|
97 | {\begin{mdframed}[backgroundcolor=nbframe-bg, userdefinedwidth=1\linewidth, leftmargin=0.08\linewidth, linecolor=nbframe-border, linewidth=1pt, usetwoside=false]} | |
97 | {\end{mdframed}} |
|
98 | {\end{mdframed}} | |
98 |
|
99 | |||
99 | \renewenvironment{Verbatim}[1][\unskip] |
|
100 | \renewenvironment{Verbatim}[1][\unskip] | |
100 | {\begin{alltt}} |
|
101 | {\begin{alltt}} | |
101 | {\end{alltt}} |
|
102 | {\end{alltt}} | |
102 | ((* endif *)) |
|
103 | ((* endif *)) | |
103 |
|
104 | |||
104 | % Help prevent overflowing lines due to urls and other hard-to-break |
|
105 | % Help prevent overflowing lines due to urls and other hard-to-break | |
105 | % entities. This doesn't catch everything... |
|
106 | % entities. This doesn't catch everything... | |
106 | \sloppy |
|
107 | \sloppy | |
107 |
|
108 | |||
108 | % Document level variables |
|
109 | % Document level variables | |
109 | \title{((( nb.metadata.name | escape_tex )))} |
|
110 | \title{((( nb.metadata.name | escape_tex )))} | |
110 | \date{((( nb.metadata._draft.date | escape_tex )))} |
|
111 | \date{((( nb.metadata._draft.date | escape_tex )))} | |
111 | \release{((( nb.metadata._draft.version | escape_tex )))} |
|
112 | \release{((( nb.metadata._draft.version | escape_tex )))} | |
112 | \author{((( nb.metadata._draft.author | escape_tex )))} |
|
113 | \author{((( nb.metadata._draft.author | escape_tex )))} | |
113 | \renewcommand{\releasename}{((( nb.metadata._draft.release | escape_tex )))} |
|
114 | \renewcommand{\releasename}{((( nb.metadata._draft.release | escape_tex )))} | |
114 |
|
115 | |||
115 | % TODO: Add option for the user to specify a logo for his/her export. |
|
116 | % TODO: Add option for the user to specify a logo for his/her export. | |
116 | \newcommand{\sphinxlogo}{} |
|
117 | \newcommand{\sphinxlogo}{} | |
117 |
|
118 | |||
118 | % Make the index page of the document. |
|
119 | % Make the index page of the document. | |
119 | \makeindex |
|
120 | \makeindex | |
120 |
|
121 | |||
121 | % Import sphinx document type specifics. |
|
122 | % Import sphinx document type specifics. | |
122 | ((* block sphinxheader *))((* endblock sphinxheader *)) |
|
123 | ((* block sphinxheader *))((* endblock sphinxheader *)) | |
123 | ((* endblock header *)) |
|
124 | ((* endblock header *)) | |
124 |
|
125 | |||
125 | %============================================================================== |
|
126 | %============================================================================== | |
126 | % Body |
|
127 | % Body | |
127 | %============================================================================== |
|
128 | %============================================================================== | |
128 | ((* block body *)) |
|
129 | ((* block body *)) | |
129 | ((* block bodyBegin *)) |
|
130 | ((* block bodyBegin *)) | |
130 | % Body |
|
131 | % Body | |
131 |
|
132 | |||
132 | % Start of the document |
|
133 | % Start of the document | |
133 | \begin{document} |
|
134 | \begin{document} | |
134 | \maketitle |
|
135 | \maketitle | |
|
136 | ||||
|
137 | ((* block toc *)) | |||
135 | \tableofcontents |
|
138 | \tableofcontents | |
|
139 | ((* endblock toc *)) | |||
136 |
|
140 | |||
137 | ((* endblock bodyBegin *))((( super() )))((* block bodyEnd *)) |
|
141 | ((* endblock bodyBegin *))((( super() )))((* block bodyEnd *)) | |
138 |
|
142 | |||
139 | \renewcommand{\indexname}{Index} |
|
143 | \renewcommand{\indexname}{Index} | |
140 | \printindex |
|
144 | \printindex | |
141 |
|
145 | |||
142 | % End of document |
|
146 | % End of document | |
143 | \end{document} |
|
147 | \end{document} | |
144 | ((* endblock bodyEnd *)) |
|
148 | ((* endblock bodyEnd *)) | |
145 | ((* endblock body *)) |
|
149 | ((* endblock body *)) | |
146 |
|
150 | |||
147 | %============================================================================== |
|
151 | %============================================================================== | |
148 | % Footer |
|
152 | % Footer | |
149 | %============================================================================== |
|
153 | %============================================================================== | |
150 | ((* block footer *)) |
|
154 | ((* block footer *)) | |
151 | ((* endblock footer *)) |
|
155 | ((* endblock footer *)) | |
152 |
|
156 | |||
153 | %============================================================================== |
|
157 | %============================================================================== | |
154 | % Headings |
|
158 | % Headings | |
155 | % |
|
159 | % | |
156 | % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx |
|
160 | % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx | |
157 | % style that is active, this will change. Thus sphinx styles will |
|
161 | % style that is active, this will change. Thus sphinx styles will | |
158 | % override the values here. |
|
162 | % override the values here. | |
159 | %============================================================================== |
|
163 | %============================================================================== | |
160 | ((* block headingcell -*)) |
|
164 | ((* block headingcell -*)) | |
161 | \ |
|
165 | \ | |
162 | ((*- if cell.level == 1 -*)) |
|
166 | ((*- if cell.level == 1 -*)) | |
163 | ((* block h1 -*))part((* endblock h1 -*)) |
|
167 | ((* block h1 -*))part((* endblock h1 -*)) | |
164 | ((*- elif cell.level == 2 -*)) |
|
168 | ((*- elif cell.level == 2 -*)) | |
165 | ((* block h2 -*))chapter((* endblock h2 -*)) |
|
169 | ((* block h2 -*))chapter((* endblock h2 -*)) | |
166 | ((*- elif cell.level == 3 -*)) |
|
170 | ((*- elif cell.level == 3 -*)) | |
167 | ((* block h3 -*))section((* endblock h3 -*)) |
|
171 | ((* block h3 -*))section((* endblock h3 -*)) | |
168 | ((*- elif cell.level == 4 -*)) |
|
172 | ((*- elif cell.level == 4 -*)) | |
169 | ((* block h4 -*))subsection((* endblock h4 -*)) |
|
173 | ((* block h4 -*))subsection((* endblock h4 -*)) | |
170 | ((*- elif cell.level == 5 -*)) |
|
174 | ((*- elif cell.level == 5 -*)) | |
171 | ((* block h5 -*))subsubsection((* endblock h5 -*)) |
|
175 | ((* block h5 -*))subsubsection((* endblock h5 -*)) | |
172 | ((*- elif cell.level == 6 -*)) |
|
176 | ((*- elif cell.level == 6 -*)) | |
173 | ((* block h6 -*))paragraph((* endblock h6 -*)) |
|
177 | ((* block h6 -*))paragraph((* endblock h6 -*)) | |
174 |
|
178 | |||
175 | ((= It's important to make sure that underscores (which tend to be common |
|
179 | ((= It's important to make sure that underscores (which tend to be common | |
176 | in IPYNB file titles) do not make their way into latex. Sometimes this |
|
180 | in IPYNB file titles) do not make their way into latex. Sometimes this | |
177 | causes latex to barf. =)) |
|
181 | causes latex to barf. =)) | |
178 | ((*- endif -*)){((( escape_underscores(cell.source | markdown2latex ) )))} |
|
182 | ((*- endif -*)){((( escape_underscores(cell.source | markdown2latex ) )))} | |
179 | ((*- endblock headingcell *)) |
|
183 | ((*- endblock headingcell *)) | |
180 |
|
184 | |||
181 | %============================================================================== |
|
185 | %============================================================================== | |
182 | % Markdown |
|
186 | % Markdown | |
183 | % |
|
187 | % | |
184 | % Purpose: Convert markdown to latex. Here markdown2latex is explicitly |
|
188 | % Purpose: Convert markdown to latex. Here markdown2latex is explicitly | |
185 | % called since we know we want latex output. |
|
189 | % called since we know we want latex output. | |
186 | %============================================================================== |
|
190 | %============================================================================== | |
187 | ((*- block markdowncell scoped-*)) |
|
191 | ((*- block markdowncell scoped-*)) | |
188 | ((( cell.source | markdown2latex ))) |
|
192 | ((( cell.source | markdown2latex ))) | |
189 | ((*- endblock markdowncell -*)) |
|
193 | ((*- endblock markdowncell -*)) | |
190 |
|
194 | |||
191 | %============================================================================== |
|
195 | %============================================================================== | |
192 | % Rawcell |
|
196 | % Rawcell | |
193 | % |
|
197 | % | |
194 | % Purpose: Raw text cells allow the user to manually inject document code that |
|
198 | % Purpose: Raw text cells allow the user to manually inject document code that | |
195 | % will not get touched by the templating system. |
|
199 | % will not get touched by the templating system. | |
196 | %============================================================================== |
|
200 | %============================================================================== | |
197 | ((*- block rawcell *)) |
|
201 | ((*- block rawcell *)) | |
198 | ((( cell.source | wrap(wrap_size) ))) |
|
202 | ((( cell.source | wrap(wrap_size) ))) | |
199 | ((* endblock rawcell -*)) |
|
203 | ((* endblock rawcell -*)) | |
200 |
|
204 | |||
201 | %============================================================================== |
|
205 | %============================================================================== | |
202 | % Unknowncell |
|
206 | % Unknowncell | |
203 | % |
|
207 | % | |
204 | % Purpose: This is the catch anything unhandled. To display this data, we |
|
208 | % Purpose: This is the catch anything unhandled. To display this data, we | |
205 | % remove all possible latex conflicts and wrap the characters so they |
|
209 | % remove all possible latex conflicts and wrap the characters so they | |
206 | % can't flow off of the page. |
|
210 | % can't flow off of the page. | |
207 | %============================================================================== |
|
211 | %============================================================================== | |
208 | ((* block unknowncell scoped*)) |
|
212 | ((* block unknowncell scoped*)) | |
209 |
|
213 | |||
210 | % Unsupported cell type, no formatting |
|
214 | % Unsupported cell type, no formatting | |
211 | ((( cell.source | wrap | escape_tex ))) |
|
215 | ((( cell.source | wrap | escape_tex ))) | |
212 | ((* endblock unknowncell *)) |
|
216 | ((* endblock unknowncell *)) | |
213 |
|
217 | |||
214 | %============================================================================== |
|
218 | %============================================================================== | |
215 | % Input |
|
219 | % Input | |
216 | %============================================================================== |
|
220 | %============================================================================== | |
217 | ((* block input *)) |
|
221 | ((* block input *)) | |
218 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
222 | ||
219 |
|
|
223 | % Make sure that atleast 4 lines are below the HR | |
220 |
|
|
224 | \needspace{((( min_header_lines )))\baselineskip} | |
221 |
|
225 | |||
|
226 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |||
|
227 | ||||
222 | % Add a horizantal break, along with break title. |
|
228 | % Add a horizantal break, along with break title. | |
223 | \vspace{10pt} |
|
229 | \vspace{10pt} | |
224 | {\scriptsize Input}\\* |
|
230 | {\scriptsize Input}\\* | |
225 | \rule[10pt]{\linewidth}{0.5pt} |
|
231 | \rule[10pt]{\linewidth}{0.5pt} | |
226 | \vspace{-25pt} |
|
232 | \vspace{-25pt} | |
227 |
|
233 | |||
228 | % Add contents below. |
|
234 | % Add contents below. | |
229 | ((( cell.input | highlight ))) |
|
235 | ((( cell.input | highlight ))) | |
230 |
|
236 | |||
231 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
237 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
232 | \textbf{In {[}((( cell.prompt_number ))){]}:}\\* |
|
238 | \vspace{5pt} | |
233 | \vspace{-2.4\baselineskip} |
|
239 | {\color{nbframe-prompt}\textbf{In {[}((( cell.prompt_number ))){]}:}}\\* | |
|
240 | \vspace{-2.6\baselineskip} | |||
234 | \begin{ColorVerbatim} |
|
241 | \begin{ColorVerbatim} | |
|
242 | \vspace{-0.5\baselineskip} | |||
235 | ((( cell.input | highlight ))) |
|
243 | ((( cell.input | highlight ))) | |
236 | \end{ColorVerbatim} |
|
244 | \end{ColorVerbatim} | |
237 | ((* endif *)) |
|
245 | ((* endif *)) | |
238 | ((* endblock input *)) |
|
246 | ((* endblock input *)) | |
239 |
|
247 | |||
240 | %============================================================================== |
|
248 | %============================================================================== | |
241 | % Output_Group |
|
249 | % Output_Group | |
242 | % |
|
250 | % | |
243 | % Purpose: Make sure that only one header bar only attaches to the output |
|
251 | % Purpose: Make sure that only one header bar only attaches to the output | |
244 | % once. By keeping track of when an input group is started |
|
252 | % once. By keeping track of when an input group is started | |
245 | %============================================================================== |
|
253 | %============================================================================== | |
246 | ((* block output_group *)) |
|
254 | ((* block output_group *)) | |
|
255 | ((* if cell.outputs.__len__() > 0 *)) | |||
247 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
256 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |
248 |
|
257 | |||
249 | % If the first block is an image, minipage the image. Else |
|
258 | % If the first block is an image, minipage the image. Else | |
250 | % request a certain amount of space for the input text. |
|
259 | % request a certain amount of space for the input text. | |
251 | ((( iff_figure(cell.outputs[0], "\\begin{minipage}{1.0\\textwidth}", "\\needspace{" ~ min_header_lines ~ "\\baselineskip}") ))) |
|
260 | ((( iff_figure(cell.outputs[0], "\\begin{minipage}{1.0\\textwidth}", "\\needspace{" ~ min_header_lines ~ "\\baselineskip}") ))) | |
252 |
|
261 | |||
253 | % Add a horizantal break, along with break title. |
|
262 | % Add a horizantal break, along with break title. | |
254 | \vspace{10pt} |
|
263 | \vspace{10pt} | |
255 | {\scriptsize Output}\\* |
|
264 | {\scriptsize Output}\\* | |
256 | \rule[10pt]{\linewidth}{0.5pt} |
|
265 | \rule[10pt]{\linewidth}{0.5pt} | |
257 | \vspace{-20pt} |
|
266 | \vspace{-20pt} | |
258 |
|
267 | |||
259 | % Add the contents of the first block. |
|
268 | % Add the contents of the first block. | |
260 | ((( render_output(cell.outputs[0]) ))) |
|
269 | ((( render_output(cell.outputs[0]) ))) | |
261 |
|
270 | |||
262 | % Close the minipage. |
|
271 | % Close the minipage. | |
263 | ((( iff_figure(cell.outputs[0], "\\end{minipage}", "") ))) |
|
272 | ((( iff_figure(cell.outputs[0], "\\end{minipage}", "") ))) | |
264 |
|
273 | |||
265 | % Add remainer of the document contents below. |
|
274 | % Add remainer of the document contents below. | |
266 | ((* for output in cell.outputs[1:] *)) |
|
275 | ((* for output in cell.outputs[1:] *)) | |
267 | ((( render_output(output) ))) |
|
276 | ((( render_output(output) ))) | |
268 | ((* endfor *)) |
|
277 | ((* endfor *)) | |
269 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
278 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
270 |
|
279 | |||
271 | %Skip one line down. |
|
280 | %Skip one line down. | |
272 | \vspace{1\baselineskip} |
|
281 | \vspace{1\baselineskip} | |
273 |
|
282 | |||
274 | % Add document contents. |
|
283 | % Add document contents. | |
275 | \begin{ColorVerbatim} |
|
284 | \begin{ColorVerbatim} | |
276 | ((* for output in cell.outputs *)) |
|
285 | ((* for output in cell.outputs *)) | |
277 | ((( render_output(output) ))) |
|
286 | ((( render_output(output) ))) | |
278 | ((* endfor *)) |
|
287 | ((* endfor *)) | |
279 | \end{ColorVerbatim} |
|
288 | \end{ColorVerbatim} | |
280 | ((* endif *)) |
|
289 | ((* endif *)) | |
|
290 | ((* endif *)) | |||
281 | ((* endblock *)) |
|
291 | ((* endblock *)) | |
282 |
|
292 | |||
283 | %============================================================================== |
|
293 | %============================================================================== | |
284 | % Additional formating |
|
294 | % Additional formating | |
285 | %============================================================================== |
|
295 | %============================================================================== | |
286 | ((* block data_text *)) |
|
296 | ((* block data_text *)) | |
287 | ((( custom_verbatim(output.text) ))) |
|
297 | ((( custom_verbatim(output.text) ))) | |
288 | ((* endblock *)) |
|
298 | ((* endblock *)) | |
289 |
|
299 | |||
290 | ((* block traceback_line *)) |
|
300 | ((* block traceback_line *)) | |
291 | ((( line | indent| rm_ansi ))) |
|
301 | ((( line | indent| rm_ansi ))) | |
292 | ((* endblock traceback_line *)) |
|
302 | ((* endblock traceback_line *)) | |
293 |
|
303 | |||
294 | %============================================================================== |
|
304 | %============================================================================== | |
295 | % Supported image formats |
|
305 | % Supported image formats | |
296 | %============================================================================== |
|
306 | %============================================================================== | |
297 | ((*- block data_png -*)) |
|
307 | ((*- block data_png -*)) | |
298 | ((( insert_graphics(output.key_png) ))) |
|
308 | ((( insert_graphics(output.key_png) ))) | |
299 | ((*- endblock -*)) |
|
309 | ((*- endblock -*)) | |
300 |
|
310 | |||
301 | ((*- block data_svg -*)) |
|
311 | ((*- block data_svg -*)) | |
302 | ((( insert_graphics(output.key_svg) ))) |
|
312 | ((( insert_graphics(output.key_svg) ))) | |
303 | ((*- endblock -*)) |
|
313 | ((*- endblock -*)) | |
304 |
|
314 | |||
|
315 | ((*- block data_latex *)) | |||
|
316 | ((( output.latex ))) | |||
|
317 | ((* endblock -*)) | |||
|
318 | ||||
305 | %============================================================================== |
|
319 | %============================================================================== | |
306 | % Support Macros |
|
320 | % Support Macros | |
307 | %============================================================================== |
|
321 | %============================================================================== | |
308 |
|
322 | |||
309 | % Name: render_output |
|
323 | % Name: render_output | |
310 | % Purpose: Renders an output block appropriately. |
|
324 | % Purpose: Renders an output block appropriately. | |
311 | ((* macro render_output(output) -*)) |
|
325 | ((* macro render_output(output) -*)) | |
312 |
((*- if output.output_type == 'py |
|
326 | ((*- if output.output_type == 'pyerr' -*)) | |
313 |
((*- block py |
|
327 | ((*- block pyerr scoped *)) | |
314 | ((( custom_verbatim(super()) ))) |
|
328 | ((( custom_verbatim(super()) ))) | |
315 |
((* |
|
329 | ((* endblock pyerr -*)) | |
316 | ((*- elif output.output_type == 'stream' -*)) |
|
330 | ((*- else -*)) | |
317 | ((*- block stream scoped -*)) |
|
|||
318 | ((( custom_verbatim(output.text) ))) |
|
|||
319 | ((*- endblock stream -*)) |
|
|||
320 | ((*- elif output.output_type == 'display_data' -*)) |
|
|||
321 | ((*- block display_data scoped -*)) |
|
331 | ((*- block display_data scoped -*)) | |
322 | ((( super() ))) |
|
332 | ((( super() ))) | |
323 | ((*- endblock display_data -*)) |
|
333 | ((*- endblock display_data -*)) | |
324 | ((*- elif output.output_type == 'pyerr' -*)) |
|
|||
325 | ((*- block pyerr scoped -*)) |
|
|||
326 | ((( custom_verbatim(super()) ))) |
|
|||
327 | ((*- endblock pyerr -*)) |
|
|||
328 | ((*- endif -*)) |
|
334 | ((*- endif -*)) | |
329 | ((*- endmacro *)) |
|
335 | ((*- endmacro *)) | |
330 |
|
336 | |||
331 | % Name: iff_figure |
|
337 | % Name: iff_figure | |
332 | % Purpose: If the output block provided is a figure type, the 'true_content' |
|
338 | % Purpose: If the output block provided is a figure type, the 'true_content' | |
333 | % parameter will be returned. Else, the 'false_content'. |
|
339 | % parameter will be returned. Else, the 'false_content'. | |
334 | ((* macro iff_figure(output, true_content, false_content) -*)) |
|
340 | ((* macro iff_figure(output, true_content, false_content) -*)) | |
335 | ((* if output.output_type in ['display_data'] -*)) |
|
341 | ((* if output.output_type in ['display_data'] -*)) | |
336 | ((( true_content ))) |
|
342 | ((( true_content ))) | |
337 | ((*- else -*)) |
|
343 | ((*- else -*)) | |
338 | ((( false_content ))) |
|
344 | ((( false_content ))) | |
339 | ((*- endif *)) |
|
345 | ((*- endif *)) | |
340 | ((*- endmacro *)) |
|
346 | ((*- endmacro *)) | |
341 |
|
347 | |||
342 | % Name: custom_verbatim |
|
348 | % Name: custom_verbatim | |
343 | % Purpose: This macro creates a verbatim style block that fits the existing |
|
349 | % Purpose: This macro creates a verbatim style block that fits the existing | |
344 | % sphinx style more readily than standard verbatim blocks. |
|
350 | % sphinx style more readily than standard verbatim blocks. | |
345 | ((* macro custom_verbatim(text) -*)) |
|
351 | ((* macro custom_verbatim(text) -*)) | |
346 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
352 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |
347 | \begin{lstlisting} |
|
353 | \begin{lstlisting} | |
348 | ((( text | wrap(wrap_size) ))) |
|
354 | ((( text | wrap(wrap_size) ))) | |
349 | \end{lstlisting} |
|
355 | \end{lstlisting} | |
350 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
356 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
351 | \begin{alltt} |
|
357 | \begin{alltt} | |
352 | ((( text | wrap(wrap_size) ))) |
|
358 | ((( text | wrap(wrap_size) ))) | |
353 | \end{alltt} |
|
359 | \end{alltt} | |
354 | ((* endif *)) |
|
360 | ((* endif *)) | |
355 | ((*- endmacro *)) |
|
361 | ((*- endmacro *)) | |
356 |
|
362 | |||
357 | % Name: insert_graphics |
|
363 | % Name: insert_graphics | |
358 | % Purpose: This macro will insert an image in the latex document given a path. |
|
364 | % Purpose: This macro will insert an image in the latex document given a path. | |
359 | ((* macro insert_graphics(path) -*)) |
|
365 | ((* macro insert_graphics(path) -*)) | |
360 | \begin{center} |
|
366 | \begin{center} | |
361 | \includegraphics[max width=0.7\textwidth]{(((path)))} |
|
367 | \includegraphics[max width=0.7\textwidth]{(((path)))} | |
362 | \par |
|
368 | \par | |
363 | \end{center} |
|
369 | \end{center} | |
364 | ((*- endmacro *)) |
|
370 | ((*- endmacro *)) | |
365 |
|
371 | |||
366 | % Name: escape_underscores |
|
372 | % Name: escape_underscores | |
367 | % Purpose: Underscores cause a problem in latex. It's important that we |
|
373 | % Purpose: Underscores cause a problem in latex. It's important that we | |
368 | % escape any underscores that appear. |
|
374 | % escape any underscores that appear. | |
369 | ((* macro escape_underscores(text) -*)) |
|
375 | ((* macro escape_underscores(text) -*)) | |
370 | ((*- set text = text|replace("_","\\_") -*)) |
|
376 | ((*- set text = text|replace("_","\\_") -*)) | |
371 | ((( text ))) |
|
377 | ((( text ))) | |
372 | ((*- endmacro *)) |
|
378 | ((*- endmacro *)) | |
373 |
|
379 |
General Comments 0
You need to be logged in to leave comments.
Login now