##// END OF EJS Templates
Needspace for the output regardless of output style.
Jonathan Frederic -
Show More
@@ -1,438 +1,439 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 \usepackage{alltt}
78 78
79 79 % Used to load and display graphics
80 80 \usepackage{graphicx}
81 81 \graphicspath{ {figs/} }
82 82 \usepackage[Export]{adjustbox} % To resize
83 83
84 84
85 85 % For formatting output while also word wrapping.
86 86 \usepackage{listings}
87 87 \lstset{breaklines=true}
88 88 \lstset{basicstyle=\small\ttfamily}
89 89 \def\smaller{\fontsize{9.5pt}{9.5pt}\selectfont}
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 needspace=0pt
120 120 ]}
121 121 {\end{mdframed}}
122 122
123 123 \newenvironment{InvisibleVerbatim}
124 124 {\begin{mdframed}[leftmargin=0.1\linewidth,innerleftmargin=3pt,innerrightmargin=3pt, userdefinedwidth=1\linewidth, linewidth=0pt, linecolor=white, usetwoside=false]}
125 125 {\end{mdframed}}
126 126
127 127 \renewenvironment{Verbatim}[1][\unskip]
128 128 {\begin{alltt}\smaller}
129 129 {\end{alltt}}
130 130 ((* endif *))
131 131
132 132 % Help prevent overflowing lines due to urls and other hard-to-break
133 133 % entities. This doesn't catch everything...
134 134 \sloppy
135 135
136 136 % Document level variables
137 137 \title{((( nb.metadata.name | escape_tex )))}
138 138 \date{((( nb.metadata._draft.date | escape_tex )))}
139 139 \release{((( nb.metadata._draft.version | escape_tex )))}
140 140 \author{((( nb.metadata._draft.author | escape_tex )))}
141 141 \renewcommand{\releasename}{((( nb.metadata._draft.release | escape_tex )))}
142 142
143 143 % TODO: Add option for the user to specify a logo for his/her export.
144 144 \newcommand{\sphinxlogo}{}
145 145
146 146 % Make the index page of the document.
147 147 \makeindex
148 148
149 149 % Import sphinx document type specifics.
150 150 ((* block sphinxheader *))((* endblock sphinxheader *))
151 151 ((* endblock header *))
152 152
153 153 %==============================================================================
154 154 % Body
155 155 %==============================================================================
156 156 ((* block body *))
157 157 ((* block bodyBegin *))
158 158 % Body
159 159
160 160 % Start of the document
161 161 \begin{document}
162 162
163 163 ((* if resources.sphinx.header *))
164 164 \maketitle
165 165 ((* endif *))
166 166
167 167 ((* block toc *))
168 168 \tableofcontents
169 169 ((* endblock toc *))
170 170
171 171 ((* endblock bodyBegin *))((( super() )))((* block bodyEnd *))
172 172
173 173 \renewcommand{\indexname}{Index}
174 174 \printindex
175 175
176 176 % End of document
177 177 \end{document}
178 178 ((* endblock bodyEnd *))
179 179 ((* endblock body *))
180 180
181 181 %==============================================================================
182 182 % Footer
183 183 %==============================================================================
184 184 ((* block footer *))
185 185 ((* endblock footer *))
186 186
187 187 %==============================================================================
188 188 % Headings
189 189 %
190 190 % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx
191 191 % style that is active, this will change. Thus sphinx styles will
192 192 % override the values here.
193 193 %==============================================================================
194 194 ((* block headingcell -*))
195 195 \
196 196 ((*- if cell.level == 1 -*))
197 197 ((* block h1 -*))part((* endblock h1 -*))
198 198 ((*- elif cell.level == 2 -*))
199 199 ((* block h2 -*))chapter((* endblock h2 -*))
200 200 ((*- elif cell.level == 3 -*))
201 201 ((* block h3 -*))section((* endblock h3 -*))
202 202 ((*- elif cell.level == 4 -*))
203 203 ((* block h4 -*))subsection((* endblock h4 -*))
204 204 ((*- elif cell.level == 5 -*))
205 205 ((* block h5 -*))subsubsection((* endblock h5 -*))
206 206 ((*- elif cell.level == 6 -*))
207 207 ((* block h6 -*))paragraph((* endblock h6 -*))
208 208
209 209 ((= It's important to make sure that underscores (which tend to be common
210 210 in IPYNB file titles) do not make their way into latex. Sometimes this
211 211 causes latex to barf. =))
212 212 ((*- endif -*)){((( escape_underscores(cell.source | markdown2latex ) )))}
213 213 ((*- endblock headingcell *))
214 214
215 215 %==============================================================================
216 216 % Markdown
217 217 %
218 218 % Purpose: Convert markdown to latex. Here markdown2latex is explicitly
219 219 % called since we know we want latex output.
220 220 %==============================================================================
221 221 ((*- block markdowncell scoped-*))
222 222 ((( cell.source | markdown2latex )))
223 223 ((*- endblock markdowncell -*))
224 224
225 225 %==============================================================================
226 226 % Rawcell
227 227 %
228 228 % Purpose: Raw text cells allow the user to manually inject document code that
229 229 % will not get touched by the templating system.
230 230 %==============================================================================
231 231 ((*- block rawcell *))
232 232 ((( cell.source | wrap(wrap_size) )))
233 233 ((* endblock rawcell -*))
234 234
235 235 %==============================================================================
236 236 % Unknowncell
237 237 %
238 238 % Purpose: This is the catch anything unhandled. To display this data, we
239 239 % remove all possible latex conflicts and wrap the characters so they
240 240 % can't flow off of the page.
241 241 %==============================================================================
242 242 ((* block unknowncell scoped*))
243 243
244 244 % Unsupported cell type, no formatting
245 245 ((( cell.source | wrap | escape_tex )))
246 246 ((* endblock unknowncell *))
247 247
248 248 %==============================================================================
249 249 % Input
250 250 %==============================================================================
251 251 ((* block input *))
252 252
253 253 % Make sure that atleast 4 lines are below the HR
254 254 \needspace{((( min_header_lines )))\baselineskip}
255 255
256 256 ((* if resources.sphinx.outputstyle == 'simple' *))
257 257
258 258 % Add a horizantal break, along with break title.
259 259 \vspace{10pt}
260 260 {\scriptsize Input}\\*
261 261 \rule[10pt]{\linewidth}{0.5pt}
262 262 \vspace{-25pt}
263 263
264 264 % Add contents below.
265 265 ((( cell.input | highlight )))
266 266
267 267 ((* elif resources.sphinx.outputstyle == 'notebook' *))
268 268 \vspace{6pt}
269 269 ((( write_prompt("In", cell.prompt_number, "nbframe-in-prompt") )))
270 270 \vspace{-2.65\baselineskip}
271 271 \begin{ColorVerbatim}
272 272 \vspace{-0.7\baselineskip}
273 273 ((( cell.input | highlight )))
274 274 ((* if cell.input == None or cell.input == '' *))
275 275 \vspace{0.3\baselineskip}
276 276 ((* else *))
277 277 \vspace{-0.2\baselineskip}
278 278 ((* endif *))
279 279 \end{ColorVerbatim}
280 280 ((* endif *))
281 281 ((* endblock input *))
282 282
283 283 %==============================================================================
284 284 % Output_Group
285 285 %
286 286 % Purpose: Make sure that only one header bar only attaches to the output
287 287 % once. By keeping track of when an input group is started
288 288 %==============================================================================
289 289 ((* block output_group *))
290 290 ((* if cell.outputs.__len__() > 0 *))
291 ((* if resources.sphinx.outputstyle == 'simple' *))
292 291
293 292 % If the first block is an image, minipage the image. Else
294 293 % request a certain amount of space for the input text.
295 294 ((( iff_figure(cell.outputs[0], "\\begin{minipage}{1.0\\textwidth}", "\\needspace{" ~ min_header_lines ~ "\\baselineskip}") )))
296 295
296 ((* if resources.sphinx.outputstyle == 'simple' *))
297
297 298 % Add a horizantal break, along with break title.
298 299 \vspace{10pt}
299 300 {\scriptsize Output}\\*
300 301 \rule[10pt]{\linewidth}{0.5pt}
301 302 \vspace{-20pt}
302 303
303 304 % Add the contents of the first block.
304 305 ((( render_output(cell.outputs[0]) )))
305 306
306 307 % Close the minipage.
307 308 ((( iff_figure(cell.outputs[0], "\\end{minipage}", "") )))
308 309
309 310 % Add remainer of the document contents below.
310 311 ((* for output in cell.outputs[1:] *))
311 312 ((( render_output(output, cell.prompt_number) )))
312 313 ((* endfor *))
313 314 ((* elif resources.sphinx.outputstyle == 'notebook' *))
314 315
315 316 % Add document contents.
316 317 ((* for output in cell.outputs *))
317 318 ((( render_output(output, cell.prompt_number) )))
318 319 ((* endfor *))
319 320 ((* endif *))
320 321 ((* endif *))
321 322 ((* endblock *))
322 323
323 324 %==============================================================================
324 325 % Additional formating
325 326 %==============================================================================
326 327 ((* block data_text *))
327 328 ((( custom_verbatim(output.text) )))
328 329 ((* endblock *))
329 330
330 331 ((* block traceback_line *))
331 332 ((( conditionally_center_output(line | indent| rm_ansi) )))
332 333 ((* endblock traceback_line *))
333 334
334 335 %==============================================================================
335 336 % Supported image formats
336 337 %==============================================================================
337 338 ((*- block data_png -*))
338 339 ((( conditionally_center_output(insert_graphics(output.key_png)) )))
339 340 ((*- endblock -*))
340 341
341 342 ((*- block data_svg -*))
342 343 ((( conditionally_center_output(insert_graphics(output.key_svg)) )))
343 344 ((*- endblock -*))
344 345
345 346 ((*- block data_latex *))
346 347 ((* if resources.sphinx.centeroutput *))\begin{center}((* endif -*))((( output.latex | rm_math_space )))((*- if resources.sphinx.centeroutput *))\end{center} ((* endif -*))
347 348 ((*- endblock -*))
348 349
349 350 %==============================================================================
350 351 % Support Macros
351 352 %==============================================================================
352 353
353 354 % Name: write_prompt
354 355 % Purpose: Renders an output/input prompt for notebook style pdfs
355 356 ((* macro write_prompt(prompt, number, color) -*))
356 357 \makebox[0.1\linewidth]{\smaller\hfill\tt\color{((( color )))}((( prompt )))\hspace{4pt}{[}((( number ))){]}:\hspace{4pt}}\\*
357 358 ((*- endmacro *))
358 359
359 360 % Name: render_output
360 361 % Purpose: Renders an output block appropriately.
361 362 ((* macro render_output(output, prompt_number) -*))
362 363 ((*- if output.output_type == 'pyerr' -*))
363 364 ((*- block pyerr scoped *))
364 365 ((( custom_verbatim(super()) )))
365 366 ((* endblock pyerr -*))
366 367 ((*- else -*))
367 368
368 369 ((* if resources.sphinx.outputstyle == 'notebook' *))
369 370 ((*- if output.output_type == 'pyout' -*))
370 371 ((( write_prompt("Out", prompt_number, "nbframe-out-prompt") )))
371 372 \vspace{-2.55\baselineskip}
372 373 ((*- endif -*))
373 374
374 375 \begin{InvisibleVerbatim}
375 376 \vspace{-0.5\baselineskip}
376 377 ((*- endif -*))
377 378
378 379 ((*- block display_data scoped -*))
379 380 ((( super() )))
380 381 ((*- endblock display_data -*))
381 382
382 383 ((* if resources.sphinx.outputstyle == 'notebook' *))
383 384 \end{InvisibleVerbatim}
384 385 ((*- endif -*))
385 386 ((*- endif -*))
386 387 ((*- endmacro *))
387 388
388 389 % Name: iff_figure
389 390 % Purpose: If the output block provided is a figure type, the 'true_content'
390 391 % parameter will be returned. Else, the 'false_content'.
391 392 ((* macro iff_figure(output, true_content, false_content) -*))
392 393 ((*- set is_figure = false -*))
393 394 ((*- for type in output | filter_data_type -*))
394 395 ((*- if type in ['pdf', 'svg', 'png', 'jpeg','html']*))
395 396 ((*- set is_figure = true -*))
396 397 ((*- endif -*))
397 398 ((*- endfor -*))
398 399
399 400 ((* if is_figure -*))
400 401 ((( true_content )))
401 402 ((*- else -*))
402 403 ((( false_content )))
403 404 ((*- endif *))
404 405 ((*- endmacro *))
405 406
406 407 % Name: custom_verbatim
407 408 % Purpose: This macro creates a verbatim style block that fits the existing
408 409 % sphinx style more readily than standard verbatim blocks.
409 410 ((* macro custom_verbatim(text) -*))
410 411 \begin{alltt}
411 412 ((*- if resources.sphinx.centeroutput *))\begin{center} ((* endif -*))
412 413 ((( text | wrap(wrap_size) )))
413 414 ((*- if resources.sphinx.centeroutput *))\end{center}((* endif -*))
414 415 \end{alltt}
415 416 ((*- endmacro *))
416 417
417 418 % Name: conditionally_center_output
418 419 % Purpose: This macro centers the output if the output centering is enabled.
419 420 ((* macro conditionally_center_output(text) -*))
420 421 ((* if resources.sphinx.centeroutput *)){\centering ((* endif *))((( text )))((* if resources.sphinx.centeroutput *))}((* endif *))
421 422 ((*- endmacro *))
422 423
423 424 % Name: insert_graphics
424 425 % Purpose: This macro will insert an image in the latex document given a path.
425 426 ((* macro insert_graphics(path) -*))
426 427 \begin{center}
427 428 \includegraphics[max size={\textwidth}{\textheight}]{(((path)))}
428 429 \par
429 430 \end{center}
430 431 ((*- endmacro *))
431 432
432 433 % Name: escape_underscores
433 434 % Purpose: Underscores cause a problem in latex. It's important that we
434 435 % escape any underscores that appear.
435 436 ((* macro escape_underscores(text) -*))
436 437 ((*- set text = text|replace("_","\\_") -*))
437 438 ((( text )))
438 439 ((*- endmacro *)) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now