##// END OF EJS Templates
Localized code into jinja macros.
Jonathan Frederic -
Show More
@@ -1,310 +1,313 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, we have to use a minipage environment. This causes problems
18 18 % for large blocks of input and output. If there is a large input/output
19 19 % block, we don't want to minipage the whole thing since it will break
20 20 % the line wrapping. The solution is to split the input/output line by
21 21 % line before we minipage which allows us to minipage the first X lines
22 22 % preceeding the input/output bar. That way, a select amount of lines
23 23 % force the input/output bar to follow it around.
24 24 ((*- set min_header_lines = 3 -*))
25 25
26 26 % This is the number of characters that are permitted per line. It's
27 27 % important that this limit is set so characters do not run off the
28 28 % edges of latex pages (since latex does not always seem smart enough
29 29 % to prevent this.)
30 30 ((*- set wrap_size = 87 -*))
31 31
32 32 % Global variable used to determine whether or not a header bar has been
33 33 % applied to the group of input/output blocks already
34 34 ((*- set needs_header = False -*))
35 35
36 36 %==============================================================================
37 37 % Header
38 38 %==============================================================================
39 39 ((* block header *))
40 40
41 41 % Header, overrides base
42 42
43 43 % Make sure that the sphinx doc style knows who it inherits from.
44 44 \def\sphinxdocclass{(((parentdocumentclass)))}
45 45
46 46 % Declare the document class
47 47 \documentclass[letterpaper,10pt,english]{((( resources.sphinx_texinputs )))/sphinx(((documentclass)))}
48 48
49 49 % Imports
50 50 \usepackage[utf8]{inputenc}
51 51 \DeclareUnicodeCharacter{00A0}{\\nobreakspace}
52 52 \usepackage[T1]{fontenc}
53 53 \usepackage{babel}
54 54 \usepackage{times}
55 55 \usepackage{import}
56 56 \usepackage[((( resources.sphinx_chapterstyle )))]{((( resources.sphinx_texinputs )))/fncychap}
57 57 \usepackage{longtable}
58 58 \usepackage{((( resources.sphinx_texinputs )))/sphinx}
59 59 \usepackage{multirow}
60 60
61 61 \usepackage{amsmath}
62 62 \usepackage{amssymb}
63 63 \usepackage{ucs}
64 64 \usepackage{enumerate}
65 65
66 66 % Pygments requirements
67 67 \usepackage{fancyvrb}
68 68 \usepackage{color}
69 69
70 70 % Used to load and display graphics
71 71 \usepackage{graphicx}
72 72 \graphicspath{ {figs/} }
73 73
74 74 % For formatting output while also word wrapping.
75 75 \usepackage{listings}
76 76 \lstset{breaklines=true}
77 77 \lstset{basicstyle=\small\ttfamily}
78 78
79 79 %Pygments definitions
80 80 ((( resources.pygment_definitions )))
81 81
82 82 % Help prevent overflowing lines due to urls and other hard-to-break
83 83 % entities. This doesn't catch everything...
84 84 \sloppy
85 85
86 86 % Document level variables
87 87 \title{((( nb.metadata.name | escape_tex )))}
88 88 \date{((( nb.metadata._draft.date | escape_tex )))}
89 89 \release{((( nb.metadata._draft.version | escape_tex )))}
90 90 \author{((( nb.metadata._draft.author | escape_tex )))}
91 91 \renewcommand{\releasename}{((( nb.metadata._draft.release | escape_tex )))}
92 92
93 93 % TODO: Add option for the user to specify a logo for his/her export.
94 94 \newcommand{\sphinxlogo}{}
95 95
96 96 % Make the index page of the document.
97 97 \makeindex
98 98
99 99 % Import sphinx document type specifics.
100 100 ((* block sphinxheader *))((* endblock sphinxheader *))
101 101 ((* endblock header *))
102 102
103 103 %==============================================================================
104 104 % Body
105 105 %==============================================================================
106 106 ((* block body *))
107 107 ((* block bodyBegin *))
108 108 % Body
109 109
110 110 % Start of the document
111 111 \begin{document}
112 112 \maketitle
113 113 \tableofcontents
114 114
115 115 ((* endblock bodyBegin *))((( super() )))((* block bodyEnd *))
116 116
117 117 \renewcommand{\indexname}{Index}
118 118 \printindex
119 119
120 120 % End of document
121 121 \end{document}
122 122 ((* endblock bodyEnd *))
123 123 ((* endblock body *))
124 124
125 125 %==============================================================================
126 126 % Footer
127 127 %==============================================================================
128 128 ((* block footer *))
129 129 ((* endblock footer *))
130 130
131 131 %==============================================================================
132 132 % Headings
133 133 %
134 134 % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx
135 135 % style that is active, this will change. Thus sphinx styles will
136 136 % override the values here.
137 137 %==============================================================================
138 138 ((* block headingcell -*))
139 139 \ ((= This backslash IS significant, do not delete =))
140 140 ((*- if cell.level == 1 -*))
141 141 ((* block h1 -*))part((* endblock h1 -*))
142 142 ((*- elif cell.level == 2 -*))
143 143 ((* block h2 -*))chapter((* endblock h2 -*))
144 144 ((*- elif cell.level == 3 -*))
145 145 ((* block h3 -*))section((* endblock h3 -*))
146 146 ((*- elif cell.level == 4 -*))
147 147 ((* block h4 -*))subsection((* endblock h4 -*))
148 148 ((*- elif cell.level == 5 -*))
149 149 ((* block h5 -*))subsubsection((* endblock h5 -*))
150 150 ((*- elif cell.level == 6 -*))
151 151 ((* block h6 -*))paragraph((* endblock h6 -*))
152 152
153 153 ((= It's important to make sure that underscores (which tend to be common
154 154 in IPYNB file titles) do not make their way into latex. Sometimes this
155 155 causes latex to barf. =))
156 156 ((*- endif -*)){((( escapeUnderscores(cell.source | markdown2latex ) )))}
157 157 ((*- endblock headingcell *))
158 158
159 159 %==============================================================================
160 160 % Markdown
161 161 %
162 162 % Purpose: Convert markdown to latex. Here markdown2latex is explicitly
163 163 % called since we know we want latex output.
164 164 %==============================================================================
165 165 ((*- block markdowncell scoped-*))
166 166 ((( cell.source | markdown2latex )))
167 167 ((*- endblock markdowncell -*))
168 168
169 169 %==============================================================================
170 170 % Rawcell
171 171 %
172 172 % Purpose: Raw text cells allow the user to manually inject document code that
173 173 % will not get touched by the templating system.
174 174 %==============================================================================
175 175 ((*- block rawcell *))
176 176 ((( cell.source | wrap(wrap_size) )))
177 177 ((* endblock rawcell -*))
178 178
179 179 %==============================================================================
180 180 % Unknowncell
181 181 %
182 182 % Purpose: This is the catch anything unhandled. To display this data, we
183 183 % remove all possible latex conflicts and wrap the characters so they
184 184 % can't flow off of the page.
185 185 %==============================================================================
186 186 ((* block unknowncell scoped*))
187 187
188 188 % Unsupported cell type, no formatting
189 189 ((( cell.source | wrap | escape_tex )))
190 190 ((* endblock unknowncell *))
191 191
192 192 %==============================================================================
193 193 % Input
194 %
195 % Purpose: TODO
196 194 %==============================================================================
197 195 ((* block input *))
196
197 ((= Global variable used to determine whether or not a header bar has been
198 applied to the group of output blocks already. We still need to set
199 it to true to make sure that the block bar gets rendered.=))
200 ((*- set needs_header = true -*))
201
198 202 ((* set text_begining = cell.input | wrap(wrap_size) | get_lines(end=min_header_lines) | highlight *))
199 203 ((* set text_remainer = cell.input | wrap(wrap_size) | get_lines(start=min_header_lines) | highlight *))
200 204 ((( inputBlock(text_begining, text_remainer) )))
201 205 ((* endblock input *))
202 206
203 207 %==============================================================================
204 % pyerr
208 % Output_Group
205 209 %
206 % Purpose: TODO
210 % Purpose: Make sure that only one header bar only attaches to the output
211 % once. By keeping track of when an input group is started
207 212 %==============================================================================
208 ((* block pyerr *))
209 ((* set text_begining = super() | wrap(wrap_size) | get_lines(end=min_header_lines) *))
210 ((* set text_remainer = super() | wrap(wrap_size) | get_lines(start=min_header_lines) *))
211 ((( inputBlock(customVerbatim(text_begining), customVerbatim(text_remainer)) )))
212 ((* endblock pyerr *))
213 ((*- block output_group -*))
213 214
214 %==============================================================================
215 % display_data
216 %
217 % Purpose: TODO
218 %==============================================================================
219 ((*- block display_data -*))
220 ((( inputBlock(super(), "") )))
221 ((*- endblock display_data -*))
215 ((= Global variable used to determine whether or not a header bar has been
216 applied to the group of output blocks already. =))
217 ((*- set needs_header = true -*))
218
219 ((( super() )))
220 ((* endblock *))
222 221
223 222 %==============================================================================
224 % stream
225 %
226 % Purpose: TODO
223 % Output types
227 224 %==============================================================================
225 ((* block pyout *))
226 ((* block data_priority scoped -*))
227 ((( inputBlock(super(),"") )))
228 ((*- endblock *))
229 ((* endblock pyout *))
230
228 231 ((* block stream *))
229 232 ((* set text_begining = output.text | wrap(wrap_size) | get_lines(end=min_header_lines) *))
230 233 ((* set text_remainer = output.text | wrap(wrap_size) | get_lines(start=min_header_lines) *))
231 234 ((( inputBlock(customVerbatim(text_begining), customVerbatim(text_remainer)) )))
232 235 ((* endblock stream *))
233 236
234 %==============================================================================
235 % pyout
236 %
237 % Purpose: TODO
238 %==============================================================================
239 ((* block pyout *))
240 ((* block data_priority scoped *))((( super() )))((* endblock *))
241 ((* endblock pyout *))
237 ((*- block display_data -*))
238 ((( inputBlock(super(), "") )))
239 ((*- endblock display_data -*))
242 240
243 %==============================================================================
244 % traceback_line
245 %
246 % Purpose: TODO
247 %==============================================================================
248 ((* block traceback_line *))
249 ((( line | wrap(wrap_size) |indent| rm_ansi )))((* endblock traceback_line *))
250 ((= .... =))
241 ((* block pyerr *))
242 ((* set text_begining = super() | wrap(wrap_size) | get_lines(end=min_header_lines) *))
243 ((* set text_remainer = super() | wrap(wrap_size) | get_lines(start=min_header_lines) *))
244 ((( inputBlock(customVerbatim(text_begining), customVerbatim(text_remainer)) )))
245 ((* endblock pyerr *))
251 246
252 247 %==============================================================================
253 % data_text
254 %
255 % Purpose: TODO
248 % Additional formating
256 249 %==============================================================================
257 250 ((* block data_text *))
258 ((( customVerbatim(output.text | wrap(wrap_size)) )))
251 ((( customVerbatim(output.text | wrap(wrap_size)) )))
259 252 ((* endblock *))
260 253
254 ((* block traceback_line *))
255 ((( line | wrap(wrap_size) |indent| rm_ansi )))
256 ((* endblock traceback_line *))
257
261 258 %==============================================================================
262 259 % Supported image formats
263 260 %==============================================================================
264 261 ((*- block data_png -*))
265 ((( insertGraphics(output.key_png) )))
262 ((( insertGraphics(output.key_png) )))
266 263 ((*- endblock -*))
267 264
268 265 ((*- block data_svg -*))
269 ((( insertGraphics(output.key_svg) )))
266 ((( insertGraphics(output.key_svg) )))
270 267 ((*- endblock -*))
271 268
272 269 %==============================================================================
273 270 % Support Macros
274 271 %==============================================================================
275 272 ((* macro outputBlock(text_begining, text_remainer) -*))
276 273 ((( nbconvertBlock("Output", text_begining, text_remainer) )))
277 274 ((*- endmacro *))
278 275
279 276 ((* macro inputBlock(text_begining, text_remainer) -*))
280 277 ((( nbconvertBlock("Input", text_begining, text_remainer) )))
281 278 ((*- endmacro *))
282 279
283 280 ((* macro nbconvertBlock(blockTitle, text_begining, text_remainer) -*))
284 \vspace{10pt}
285 \begin{minipage}{\textwidth}
286 {\scriptsize (((blockTitle)))}\\*
287 \rule[10pt]{\linewidth}{0.5pt}
288 \vspace{-25pt}
281 ((*- if needs_header -*))
282 \vspace{10pt}
283 \begin{minipage}{\textwidth}
284 {\scriptsize (((blockTitle)))}\\*
285 \rule[10pt]{\linewidth}{0.5pt}
286 \vspace{-25pt}
287 ((( text_begining )))
288 \end{minipage}((( text_remainer )))
289 ((*- else -*))
289 290 ((( text_begining )))
290 \end{minipage}((( text_remainer )))
291 ((( text_remainer )))
292 ((*- endif -*))
293 ((*- set needs_header = false -*))
291 294 ((*- endmacro *))
292 295
293 296 ((* macro customVerbatim(text) -*))
294 297 \begin{lstlisting}
295 298 ((( text )))
296 299 \end{lstlisting}
297 300 ((*- endmacro *))
298 301
299 302 ((* macro insertGraphics(path) -*))
300 303 \begin{center}
301 304 \includegraphics[width=0.7\textwidth]{(((path)))}
302 305 \par
303 306 \end{center}
304 307 ((*- endmacro *))
305 308
306 309 ((* macro escapeUnderscores(text) -*))
307 310 ((*- set text = text|replace("_","\\_") -*))
308 311 ((( text )))
309 312 ((*- endmacro *))
310 313
General Comments 0
You need to be logged in to leave comments. Login now