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