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