-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter-base.tplx
97 lines (80 loc) · 3.15 KB
/
chapter-base.tplx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
((= Latex chapter base template (must inherit)
This templatex, mostly copied from base.tplx, converts a notebook to a chapter.
The result, after conversion, must be LaTeX included in a master document.
=))
((*- extends 'display_priority.tplx' -*))
%===============================================================================
% Abstract overrides
%===============================================================================
((* block header *))
((* endblock header *))
((* block body *))
\begin{chapter}{((( nb.metadata.get('nbconvert', {}).get('title', resources.metadata.name) | ascii_only | escape_latex )))}
((* block predoc *))
((* endblock predoc *))
((( super() )))
\end{chapter}
((* endblock body *))
%===============================================================================
% Support blocks
%===============================================================================
% Displaying simple data text
((* block data_text *))
\begin{verbatim}
((( output.data['text/plain'] )))
\end{verbatim}
((* endblock data_text *))
% Display python error text as-is
((* block error *))
\begin{Verbatim}[commandchars=\\\{\}]
((( super() )))
\end{Verbatim}
((* endblock error *))
((* block traceback_line *))
((( line | indent | strip_ansi | escape_latex )))
((* endblock traceback_line *))
% Display stream ouput with coloring
((* block stream *))
\begin{Verbatim}[commandchars=\\\{\}]
((( output.text | escape_latex | ansi2latex )))
\end{Verbatim}
((* endblock stream *))
% Display latex
((* block data_latex -*))
((*- if output.data['text/latex'].startswith('$'): -*))
((= Replace $ symbols with more explicit, equation block. =))
\begin{equation*}\adjustbox{max width=\hsize}{$
((( output.data['text/latex'] | strip_dollars )))
$}\end{equation*}
((*- else -*))
((( output.data['text/latex'] )))
((*- endif *))
((* endblock data_latex *))
% Default mechanism for rendering figures
((*- block data_png -*))((( draw_figure(output.metadata.filenames['image/png']) )))((*- endblock -*))
((*- block data_jpg -*))((( draw_figure(output.metadata.filenames['image/jpeg']) )))((*- endblock -*))
((*- block data_svg -*))((( draw_figure(output.metadata.filenames['image/svg+xml']) )))((*- endblock -*))
((*- block data_pdf -*))((( draw_figure(output.metadata.filenames['application/pdf']) )))((*- endblock -*))
% Draw a figure using the graphicx package.
((* macro draw_figure(filename) -*))
((* set filename = filename | posix_path *))
((*- block figure scoped -*))
\begin{center}
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{((( filename )))}
\end{center}
{ \hspace*{\fill} \\}
((*- endblock figure -*))
((*- endmacro *))
% Redirect execute_result to display data priority.
((* block execute_result scoped *))
((* block data_priority scoped *))
((( super() )))
((* endblock *))
((* endblock execute_result *))
% Render markdown
((* block markdowncell scoped *))
((( cell.source | citation2latex | strip_files_prefix | markdown2latex )))
((* endblock markdowncell *))
% Don't display unknown types
((* block unknowncell scoped *))
((* endblock unknowncell *))