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