##// END OF EJS Templates
Removed extra spaces
Jonathan Frederic -
Show More
@@ -1,388 +1,388 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 ((*- set wrap_size = 85 -*))
30 ((*- set wrap_size = 85 -*))
31 31 ((* elif resources.sphinx.outputstyle == 'notebook' *))
32 ((*- set wrap_size = 70 -*))
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
136 136 ((* if resources.sphinx.header *))
137 137 \maketitle
138 138 ((* endif *))
139
139
140 140 ((* block toc *))
141 141 \tableofcontents
142 142 ((* endblock toc *))
143 143
144 144 ((* endblock bodyBegin *))((( super() )))((* block bodyEnd *))
145 145
146 146 \renewcommand{\indexname}{Index}
147 147 \printindex
148 148
149 149 % End of document
150 150 \end{document}
151 151 ((* endblock bodyEnd *))
152 152 ((* endblock body *))
153 153
154 154 %==============================================================================
155 155 % Footer
156 156 %==============================================================================
157 157 ((* block footer *))
158 158 ((* endblock footer *))
159 159
160 160 %==============================================================================
161 161 % Headings
162 162 %
163 163 % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx
164 164 % style that is active, this will change. Thus sphinx styles will
165 165 % override the values here.
166 166 %==============================================================================
167 167 ((* block headingcell -*))
168 168 \
169 169 ((*- if cell.level == 1 -*))
170 170 ((* block h1 -*))part((* endblock h1 -*))
171 171 ((*- elif cell.level == 2 -*))
172 172 ((* block h2 -*))chapter((* endblock h2 -*))
173 173 ((*- elif cell.level == 3 -*))
174 174 ((* block h3 -*))section((* endblock h3 -*))
175 175 ((*- elif cell.level == 4 -*))
176 176 ((* block h4 -*))subsection((* endblock h4 -*))
177 177 ((*- elif cell.level == 5 -*))
178 178 ((* block h5 -*))subsubsection((* endblock h5 -*))
179 179 ((*- elif cell.level == 6 -*))
180 180 ((* block h6 -*))paragraph((* endblock h6 -*))
181
181
182 182 ((= It's important to make sure that underscores (which tend to be common
183 183 in IPYNB file titles) do not make their way into latex. Sometimes this
184 184 causes latex to barf. =))
185 185 ((*- endif -*)){((( escape_underscores(cell.source | markdown2latex ) )))}
186 186 ((*- endblock headingcell *))
187 187
188 188 %==============================================================================
189 189 % Markdown
190 190 %
191 191 % Purpose: Convert markdown to latex. Here markdown2latex is explicitly
192 192 % called since we know we want latex output.
193 193 %==============================================================================
194 194 ((*- block markdowncell scoped-*))
195 195 ((( cell.source | markdown2latex )))
196 196 ((*- endblock markdowncell -*))
197 197
198 198 %==============================================================================
199 199 % Rawcell
200 200 %
201 201 % Purpose: Raw text cells allow the user to manually inject document code that
202 202 % will not get touched by the templating system.
203 203 %==============================================================================
204 204 ((*- block rawcell *))
205 205 ((( cell.source | wrap(wrap_size) )))
206 206 ((* endblock rawcell -*))
207 207
208 208 %==============================================================================
209 209 % Unknowncell
210 210 %
211 211 % Purpose: This is the catch anything unhandled. To display this data, we
212 212 % remove all possible latex conflicts and wrap the characters so they
213 213 % can't flow off of the page.
214 214 %==============================================================================
215 215 ((* block unknowncell scoped*))
216 216
217 217 % Unsupported cell type, no formatting
218 218 ((( cell.source | wrap | escape_tex )))
219 219 ((* endblock unknowncell *))
220 220
221 221 %==============================================================================
222 222 % Input
223 223 %==============================================================================
224 224 ((* block input *))
225 225
226 226 % Make sure that atleast 4 lines are below the HR
227 227 \needspace{((( min_header_lines )))\baselineskip}
228
228
229 229 ((* if resources.sphinx.outputstyle == 'simple' *))
230 230
231 231 % Add a horizantal break, along with break title.
232 232 \vspace{10pt}
233 233 {\scriptsize Input}\\*
234 234 \rule[10pt]{\linewidth}{0.5pt}
235 235 \vspace{-25pt}
236 236
237 237 % Add contents below.
238 238 ((( cell.input | highlight )))
239
239
240 240 ((* elif resources.sphinx.outputstyle == 'notebook' *))
241 241 \vspace{5pt}
242 242 {\color{nbframe-prompt}\textbf{In {[}((( cell.prompt_number ))){]}:}}\\*
243 243 \vspace{-2.6\baselineskip}
244 244 \begin{ColorVerbatim}
245 245 \vspace{-0.5\baselineskip}
246 246 ((( cell.input | highlight )))
247 247 \end{ColorVerbatim}
248 248 ((* endif *))
249 249 ((* endblock input *))
250 250
251 251 %==============================================================================
252 252 % Output_Group
253 253 %
254 254 % Purpose: Make sure that only one header bar only attaches to the output
255 255 % once. By keeping track of when an input group is started
256 256 %==============================================================================
257 257 ((* block output_group *))
258 258 ((* if cell.outputs.__len__() > 0 *))
259 259 ((* if resources.sphinx.outputstyle == 'simple' *))
260
260
261 261 % If the first block is an image, minipage the image. Else
262 262 % request a certain amount of space for the input text.
263 263 ((( iff_figure(cell.outputs[0], "\\begin{minipage}{1.0\\textwidth}", "\\needspace{" ~ min_header_lines ~ "\\baselineskip}") )))
264
264
265 265 % Add a horizantal break, along with break title.
266 266 \vspace{10pt}
267 267 {\scriptsize Output}\\*
268 268 \rule[10pt]{\linewidth}{0.5pt}
269 269 \vspace{-20pt}
270 270
271 271 % Add the contents of the first block.
272 272 ((( render_output(cell.outputs[0]) )))
273 273
274 274 % Close the minipage.
275 275 ((( iff_figure(cell.outputs[0], "\\end{minipage}", "") )))
276 276
277 277 % Add remainer of the document contents below.
278 278 ((* for output in cell.outputs[1:] *))
279 279 ((( render_output(output) )))
280 280 ((* endfor *))
281 281 ((* elif resources.sphinx.outputstyle == 'notebook' *))
282
282
283 283 %Skip one line down.
284 284 \vspace{1\baselineskip}
285
285
286 286 % Add document contents.
287 287 \begin{ColorVerbatim}
288 288 ((* for output in cell.outputs *))
289 289 ((( render_output(output) )))
290 290 ((* endfor *))
291 291 \end{ColorVerbatim}
292 292 ((* endif *))
293 293 ((* endif *))
294 294 ((* endblock *))
295 295
296 296 %==============================================================================
297 297 % Additional formating
298 298 %==============================================================================
299 299 ((* block data_text *))
300 300 ((( custom_verbatim(output.text) )))
301 301 ((* endblock *))
302 302
303 303 ((* block traceback_line *))
304 304 ((( center_output(line | indent| rm_ansi) )))
305 305 ((* endblock traceback_line *))
306 306
307 307 %==============================================================================
308 308 % Supported image formats
309 309 %==============================================================================
310 310 ((*- block data_png -*))
311 311 ((( center_output(insert_graphics(output.key_png)) )))
312 312 ((*- endblock -*))
313 313
314 314 ((*- block data_svg -*))
315 315 ((( center_output(insert_graphics(output.key_svg)) )))
316 316 ((*- endblock -*))
317 317
318 318 ((*- block data_latex -*))
319 ((( center_output(output.latex | rm_math_space) )))
319 ((( center_output(output.latex | rm_math_space) )))
320 320 ((*- endblock -*))
321 321
322 322 %==============================================================================
323 323 % Support Macros
324 324 %==============================================================================
325 325
326 326 % Name: render_output
327 327 % Purpose: Renders an output block appropriately.
328 328 ((* macro render_output(output) -*))
329 329 ((*- if output.output_type == 'pyerr' -*))
330 330 ((*- block pyerr scoped *))
331 ((( custom_verbatim(super()) )))
331 ((( custom_verbatim(super()) )))
332 332 ((* endblock pyerr -*))
333 333 ((*- else -*))
334 334 ((*- block display_data scoped -*))
335 335 ((( super() )))
336 336 ((*- endblock display_data -*))
337 337 ((*- endif -*))
338 338 ((*- endmacro *))
339 339
340 340 % Name: iff_figure
341 341 % Purpose: If the output block provided is a figure type, the 'true_content'
342 342 % parameter will be returned. Else, the 'false_content'.
343 343 ((* macro iff_figure(output, true_content, false_content) -*))
344 344 ((*- set is_figure = false -*))
345 345 ((*- for type in output | filter_data_type -*))
346 346 ((*- if type in ['pdf', 'svg', 'png', 'jpeg','html']*))
347 347 ((*- set is_figure = true -*))
348 348 ((*- endif -*))
349 349 ((*- endfor -*))
350 350
351 351 ((* if is_figure -*))
352 352 ((( true_content )))
353 353 ((*- else -*))
354 354 ((( false_content )))
355 355 ((*- endif *))
356 356 ((*- endmacro *))
357 357
358 358 % Name: custom_verbatim
359 359 % Purpose: This macro creates a verbatim style block that fits the existing
360 360 % sphinx style more readily than standard verbatim blocks.
361 361 ((* macro custom_verbatim(text) -*))
362 362 \begin{alltt}
363 363 ((( center_output(text | wrap(wrap_size)) )))
364 \end{alltt}
364 \end{alltt}
365 365 ((*- endmacro *))
366 366
367 367 % Name: center_output
368 368 % Purpose: This macro centers the output if the output centering is enabled.
369 369 ((* macro center_output(text) -*))
370 370 ((* if resources.sphinx.centeroutput *)){\centering ((* endif *))((( text )))((* if resources.sphinx.centeroutput *))}((* endif *))
371 371 ((*- endmacro *))
372 372
373 373 % Name: insert_graphics
374 374 % Purpose: This macro will insert an image in the latex document given a path.
375 375 ((* macro insert_graphics(path) -*))
376 376 \begin{center}
377 377 \includegraphics[max width=0.7\textwidth]{(((path)))}
378 378 \par
379 379 \end{center}
380 380 ((*- endmacro *))
381 381
382 382 % Name: escape_underscores
383 383 % Purpose: Underscores cause a problem in latex. It's important that we
384 384 % escape any underscores that appear.
385 385 ((* macro escape_underscores(text) -*))
386 386 ((*- set text = text|replace("_","\\_") -*))
387 387 ((( text )))
388 388 ((*- endmacro *)) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now