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