##// END OF EJS Templates
Moved pygments logic to latex base.
Jonathan Frederic -
Show More
@@ -1,184 +1,189 b''
1 1 ((= Latex base template (must inherit)
2 2 This template builds upon the abstract template, adding common latex output
3 3 functions. Figures, data_text,
4 4 This template does not define a docclass, the inheriting class must define this.=))
5 5
6 6 ((*- extends 'abstract.tplx' -*))
7 7
8 8 %===============================================================================
9 9 % Abstract overrides
10 10 %===============================================================================
11 11
12 12 ((* block packages *))
13 13 \usepackage{graphicx} % Used to insert images
14 14 \usepackage{adjustbox} % Used to constrain images to a maximum size
15 15 \usepackage{color} % Allow colors to be defined
16 16 \usepackage{enumerate} % Needed for markdown enumerations to work
17 17 \usepackage{fancyvrb} % Needed to support color codes (tex) in verbatim blocks
18 18 \usepackage{geometry} % Used to adjust the document margins
19 19 \usepackage{amsmath} % Equations
20 20 \usepackage{amssymb} % Equations
21 21 \usepackage[utf8]{inputenc} % Allow utf-8 characters in the tex document
22 22 \usepackage{ucs} % Extended unicode (utf-8) support
23 23 \usepackage{alltt} % Verbatim replacement that allows latex
24 24
25 25 \usepackage{grffile} % extends the file name processing of package graphics
26 26 %to support a larger range
27 27
28 28 % The hyperref package gives us a pdf with properly built
29 29 % internal navigation ('pdf bookmarks' for the table of contents,
30 30 % internal cross-reference links, web links for URLs, etc.)
31 31 \usepackage{hyperref}
32 32
33 33 % Pygments definitions
34 34 ((( resources.latex.pygment_definitions )))
35 35 ((* endblock packages *))
36 36
37 37 ((* block definitions *))
38 38 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
39 39 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
40 40 \definecolor{darkgreen}{rgb}{.12,.54,.11}
41 41 \definecolor{myteal}{rgb}{.26, .44, .56}
42 42 \definecolor{gray}{gray}{0.45}
43 43 \definecolor{lightgray}{gray}{.95}
44 44 \definecolor{mediumgray}{gray}{.8}
45 45 \definecolor{inputbackground}{rgb}{.95, .95, .85}
46 46 \definecolor{outputbackground}{rgb}{.95, .95, .95}
47 47 \definecolor{traceback}{rgb}{1, .95, .95}
48 48
49 49 % new ansi colors
50 50 \definecolor{brown}{rgb}{0.54,0.27,0.07}
51 51 \definecolor{purple}{rgb}{0.5,0.0,0.5}
52 52 \definecolor{darkgray}{gray}{0.25}
53 53 \definecolor{lightred}{rgb}{1.0,0.39,0.28}
54 54 \definecolor{lightgreen}{rgb}{0.48,0.99,0.0}
55 55 \definecolor{lightblue}{rgb}{0.53,0.81,0.92}
56 56 \definecolor{lightpurple}{rgb}{0.87,0.63,0.87}
57 57 \definecolor{lightcyan}{rgb}{0.5,1.0,0.83}
58 58
59 59 % Define a nice break command that doesn't care if a line doesn't already
60 60 % exist.
61 61 \def\br{\hspace*{\fill} \\* }
62 62
63 63 % Define a custom verbatim that allows latex
64 64 \renewenvironment{Verbatim}[1][\unskip]
65 65 {\begin{alltt}\smaller\noindent}
66 66 {\end{alltt}}
67 67 ((* endblock definitions *))
68 68
69 69 ((* block commands *))
70 70 \sloppy % Prevent overflowing lines due to hard-to-break entities
71 71
72 72 % Setup hyperref package
73 73 \hypersetup{
74 74 breaklinks=true, % so long urls are correctly broken across lines
75 75 colorlinks=true,
76 76 urlcolor=blue,
77 77 linkcolor=darkorange,
78 78 citecolor=darkgreen,
79 79 }
80 80
81 81 % Slightly bigger margins than the latex defaults
82 82 \geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=2.5cm,rmargin=2.5cm}
83 83
84 84 % Hardcode size of all verbatim environments to be a bit smaller
85 85 \makeatletter
86 86 \g@addto@macro\@verbatim\small\topsep=0.5em\partopsep=0pt
87 87 \makeatother
88 88 ((* endblock commands *))
89 89
90 90 %===============================================================================
91 91 % Support blocks
92 92 %===============================================================================
93 93
94 94 % Displaying simple data text
95 95 ((* block data_text *))
96 96 \begin{Verbatim}
97 97 ((( output.text | escape_latex )))
98 98 \end{Verbatim}
99 99 ((* endblock data_text *))
100 100
101 101 % Display python error text as-is
102 102 ((* block pyerr *))
103 103 \begin{Verbatim}
104 104 ((( super() )))
105 105 \end{Verbatim}
106 106 ((* endblock pyerr *))
107 107 ((* block traceback_line *))
108 108 ((( line | indent | strip_ansi | escape_latex )))
109 109 ((* endblock traceback_line *))
110 110
111 111 % Display stream ouput with coloring
112 112 ((* block stream *))
113 113 \begin{Verbatim}[commandchars=\\\{\}]
114 114 ((( output.text | ansi2latex )))
115 115 \end{Verbatim}
116 116 ((* endblock stream *))
117 117
118 118 % Display latex
119 119 ((* block data_latex -*))
120 120 ((*- if output.latex.startswith('$'): -*))
121 121 ((= Replace $ symbols with more explicit, equation block. =))
122 122 \begin{equation*}
123 123 ((( output.latex | strip_dollars )))
124 124 \end{equation*}
125 125 ((*- else -*))
126 126 ((( output.latex )))
127 127 ((*- endif *))
128 128 ((* endblock data_latex *))
129 129
130 130 % Default mechanism for rendering figures
131 131 ((*- block data_png -*))((( draw_figure(output.png_filename) )))((*- endblock -*))
132 132 ((*- block data_jpg -*))((( draw_figure(output.jpeg_filename) )))((*- endblock -*))
133 133 ((*- block data_svg -*))((( draw_figure(output.svg_filename) )))((*- endblock -*))
134 134 ((*- block data_pdf -*))((( draw_figure(output.pdf_filename) )))((*- endblock -*))
135 135
136 136 % Draw a figure using the graphicx package.
137 137 ((* macro draw_figure(filename) -*))
138 138 ((* set filename = filename | posix_path *))
139 139 ((*- block figure scoped -*))
140 140 \begin{center}
141 141 \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{((( filename )))}
142 142 \end{center}
143 143 { \hspace*{\fill} \\}
144 144 ((*- endblock figure -*))
145 145 ((*- endmacro *))
146 146
147 147 % Draw heading cell. Explicitly map different cell levels.
148 148 ((* block headingcell scoped -*))
149 149 ((*- if cell.level == 1 -*))
150 150 ((* block h1 -*))\section((* endblock h1 -*))
151 151 ((*- elif cell.level == 2 -*))
152 152 ((* block h2 -*))\subsection((* endblock h2 -*))
153 153 ((*- elif cell.level == 3 -*))
154 154 ((* block h3 -*))\subsubsection((* endblock h3 -*))
155 155 ((*- elif cell.level == 4 -*))
156 156 ((* block h4 -*))\paragraph((* endblock h4 -*))
157 157 ((*- elif cell.level == 5 -*))
158 158 ((* block h5 -*))\subparagraph((* endblock h5 -*))
159 159 ((*- elif cell.level == 6 -*))
160 160 ((* block h6 -*))\\*\textit((* endblock h6 -*))
161 161 ((*- endif -*))
162 162 {((( cell.source | escape_latex )))}
163 163 ((*- endblock headingcell *))
164 164
165 165 % Redirect pyout to display data priority.
166 166 ((* block pyout scoped *))
167 167 ((* block data_priority scoped *))
168 168 ((( super() )))
169 169 ((* endblock *))
170 170 ((* endblock pyout *))
171 171
172 172 % Render markdown
173 173 ((* block markdowncell scoped *))
174 174 ((( cell.source | markdown2latex )))
175 175 ((* endblock markdowncell *))
176 176
177 177 % Spit out the contents of raw cells unmodified
178 178 ((* block rawcell scoped *))
179 179 ((( cell.source )))
180 180 ((* endblock rawcell *))
181 181
182 182 % Don't display unknown types
183 183 ((* block unknowncell scoped *))
184 184 ((* endblock unknowncell *))
185
186 % Render code using pygments
187 ((* block input scoped *))
188 ((( cell.input | highlight2latex )))
189 ((* endblock input *)) No newline at end of file
@@ -1,138 +1,138 b''
1 1 ((= Notebook input/output style =))
2 2
3 3 ((* extends 'latex_base.tplx' *))
4 4
5 5 % Custom packages
6 6 ((* block packages *))
7 7 ((( super() )))
8 8
9 9 % Needed to box output/input
10 10 \usepackage{tikz}
11 11 \usetikzlibrary{calc,arrows,shadows}
12 12 \usepackage[framemethod=tikz]{mdframed}
13 13 ((* endblock packages *))
14 14
15 15 % Custom definitions
16 16 ((* block definitions *))
17 17 ((( super() )))
18 18
19 19 \listfiles
20 20
21 21 \def\smaller{\fontsize{9.5pt}{9.5pt}\selectfont}
22 22
23 23 \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867}
24 24 \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969}
25 25 \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502}
26 26 \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0}
27 27
28 28 \newenvironment{ColorVerbatim}
29 29 {\vspace{-2\baselineskip}
30 30 \leavevmode\begin{mdframed}[%
31 31 roundcorner=1.0pt, %
32 32 backgroundcolor=nbframe-bg, %
33 33 userdefinedwidth=1\linewidth, %
34 34 leftmargin=0.1\linewidth, %
35 35 innerleftmargin=0pt, %
36 36 innerrightmargin=0pt, %
37 37 linecolor=nbframe-border, %
38 38 linewidth=1pt, %
39 39 usetwoside=false, %
40 40 everyline=true, %
41 41 innerlinewidth=3pt, %
42 42 innerlinecolor=nbframe-bg, %
43 43 middlelinewidth=1pt, %
44 44 middlelinecolor=nbframe-bg, %
45 45 outerlinewidth=0.5pt, %
46 46 outerlinecolor=nbframe-border, %
47 47 needspace=0pt
48 48 ]}
49 49 {\end{mdframed}\vspace{-2\baselineskip}}
50 50
51 51 \newenvironment{WhiteVerbatim}
52 52 {\vspace{-2\baselineskip}
53 53 \leavevmode\begin{mdframed}[%
54 54 roundcorner=1.0pt, %
55 55 backgroundcolor=white, %
56 56 userdefinedwidth=1\linewidth, %
57 57 leftmargin=0.1\linewidth, %
58 58 innerleftmargin=0pt, %
59 59 innerrightmargin=0pt, %
60 60 linecolor=white, %
61 61 linewidth=1pt, %
62 62 usetwoside=false, %
63 63 everyline=true, %
64 64 innerlinewidth=3pt, %
65 65 innerlinecolor=white, %
66 66 middlelinewidth=1pt, %
67 67 middlelinecolor=white, %
68 68 outerlinewidth=0.5pt, %
69 69 outerlinecolor=white, %
70 70 needspace=0pt
71 71 ]}
72 72 {\end{mdframed}\vspace{-2\baselineskip}}
73 73
74 74 ((* endblock definitions *))
75 75
76 76 %===============================================================================
77 77 % Input
78 78 %===============================================================================
79 79
80 80
81 81 ((* block in_prompt scoped *))
82 82 \br
83 83 ((( draw_prompt("In", cell.prompt_number, "nbframe-in-prompt") )))
84 84 ((* endblock in_prompt *))
85 85
86 86 ((* block input scoped *))
87 87 % Add contents below.
88 88
89 89 \begin{ColorVerbatim}
90 ((( cell.input | highlight2latex )))
90 \smaller{\leavevmode\hspace*{-0.1\linewidth}((( super() )))
91 91 \end{ColorVerbatim}
92 92 ((* endblock input *))
93 93
94 94 ((* block input_group scoped *))
95 95 ((( super() )))
96 96 ((* endblock input_group *))
97 97
98 98
99 99 %===============================================================================
100 100 % Output
101 101 %===============================================================================
102 102
103 103 ((* block output *))
104 104 \br
105 105
106 106 % Only render the prompt if the cell is pyout. Note, the outputs prompt
107 107 % block isn't used since we need to check each indiviual output and only
108 108 % add prompts to the pyout ones.
109 109 ((* if output.output_type in ['pyout'] *))
110 110 ((( draw_prompt("Out", cell.prompt_number, "nbframe-out-prompt") )))
111 111 ((* endif *))
112 112
113 113 \begin{WhiteVerbatim}
114 114 ((( super() )))
115 115 \end{WhiteVerbatim}
116 116 ((* endblock output *))
117 117
118 118 %==============================================================================
119 119 % Support Macros
120 120 %==============================================================================
121 121
122 122 % Name: draw_prompt
123 123 % Purpose: Renders an output/input prompt for notebook style pdfs. Prompt is
124 124 % rendered at the current location, the cursor position is left
125 125 % unmodified.
126 126 ((* macro draw_prompt(prompt, number, color) *))
127 127
128 128 {
129 129 \smaller
130 130 \tt
131 131 \color{((( color )))}
132 132 \noindent
133 133 ((( prompt )))
134 134 {[}((( number ))){]}:
135 135 }
136 136
137 137 \vspace{-1\baselineskip}
138 138 ((* endmacro *))
@@ -1,50 +1,45 b''
1 1 ((= Simple input/output style =))
2 2
3 3 ((*- extends 'latex_base.tplx' -*))
4 4
5 5 %===============================================================================
6 6 % Input
7 7 %===============================================================================
8 8
9 9 ((*- block in_prompt scoped -*))
10 10 ((( write_prompt('Input') )))
11 11 ((*- endblock in_prompt -*))
12 12
13 ((*- block input scoped -*))
14 % Add contents below.
15 ((( cell.input | highlight2latex )))
16 ((*- endblock input -*))
17
18 13 ((*- block input_group scoped -*))
19 14 (((- super() )))
20 15 \vspace{-2em}
21 16 ((* endblock input_group -*))
22 17
23 18
24 19 %===============================================================================
25 20 % Output
26 21 %===============================================================================
27 22
28 23 ((*- block output_prompt scoped -*))
29 24 ((( write_prompt('Output') )))
30 25 ((*- endblock output_prompt -*))
31 26
32 27 ((*- block output_group scoped -*))
33 28 (((- super() )))
34 29 \vspace{-2em}
35 30 ((* endblock output_group -*))
36 31
37 32 %==============================================================================
38 33 % Support Macros
39 34 %==============================================================================
40 35
41 36 % Name: write_prompt
42 37 % Purpose: Renders an output/input prompt for notebook style pdfs
43 38 ((* macro write_prompt(prompt) *))
44 39 % Add a horizantal break, along with break title.
45 40 \br\br
46 41 {\scriptsize ((( prompt )))}
47 42 \br
48 43 \rule[10pt]{\linewidth}{0.5pt}
49 44 \vspace{-2.5em}
50 45 ((* endmacro *))
General Comments 0
You need to be logged in to leave comments. Login now