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