##// END OF EJS Templates
Handle case where prompt number is not defined in latex templates
Jessica B. Hamrick -
Show More
@@ -1,41 +1,45 b''
1 1 ((= Black&white ipython input/output style =))
2 2
3 3 ((*- extends 'base.tplx' -*))
4 4
5 5 %===============================================================================
6 6 % Input
7 7 %===============================================================================
8 8
9 9 ((* block input scoped *))
10 10 ((( add_prompt(cell.input, cell, 'In ') )))
11 11 ((* endblock input *))
12 12
13 13
14 14 %===============================================================================
15 15 % Output
16 16 %===============================================================================
17 17
18 18 ((* block pyout scoped *))
19 19 ((*- for type in output | filter_data_type -*))
20 20 ((*- if type in ['text']*))
21 21 ((( add_prompt(output.text, cell, 'Out') )))
22 22 ((*- else -*))
23 23 \verb+Out[((( cell.prompt_number )))]:+((( super() )))
24 24 ((*- endif -*))
25 25 ((*- endfor -*))
26 26 ((* endblock pyout *))
27 27
28 28
29 29 %==============================================================================
30 30 % Support Macros
31 31 %==============================================================================
32 32
33 33 % Name: draw_prompt
34 34 % Purpose: Renders an output/input prompt
35 35 ((* macro add_prompt(text, cell, prompt) -*))
36 ((*- if cell.prompt_number is defined -*))
36 37 ((*- set prompt_number = "" ~ (cell.prompt_number | replace(None, " ")) -*))
38 ((*- else -*))
39 ((*- set prompt_number = " " -*))
40 ((*- endif -*))
37 41 ((*- set indentation = " " * (prompt_number | length + 7) -*))
38 42 \begin{verbatim}
39 43 (((- text | add_prompts(first=prompt ~ '[' ~ prompt_number ~ ']: ', cont=indentation) -)))
40 44 \end{verbatim}
41 45 ((*- endmacro *))
@@ -1,54 +1,58 b''
1 1 ((= IPython input/output style =))
2 2
3 3 ((*- extends 'base.tplx' -*))
4 4
5 5 % Custom definitions
6 6 ((* block definitions *))
7 7 ((( super() )))
8 8
9 9 % Pygments definitions
10 10 ((( resources.latex.pygments_definitions )))
11 11
12 12 % Exact colors from NB
13 13 \definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
14 14 \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
15 15
16 16 ((* endblock definitions *))
17 17
18 18 %===============================================================================
19 19 % Input
20 20 %===============================================================================
21 21
22 22 ((* block input scoped *))
23 23 ((( add_prompt(cell.input | highlight2latex(strip_verbatim=True), cell, 'In ', 'incolor') )))
24 24 ((* endblock input *))
25 25
26 26
27 27 %===============================================================================
28 28 % Output
29 29 %===============================================================================
30 30
31 31 ((* block pyout scoped *))
32 32 ((*- for type in output | filter_data_type -*))
33 33 ((*- if type in ['text']*))
34 34 ((( add_prompt(output.text | escape_latex, cell, 'Out', 'outcolor') )))
35 35 ((* else -*))
36 36 \texttt{\color{outcolor}Out[{\color{outcolor}((( cell.prompt_number )))}]:}((( super() )))
37 37 ((*- endif -*))
38 38 ((*- endfor -*))
39 39 ((* endblock pyout *))
40 40
41 41
42 42 %==============================================================================
43 43 % Support Macros
44 44 %==============================================================================
45 45
46 46 % Name: draw_prompt
47 47 % Purpose: Renders an output/input prompt
48 48 ((* macro add_prompt(text, cell, prompt, prompt_color) -*))
49 ((*- if cell.prompt_number is defined -*))
49 50 ((*- set prompt_number = "" ~ (cell.prompt_number | replace(None, " ")) -*))
51 ((*- else -*))
52 ((*- set prompt_number = " " -*))
53 ((*- endif -*))
50 54 ((*- set indention = " " * (prompt_number | length + 7) -*))
51 55 \begin{Verbatim}[commandchars=\\\{\}]
52 56 ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) )))
53 57 \end{Verbatim}
54 58 ((*- endmacro *))
General Comments 0
You need to be logged in to leave comments. Login now