Show More
@@ -1,131 +1,98 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module containing filter functions that allow code to be highlighted |
|
2 | Module containing filter functions that allow code to be highlighted | |
3 | from within Jinja templates. |
|
3 | from within Jinja templates. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | import re |
|
17 | import re | |
18 |
|
18 | |||
19 | from pygments import highlight as pygements_highlight |
|
19 | from pygments import highlight as pygements_highlight | |
20 | from pygments.lexers import get_lexer_by_name |
|
20 | from pygments.lexers import get_lexer_by_name | |
21 | from pygments.formatters import HtmlFormatter |
|
21 | from pygments.formatters import HtmlFormatter | |
22 | from pygments.formatters import LatexFormatter |
|
22 | from pygments.formatters import LatexFormatter | |
23 |
|
23 | |||
24 | # Our own imports |
|
24 | # Our own imports | |
25 | from IPython.nbconvert.utils.lexers import IPythonLexer |
|
25 | from IPython.nbconvert.utils.lexers import IPythonLexer | |
26 |
|
26 | |||
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 | # Globals and constants |
|
28 | # Globals and constants | |
29 | #----------------------------------------------------------------------------- |
|
29 | #----------------------------------------------------------------------------- | |
30 |
|
30 | |||
31 | MULTILINE_OUTPUTS = ['text', 'html', 'svg', 'latex', 'javascript', 'json'] |
|
31 | MULTILINE_OUTPUTS = ['text', 'html', 'svg', 'latex', 'javascript', 'json'] | |
32 |
|
32 | |||
33 | # list of magic language extensions and their associated pygment lexers |
|
|||
34 | magic_languages = {'%%R': 'r', |
|
|||
35 | '%%bash': 'bash', |
|
|||
36 | '%%octave': 'octave', |
|
|||
37 | '%%perl': 'perl', |
|
|||
38 | '%%ruby': 'ruby' |
|
|||
39 | } |
|
|||
40 |
|
||||
41 | # build a RE to catch language extensions and choose an adequate |
|
|||
42 | # pygments lexer |
|
|||
43 | re_languages = "|".join(magic_languages.keys()) |
|
|||
44 | re_magic_language = re.compile(r'^\s*({})\s+'.format(re_languages), |
|
|||
45 | re.MULTILINE) |
|
|||
46 |
|
||||
47 | #----------------------------------------------------------------------------- |
|
33 | #----------------------------------------------------------------------------- | |
48 | # Utility functions |
|
34 | # Utility functions | |
49 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
50 |
|
36 | |||
51 | __all__ = [ |
|
37 | __all__ = [ | |
52 | 'highlight2html', |
|
38 | 'highlight2html', | |
53 | 'highlight2latex' |
|
39 | 'highlight2latex' | |
54 | ] |
|
40 | ] | |
55 |
|
41 | |||
56 |
|
42 | def highlight2html(cell, language='ipython'): | ||
57 | def highlight2html(source, language='ipython'): |
|
|||
58 | """ |
|
43 | """ | |
59 | Return a syntax-highlighted version of the input source as html output. |
|
44 | Return a syntax-highlighted version of the input source as html output. | |
60 |
|
45 | |||
61 | Parameters |
|
46 | Parameters | |
62 | ---------- |
|
47 | ---------- | |
63 | source : str |
|
48 | cell : NotebookNode cell | |
64 |
|
|
49 | cell to highlight | |
65 | language : str |
|
50 | language : str | |
66 | Language to highlight the syntax of. |
|
51 | Language to highlight the syntax of. | |
67 | """ |
|
52 | """ | |
68 |
|
53 | |||
69 |
return _pygment_highlight( |
|
54 | return _pygment_highlight(cell, HtmlFormatter(), language) | |
70 |
|
55 | |||
71 |
|
56 | |||
72 |
def highlight2latex( |
|
57 | def highlight2latex(cell, language='ipython'): | |
73 | """ |
|
58 | """ | |
74 | Return a syntax-highlighted version of the input source as latex output. |
|
59 | Return a syntax-highlighted version of the input source as latex output. | |
75 |
|
60 | |||
76 | Parameters |
|
61 | Parameters | |
77 | ---------- |
|
62 | ---------- | |
78 | source : str |
|
63 | cell : NotebookNode cell | |
79 |
|
|
64 | cell to highlight | |
80 | language : str |
|
65 | language : str | |
81 | Language to highlight the syntax of. |
|
66 | Language to highlight the syntax of. | |
82 | """ |
|
67 | """ | |
83 |
return _pygment_highlight( |
|
68 | return _pygment_highlight(cell, LatexFormatter(), language) | |
84 |
|
||||
85 |
|
||||
86 | def which_magic_language(source): |
|
|||
87 | """ |
|
|||
88 | When a cell uses another language through a magic extension, |
|
|||
89 | the other language is returned. |
|
|||
90 | If no language magic is detected, this function returns None. |
|
|||
91 |
|
||||
92 | Parameters |
|
|||
93 | ---------- |
|
|||
94 | source: str |
|
|||
95 | Source code of the cell to highlight |
|
|||
96 | """ |
|
|||
97 |
|
69 | |||
98 | m = re_magic_language.search(source) |
|
|||
99 |
|
||||
100 | if m: |
|
|||
101 | # By construction of the re, the matched language must be in the |
|
|||
102 | # language dictionnary |
|
|||
103 | assert(m.group(1) in magic_languages) |
|
|||
104 | return magic_languages[m.group(1)] |
|
|||
105 | else: |
|
|||
106 | return None |
|
|||
107 |
|
70 | |||
108 |
|
71 | |||
109 |
def _pygment_highlight( |
|
72 | def _pygment_highlight(cell, output_formatter, language='ipython'): | |
110 | """ |
|
73 | """ | |
111 | Return a syntax-highlighted version of the input source |
|
74 | Return a syntax-highlighted version of the input source | |
112 |
|
75 | |||
113 | Parameters |
|
76 | Parameters | |
114 | ---------- |
|
77 | ---------- | |
115 | source : str |
|
78 | cell : NotebookNode cell | |
116 |
|
|
79 | cell to highlight | |
117 | output_formatter : Pygments formatter |
|
80 | output_formatter : Pygments formatter | |
118 | language : str |
|
81 | language : str | |
119 | Language to highlight the syntax of. |
|
82 | Language to highlight the syntax of. | |
120 | """ |
|
83 | """ | |
121 |
|
84 | |||
122 | magic_language = which_magic_language(source) |
|
85 | # If the cell uses a magic extension language, | |
123 |
|
|
86 | # use the magic language instead. | |
124 | language = magic_language |
|
87 | if language == 'ipython' \ | |
|
88 | and 'metadata' in cell \ | |||
|
89 | and 'magics_language' in cell['metadata']: | |||
|
90 | ||||
|
91 | language = cell['metadata']['magics_language'] | |||
125 |
|
92 | |||
126 | if language == 'ipython': |
|
93 | if language == 'ipython': | |
127 | lexer = IPythonLexer() |
|
94 | lexer = IPythonLexer() | |
128 | else: |
|
95 | else: | |
129 | lexer = get_lexer_by_name(language, stripall=True) |
|
96 | lexer = get_lexer_by_name(language, stripall=True) | |
130 |
|
97 | |||
131 |
return pygements_highlight( |
|
98 | return pygements_highlight(cell, lexer, output_formatter) |
@@ -1,97 +1,65 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for Highlight |
|
2 | Module with tests for Highlight | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | from ...tests.base import TestsBase |
|
17 | from ...tests.base import TestsBase | |
18 |
from ..highlight import highlight2html, highlight2latex |
|
18 | from ..highlight import highlight2html, highlight2latex | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
22 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
|
24 | |||
25 | class TestHighlight(TestsBase): |
|
25 | class TestHighlight(TestsBase): | |
26 | """Contains test functions for highlight.py""" |
|
26 | """Contains test functions for highlight.py""" | |
27 |
|
27 | |||
28 | #Hello world test, magics test, blank string test |
|
28 | #Hello world test, magics test, blank string test | |
29 | tests = [ |
|
29 | tests = [ | |
30 | """ |
|
30 | """ | |
31 | #Hello World Example |
|
31 | #Hello World Example | |
32 |
|
32 | |||
33 | def say(text): |
|
33 | def say(text): | |
34 | print(text) |
|
34 | print(text) | |
35 |
|
35 | |||
36 | say('Hello World!') |
|
36 | say('Hello World!') | |
37 | """, |
|
37 | """, | |
38 | """ |
|
38 | """ | |
39 | %%pylab |
|
39 | %%pylab | |
40 | plot(x,y, 'r') |
|
40 | plot(x,y, 'r') | |
41 | """ |
|
41 | """ | |
42 | ] |
|
42 | ] | |
43 |
|
43 | |||
44 | tokens = [ |
|
44 | tokens = [ | |
45 | ['Hello World Example', 'say', 'text', 'print', 'def'], |
|
45 | ['Hello World Example', 'say', 'text', 'print', 'def'], | |
46 | ['pylab', 'plot']] |
|
46 | ['pylab', 'plot']] | |
47 |
|
47 | |||
|
48 | ||||
48 | def test_highlight2html(self): |
|
49 | def test_highlight2html(self): | |
49 | """highlight2html test""" |
|
50 | """highlight2html test""" | |
50 | for index, test in enumerate(self.tests): |
|
51 | for index, test in enumerate(self.tests): | |
51 | self._try_highlight(highlight2html, test, self.tokens[index]) |
|
52 | self._try_highlight(highlight2html, test, self.tokens[index]) | |
52 |
|
53 | |||
|
54 | ||||
53 | def test_highlight2latex(self): |
|
55 | def test_highlight2latex(self): | |
54 | """highlight2latex test""" |
|
56 | """highlight2latex test""" | |
55 | for index, test in enumerate(self.tests): |
|
57 | for index, test in enumerate(self.tests): | |
56 | self._try_highlight(highlight2latex, test, self.tokens[index]) |
|
58 | self._try_highlight(highlight2latex, test, self.tokens[index]) | |
57 |
|
59 | |||
|
60 | ||||
58 | def _try_highlight(self, method, test, tokens): |
|
61 | def _try_highlight(self, method, test, tokens): | |
59 | """Try highlighting source, look for key tokens""" |
|
62 | """Try highlighting source, look for key tokens""" | |
60 | results = method(test) |
|
63 | results = method(test) | |
61 | for token in tokens: |
|
64 | for token in tokens: | |
62 | assert token in results |
|
65 | assert token in results | |
63 |
|
||||
64 | magic_tests = { |
|
|||
65 | 'r': |
|
|||
66 | """%%R -i x,y -o XYcoef |
|
|||
67 | lm.fit <- lm(y~x) |
|
|||
68 | par(mfrow=c(2,2)) |
|
|||
69 | print(summary(lm.fit)) |
|
|||
70 | plot(lm.fit) |
|
|||
71 | XYcoef <- coef(lm.fit) |
|
|||
72 | """, |
|
|||
73 | 'bash': |
|
|||
74 | """# the following code is in bash |
|
|||
75 | %%bash |
|
|||
76 | echo "test" > out |
|
|||
77 | """, |
|
|||
78 | 'ipython': |
|
|||
79 | """# this should not be detected |
|
|||
80 | print("%%R") |
|
|||
81 | """ |
|
|||
82 | } |
|
|||
83 |
|
||||
84 | def test_highlight_rmagic(self): |
|
|||
85 | """Test %%R magic highlighting""" |
|
|||
86 | language = which_magic_language(self.magic_tests['r']) |
|
|||
87 | assert language == 'r' |
|
|||
88 |
|
||||
89 | def test_highlight_bashmagic(self): |
|
|||
90 | """Test %%bash magic highlighting""" |
|
|||
91 | language = which_magic_language(self.magic_tests['bash']) |
|
|||
92 | assert language == 'bash' |
|
|||
93 |
|
||||
94 | def test_highlight_interferemagic(self): |
|
|||
95 | """Test that magic highlighting does not interfere with ipython code""" |
|
|||
96 | language = which_magic_language(self.magic_tests['ipython']) |
|
|||
97 | assert language == None No newline at end of file |
|
@@ -1,148 +1,148 b'' | |||||
1 | {%- extends 'display_priority.tpl' -%} |
|
1 | {%- extends 'display_priority.tpl' -%} | |
2 |
|
2 | |||
3 |
|
3 | |||
4 | {% block codecell %} |
|
4 | {% block codecell %} | |
5 | <div class="cell border-box-sizing code_cell vbox"> |
|
5 | <div class="cell border-box-sizing code_cell vbox"> | |
6 | {{ super() }} |
|
6 | {{ super() }} | |
7 | </div> |
|
7 | </div> | |
8 | {%- endblock codecell %} |
|
8 | {%- endblock codecell %} | |
9 |
|
9 | |||
10 | {% block input_group -%} |
|
10 | {% block input_group -%} | |
11 | <div class="input hbox"> |
|
11 | <div class="input hbox"> | |
12 | {{ super() }} |
|
12 | {{ super() }} | |
13 | </div> |
|
13 | </div> | |
14 | {% endblock input_group %} |
|
14 | {% endblock input_group %} | |
15 |
|
15 | |||
16 | {% block output_group %} |
|
16 | {% block output_group %} | |
17 | <div class="vbox output_wrapper"> |
|
17 | <div class="vbox output_wrapper"> | |
18 | <div class="output vbox"> |
|
18 | <div class="output vbox"> | |
19 | {{ super() }} |
|
19 | {{ super() }} | |
20 | </div> |
|
20 | </div> | |
21 | </div> |
|
21 | </div> | |
22 | {% endblock output_group %} |
|
22 | {% endblock output_group %} | |
23 |
|
23 | |||
24 | {% block in_prompt -%} |
|
24 | {% block in_prompt -%} | |
25 | <div class="prompt input_prompt"> |
|
25 | <div class="prompt input_prompt"> | |
26 | In [{{ cell.prompt_number }}]: |
|
26 | In [{{ cell.prompt_number }}]: | |
27 | </div> |
|
27 | </div> | |
28 | {%- endblock in_prompt %} |
|
28 | {%- endblock in_prompt %} | |
29 |
|
29 | |||
30 | {# |
|
30 | {# | |
31 | output_prompt doesn't do anything in HTML, |
|
31 | output_prompt doesn't do anything in HTML, | |
32 | because there is a prompt div in each output area (see output block) |
|
32 | because there is a prompt div in each output area (see output block) | |
33 | #} |
|
33 | #} | |
34 | {% block output_prompt %} |
|
34 | {% block output_prompt %} | |
35 | {% endblock output_prompt %} |
|
35 | {% endblock output_prompt %} | |
36 |
|
36 | |||
37 | {% block input %} |
|
37 | {% block input %} | |
38 | <div class="input_area box-flex1"> |
|
38 | <div class="input_area box-flex1"> | |
39 |
{{ cell |
|
39 | {{ cell | highlight2html }} | |
40 | </div> |
|
40 | </div> | |
41 | {%- endblock input %} |
|
41 | {%- endblock input %} | |
42 |
|
42 | |||
43 | {% block output %} |
|
43 | {% block output %} | |
44 | <div class="hbox output_area"> |
|
44 | <div class="hbox output_area"> | |
45 | {%- if output.output_type == 'pyout' -%} |
|
45 | {%- if output.output_type == 'pyout' -%} | |
46 | <div class="prompt output_prompt"> |
|
46 | <div class="prompt output_prompt"> | |
47 | Out[{{ cell.prompt_number }}]: |
|
47 | Out[{{ cell.prompt_number }}]: | |
48 | {%- else -%} |
|
48 | {%- else -%} | |
49 | <div class="prompt"> |
|
49 | <div class="prompt"> | |
50 | {%- endif -%} |
|
50 | {%- endif -%} | |
51 | </div> |
|
51 | </div> | |
52 | {{ super() }} |
|
52 | {{ super() }} | |
53 | </div> |
|
53 | </div> | |
54 | {% endblock output %} |
|
54 | {% endblock output %} | |
55 |
|
55 | |||
56 | {% block markdowncell scoped %} |
|
56 | {% block markdowncell scoped %} | |
57 | <div class="text_cell_render border-box-sizing rendered_html"> |
|
57 | <div class="text_cell_render border-box-sizing rendered_html"> | |
58 | {{ cell.source | strip_math_space | markdown2html | strip_files_prefix }} |
|
58 | {{ cell.source | strip_math_space | markdown2html | strip_files_prefix }} | |
59 | </div> |
|
59 | </div> | |
60 | {%- endblock markdowncell %} |
|
60 | {%- endblock markdowncell %} | |
61 |
|
61 | |||
62 | {% block headingcell scoped %} |
|
62 | {% block headingcell scoped %} | |
63 | <div class="text_cell_render border-box-sizing rendered_html"> |
|
63 | <div class="text_cell_render border-box-sizing rendered_html"> | |
64 | {{ ("#" * cell.level + cell.source) | replace('\n', ' ') | strip_math_space | markdown2html | strip_files_prefix | add_anchor }} |
|
64 | {{ ("#" * cell.level + cell.source) | replace('\n', ' ') | strip_math_space | markdown2html | strip_files_prefix | add_anchor }} | |
65 | </div> |
|
65 | </div> | |
66 | {% endblock headingcell %} |
|
66 | {% endblock headingcell %} | |
67 |
|
67 | |||
68 | {% block rawcell scoped %} |
|
68 | {% block rawcell scoped %} | |
69 | {{ cell.source }} |
|
69 | {{ cell.source }} | |
70 | {% endblock rawcell %} |
|
70 | {% endblock rawcell %} | |
71 |
|
71 | |||
72 | {% block unknowncell scoped %} |
|
72 | {% block unknowncell scoped %} | |
73 | unknown type {{ cell.type }} |
|
73 | unknown type {{ cell.type }} | |
74 | {% endblock unknowncell %} |
|
74 | {% endblock unknowncell %} | |
75 |
|
75 | |||
76 | {% block pyout -%} |
|
76 | {% block pyout -%} | |
77 | <div class="box-flex1 output_subarea output_pyout"> |
|
77 | <div class="box-flex1 output_subarea output_pyout"> | |
78 | {% block data_priority scoped %} |
|
78 | {% block data_priority scoped %} | |
79 | {{ super() }} |
|
79 | {{ super() }} | |
80 | {% endblock %} |
|
80 | {% endblock %} | |
81 | </div> |
|
81 | </div> | |
82 | {%- endblock pyout %} |
|
82 | {%- endblock pyout %} | |
83 |
|
83 | |||
84 | {% block stream_stdout -%} |
|
84 | {% block stream_stdout -%} | |
85 | <div class="box-flex1 output_subarea output_stream output_stdout"> |
|
85 | <div class="box-flex1 output_subarea output_stream output_stdout"> | |
86 | <pre> |
|
86 | <pre> | |
87 | {{ output.text | ansi2html }} |
|
87 | {{ output.text | ansi2html }} | |
88 | </pre> |
|
88 | </pre> | |
89 | </div> |
|
89 | </div> | |
90 | {%- endblock stream_stdout %} |
|
90 | {%- endblock stream_stdout %} | |
91 |
|
91 | |||
92 | {% block stream_stderr -%} |
|
92 | {% block stream_stderr -%} | |
93 | <div class="box-flex1 output_subarea output_stream output_stderr"> |
|
93 | <div class="box-flex1 output_subarea output_stream output_stderr"> | |
94 | <pre> |
|
94 | <pre> | |
95 | {{ output.text | ansi2html }} |
|
95 | {{ output.text | ansi2html }} | |
96 | </pre> |
|
96 | </pre> | |
97 | </div> |
|
97 | </div> | |
98 | {%- endblock stream_stderr %} |
|
98 | {%- endblock stream_stderr %} | |
99 |
|
99 | |||
100 | {% block data_svg -%} |
|
100 | {% block data_svg -%} | |
101 | {{ output.svg }} |
|
101 | {{ output.svg }} | |
102 | {%- endblock data_svg %} |
|
102 | {%- endblock data_svg %} | |
103 |
|
103 | |||
104 | {% block data_html -%} |
|
104 | {% block data_html -%} | |
105 | <div class="output_html rendered_html"> |
|
105 | <div class="output_html rendered_html"> | |
106 | {{ output.html }} |
|
106 | {{ output.html }} | |
107 | </div> |
|
107 | </div> | |
108 | {%- endblock data_html %} |
|
108 | {%- endblock data_html %} | |
109 |
|
109 | |||
110 | {% block data_png %} |
|
110 | {% block data_png %} | |
111 | <img src="data:image/png;base64,{{ output.png }}"> |
|
111 | <img src="data:image/png;base64,{{ output.png }}"> | |
112 | {%- endblock data_png %} |
|
112 | {%- endblock data_png %} | |
113 |
|
113 | |||
114 | {% block data_jpg %} |
|
114 | {% block data_jpg %} | |
115 | <img src="data:image/jpeg;base64,{{ output.jpeg }}"> |
|
115 | <img src="data:image/jpeg;base64,{{ output.jpeg }}"> | |
116 | {%- endblock data_jpg %} |
|
116 | {%- endblock data_jpg %} | |
117 |
|
117 | |||
118 | {% block data_latex %} |
|
118 | {% block data_latex %} | |
119 | {{ output.latex }} |
|
119 | {{ output.latex }} | |
120 | {%- endblock data_latex %} |
|
120 | {%- endblock data_latex %} | |
121 |
|
121 | |||
122 | {% block pyerr -%} |
|
122 | {% block pyerr -%} | |
123 | <div class="box-flex1 output_subarea output_pyerr"> |
|
123 | <div class="box-flex1 output_subarea output_pyerr"> | |
124 | <pre>{{ super() }}</pre> |
|
124 | <pre>{{ super() }}</pre> | |
125 | </div> |
|
125 | </div> | |
126 | {%- endblock pyerr %} |
|
126 | {%- endblock pyerr %} | |
127 |
|
127 | |||
128 | {%- block traceback_line %} |
|
128 | {%- block traceback_line %} | |
129 | {{ line | ansi2html }} |
|
129 | {{ line | ansi2html }} | |
130 | {%- endblock traceback_line %} |
|
130 | {%- endblock traceback_line %} | |
131 |
|
131 | |||
132 | {%- block data_text %} |
|
132 | {%- block data_text %} | |
133 | <pre> |
|
133 | <pre> | |
134 | {{ output.text | ansi2html }} |
|
134 | {{ output.text | ansi2html }} | |
135 | </pre> |
|
135 | </pre> | |
136 | {%- endblock -%} |
|
136 | {%- endblock -%} | |
137 |
|
137 | |||
138 | {%- block data_javascript %} |
|
138 | {%- block data_javascript %} | |
139 | <script type="text/javascript"> |
|
139 | <script type="text/javascript"> | |
140 | {{ output.javascript }} |
|
140 | {{ output.javascript }} | |
141 | </script> |
|
141 | </script> | |
142 | {%- endblock -%} |
|
142 | {%- endblock -%} | |
143 |
|
143 | |||
144 | {%- block display_data scoped -%} |
|
144 | {%- block display_data scoped -%} | |
145 | <div class="box-flex1 output_subarea output_display_data"> |
|
145 | <div class="box-flex1 output_subarea output_display_data"> | |
146 | {{ super() }} |
|
146 | {{ super() }} | |
147 | </div> |
|
147 | </div> | |
148 | {%- endblock display_data -%} No newline at end of file |
|
148 | {%- endblock display_data -%} |
@@ -1,472 +1,472 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 |
|
6 | Inheritance: null>display_priority | |
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 | \nonstopmode |
|
13 | \nonstopmode | |
14 |
|
14 | |||
15 | %============================================================================== |
|
15 | %============================================================================== | |
16 | % Declarations |
|
16 | % Declarations | |
17 | %============================================================================== |
|
17 | %============================================================================== | |
18 |
|
18 | |||
19 | % In order to make sure that the input/output header follows the code it |
|
19 | % In order to make sure that the input/output header follows the code it | |
20 | % preceeds, the needspace package is used to request that a certain |
|
20 | % preceeds, the needspace package is used to request that a certain | |
21 | % amount of lines (specified by this variable) are reserved. If those |
|
21 | % amount of lines (specified by this variable) are reserved. If those | |
22 | % lines aren't available on the current page, the documenter will break |
|
22 | % lines aren't available on the current page, the documenter will break | |
23 | % to the next page and the header along with accomanying lines will be |
|
23 | % to the next page and the header along with accomanying lines will be | |
24 | % rendered together. This value specifies the number of lines that |
|
24 | % rendered together. This value specifies the number of lines that | |
25 | % the header will be forced to group with without a page break. |
|
25 | % the header will be forced to group with without a page break. | |
26 | ((*- set min_header_lines = 4 -*)) |
|
26 | ((*- set min_header_lines = 4 -*)) | |
27 |
|
27 | |||
28 | % This is the number of characters that are permitted per line. It's |
|
28 | % This is the number of characters that are permitted per line. It's | |
29 | % important that this limit is set so characters do not run off the |
|
29 | % important that this limit is set so characters do not run off the | |
30 | % edges of latex pages (since latex does not always seem smart enough |
|
30 | % edges of latex pages (since latex does not always seem smart enough | |
31 | % to prevent this in some cases.) This is only applied to textual output |
|
31 | % to prevent this in some cases.) This is only applied to textual output | |
32 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
32 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |
33 | ((*- set wrap_size = 85 -*)) |
|
33 | ((*- set wrap_size = 85 -*)) | |
34 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
34 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
35 | ((*- set wrap_size = 70 -*)) |
|
35 | ((*- set wrap_size = 70 -*)) | |
36 | ((* endif *)) |
|
36 | ((* endif *)) | |
37 |
|
37 | |||
38 | %============================================================================== |
|
38 | %============================================================================== | |
39 | % Header |
|
39 | % Header | |
40 | %============================================================================== |
|
40 | %============================================================================== | |
41 | ((* block header *)) |
|
41 | ((* block header *)) | |
42 |
|
42 | |||
43 | % Header, overrides base |
|
43 | % Header, overrides base | |
44 |
|
44 | |||
45 | % Make sure that the sphinx doc style knows who it inherits from. |
|
45 | % Make sure that the sphinx doc style knows who it inherits from. | |
46 | \def\sphinxdocclass{(((parentdocumentclass)))} |
|
46 | \def\sphinxdocclass{(((parentdocumentclass)))} | |
47 |
|
47 | |||
48 | % Declare the document class |
|
48 | % Declare the document class | |
49 | \documentclass[letterpaper,10pt,english]{((( resources.sphinx.texinputs | posix_path )))/sphinx(((documentclass)))} |
|
49 | \documentclass[letterpaper,10pt,english]{((( resources.sphinx.texinputs | posix_path )))/sphinx(((documentclass)))} | |
50 |
|
50 | |||
51 | % Imports |
|
51 | % Imports | |
52 | \usepackage[utf8]{inputenc} |
|
52 | \usepackage[utf8]{inputenc} | |
53 | \DeclareUnicodeCharacter{00A0}{\\nobreakspace} |
|
53 | \DeclareUnicodeCharacter{00A0}{\\nobreakspace} | |
54 | \usepackage[T1]{fontenc} |
|
54 | \usepackage[T1]{fontenc} | |
55 | \usepackage{babel} |
|
55 | \usepackage{babel} | |
56 | \usepackage{times} |
|
56 | \usepackage{times} | |
57 | \usepackage{import} |
|
57 | \usepackage{import} | |
58 | \usepackage[((( resources.sphinx.chapterstyle )))]{((( resources.sphinx.texinputs | posix_path )))/fncychap} |
|
58 | \usepackage[((( resources.sphinx.chapterstyle )))]{((( resources.sphinx.texinputs | posix_path )))/fncychap} | |
59 | \usepackage{longtable} |
|
59 | \usepackage{longtable} | |
60 | \usepackage{((( resources.sphinx.texinputs | posix_path )))/sphinx} |
|
60 | \usepackage{((( resources.sphinx.texinputs | posix_path )))/sphinx} | |
61 | \usepackage{multirow} |
|
61 | \usepackage{multirow} | |
62 |
|
62 | |||
63 | \usepackage{amsmath} |
|
63 | \usepackage{amsmath} | |
64 | \usepackage{amssymb} |
|
64 | \usepackage{amssymb} | |
65 | \usepackage{ucs} |
|
65 | \usepackage{ucs} | |
66 | \usepackage{enumerate} |
|
66 | \usepackage{enumerate} | |
67 |
|
67 | |||
68 | % Used to make the Input/Output rules follow around the contents. |
|
68 | % Used to make the Input/Output rules follow around the contents. | |
69 | \usepackage{needspace} |
|
69 | \usepackage{needspace} | |
70 |
|
70 | |||
71 | % Pygments requirements |
|
71 | % Pygments requirements | |
72 | \usepackage{fancyvrb} |
|
72 | \usepackage{fancyvrb} | |
73 | \usepackage{color} |
|
73 | \usepackage{color} | |
74 | % ansi colors additions |
|
74 | % ansi colors additions | |
75 | \definecolor{darkgreen}{rgb}{.12,.54,.11} |
|
75 | \definecolor{darkgreen}{rgb}{.12,.54,.11} | |
76 | \definecolor{lightgray}{gray}{.95} |
|
76 | \definecolor{lightgray}{gray}{.95} | |
77 | \definecolor{brown}{rgb}{0.54,0.27,0.07} |
|
77 | \definecolor{brown}{rgb}{0.54,0.27,0.07} | |
78 | \definecolor{purple}{rgb}{0.5,0.0,0.5} |
|
78 | \definecolor{purple}{rgb}{0.5,0.0,0.5} | |
79 | \definecolor{darkgray}{gray}{0.25} |
|
79 | \definecolor{darkgray}{gray}{0.25} | |
80 | \definecolor{lightred}{rgb}{1.0,0.39,0.28} |
|
80 | \definecolor{lightred}{rgb}{1.0,0.39,0.28} | |
81 | \definecolor{lightgreen}{rgb}{0.48,0.99,0.0} |
|
81 | \definecolor{lightgreen}{rgb}{0.48,0.99,0.0} | |
82 | \definecolor{lightblue}{rgb}{0.53,0.81,0.92} |
|
82 | \definecolor{lightblue}{rgb}{0.53,0.81,0.92} | |
83 | \definecolor{lightpurple}{rgb}{0.87,0.63,0.87} |
|
83 | \definecolor{lightpurple}{rgb}{0.87,0.63,0.87} | |
84 | \definecolor{lightcyan}{rgb}{0.5,1.0,0.83} |
|
84 | \definecolor{lightcyan}{rgb}{0.5,1.0,0.83} | |
85 |
|
85 | |||
86 | % Needed to box output/input |
|
86 | % Needed to box output/input | |
87 | \usepackage{tikz} |
|
87 | \usepackage{tikz} | |
88 | \usetikzlibrary{calc,arrows,shadows} |
|
88 | \usetikzlibrary{calc,arrows,shadows} | |
89 | \usepackage[framemethod=tikz]{mdframed} |
|
89 | \usepackage[framemethod=tikz]{mdframed} | |
90 |
|
90 | |||
91 | \usepackage{alltt} |
|
91 | \usepackage{alltt} | |
92 |
|
92 | |||
93 | % Used to load and display graphics |
|
93 | % Used to load and display graphics | |
94 | \usepackage{graphicx} |
|
94 | \usepackage{graphicx} | |
95 | \graphicspath{ {figs/} } |
|
95 | \graphicspath{ {figs/} } | |
96 | \usepackage[Export]{adjustbox} % To resize |
|
96 | \usepackage[Export]{adjustbox} % To resize | |
97 |
|
97 | |||
98 | % used so that images for notebooks which have spaces in the name can still be included |
|
98 | % used so that images for notebooks which have spaces in the name can still be included | |
99 | \usepackage{grffile} |
|
99 | \usepackage{grffile} | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | % For formatting output while also word wrapping. |
|
102 | % For formatting output while also word wrapping. | |
103 | \usepackage{listings} |
|
103 | \usepackage{listings} | |
104 | \lstset{breaklines=true} |
|
104 | \lstset{breaklines=true} | |
105 | \lstset{basicstyle=\small\ttfamily} |
|
105 | \lstset{basicstyle=\small\ttfamily} | |
106 | \def\smaller{\fontsize{9.5pt}{9.5pt}\selectfont} |
|
106 | \def\smaller{\fontsize{9.5pt}{9.5pt}\selectfont} | |
107 |
|
107 | |||
108 | %Pygments definitions |
|
108 | %Pygments definitions | |
109 | ((( resources.sphinx.pygment_definitions ))) |
|
109 | ((( resources.sphinx.pygment_definitions ))) | |
110 |
|
110 | |||
111 | %Set pygments styles if needed... |
|
111 | %Set pygments styles if needed... | |
112 | ((* if resources.sphinx.outputstyle == 'notebook' *)) |
|
112 | ((* if resources.sphinx.outputstyle == 'notebook' *)) | |
113 | \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867} |
|
113 | \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867} | |
114 | \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969} |
|
114 | \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969} | |
115 | \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502} |
|
115 | \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502} | |
116 | \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0} |
|
116 | \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0} | |
117 |
|
117 | |||
118 | \newenvironment{ColorVerbatim} |
|
118 | \newenvironment{ColorVerbatim} | |
119 | {\begin{mdframed}[% |
|
119 | {\begin{mdframed}[% | |
120 | roundcorner=1.0pt, % |
|
120 | roundcorner=1.0pt, % | |
121 | backgroundcolor=nbframe-bg, % |
|
121 | backgroundcolor=nbframe-bg, % | |
122 | userdefinedwidth=1\linewidth, % |
|
122 | userdefinedwidth=1\linewidth, % | |
123 | leftmargin=0.1\linewidth, % |
|
123 | leftmargin=0.1\linewidth, % | |
124 | innerleftmargin=0pt, % |
|
124 | innerleftmargin=0pt, % | |
125 | innerrightmargin=0pt, % |
|
125 | innerrightmargin=0pt, % | |
126 | linecolor=nbframe-border, % |
|
126 | linecolor=nbframe-border, % | |
127 | linewidth=1pt, % |
|
127 | linewidth=1pt, % | |
128 | usetwoside=false, % |
|
128 | usetwoside=false, % | |
129 | everyline=true, % |
|
129 | everyline=true, % | |
130 | innerlinewidth=3pt, % |
|
130 | innerlinewidth=3pt, % | |
131 | innerlinecolor=nbframe-bg, % |
|
131 | innerlinecolor=nbframe-bg, % | |
132 | middlelinewidth=1pt, % |
|
132 | middlelinewidth=1pt, % | |
133 | middlelinecolor=nbframe-bg, % |
|
133 | middlelinecolor=nbframe-bg, % | |
134 | outerlinewidth=0.5pt, % |
|
134 | outerlinewidth=0.5pt, % | |
135 | outerlinecolor=nbframe-border, % |
|
135 | outerlinecolor=nbframe-border, % | |
136 | needspace=0pt |
|
136 | needspace=0pt | |
137 | ]} |
|
137 | ]} | |
138 | {\end{mdframed}} |
|
138 | {\end{mdframed}} | |
139 |
|
139 | |||
140 | \newenvironment{InvisibleVerbatim} |
|
140 | \newenvironment{InvisibleVerbatim} | |
141 | {\begin{mdframed}[leftmargin=0.1\linewidth,innerleftmargin=3pt,innerrightmargin=3pt, userdefinedwidth=1\linewidth, linewidth=0pt, linecolor=white, usetwoside=false]} |
|
141 | {\begin{mdframed}[leftmargin=0.1\linewidth,innerleftmargin=3pt,innerrightmargin=3pt, userdefinedwidth=1\linewidth, linewidth=0pt, linecolor=white, usetwoside=false]} | |
142 | {\end{mdframed}} |
|
142 | {\end{mdframed}} | |
143 |
|
143 | |||
144 | \renewenvironment{Verbatim}[1][\unskip] |
|
144 | \renewenvironment{Verbatim}[1][\unskip] | |
145 | {\begin{alltt}\smaller} |
|
145 | {\begin{alltt}\smaller} | |
146 | {\end{alltt}} |
|
146 | {\end{alltt}} | |
147 | ((* endif *)) |
|
147 | ((* endif *)) | |
148 |
|
148 | |||
149 | % Help prevent overflowing lines due to urls and other hard-to-break |
|
149 | % Help prevent overflowing lines due to urls and other hard-to-break | |
150 | % entities. This doesn't catch everything... |
|
150 | % entities. This doesn't catch everything... | |
151 | \sloppy |
|
151 | \sloppy | |
152 |
|
152 | |||
153 | % Document level variables |
|
153 | % Document level variables | |
154 | \title{((( resources.metadata.name | escape_latex )))} |
|
154 | \title{((( resources.metadata.name | escape_latex )))} | |
155 | \date{((( resources.sphinx.date | escape_latex )))} |
|
155 | \date{((( resources.sphinx.date | escape_latex )))} | |
156 | \release{((( resources.sphinx.version | escape_latex )))} |
|
156 | \release{((( resources.sphinx.version | escape_latex )))} | |
157 | \author{((( resources.sphinx.author | escape_latex )))} |
|
157 | \author{((( resources.sphinx.author | escape_latex )))} | |
158 | \renewcommand{\releasename}{((( resources.sphinx.release | escape_latex )))} |
|
158 | \renewcommand{\releasename}{((( resources.sphinx.release | escape_latex )))} | |
159 |
|
159 | |||
160 | % TODO: Add option for the user to specify a logo for his/her export. |
|
160 | % TODO: Add option for the user to specify a logo for his/her export. | |
161 | \newcommand{\sphinxlogo}{} |
|
161 | \newcommand{\sphinxlogo}{} | |
162 |
|
162 | |||
163 | % Make the index page of the document. |
|
163 | % Make the index page of the document. | |
164 | \makeindex |
|
164 | \makeindex | |
165 |
|
165 | |||
166 | % Import sphinx document type specifics. |
|
166 | % Import sphinx document type specifics. | |
167 | ((* block sphinxheader *))((* endblock sphinxheader *)) |
|
167 | ((* block sphinxheader *))((* endblock sphinxheader *)) | |
168 | ((* endblock header *)) |
|
168 | ((* endblock header *)) | |
169 |
|
169 | |||
170 | %============================================================================== |
|
170 | %============================================================================== | |
171 | % Body |
|
171 | % Body | |
172 | %============================================================================== |
|
172 | %============================================================================== | |
173 | ((* block body *)) |
|
173 | ((* block body *)) | |
174 | ((* block bodyBegin *)) |
|
174 | ((* block bodyBegin *)) | |
175 | % Body |
|
175 | % Body | |
176 |
|
176 | |||
177 | % Start of the document |
|
177 | % Start of the document | |
178 | \begin{document} |
|
178 | \begin{document} | |
179 |
|
179 | |||
180 | ((* if resources.sphinx.header *)) |
|
180 | ((* if resources.sphinx.header *)) | |
181 | \maketitle |
|
181 | \maketitle | |
182 | ((* endif *)) |
|
182 | ((* endif *)) | |
183 |
|
183 | |||
184 | ((* block toc *)) |
|
184 | ((* block toc *)) | |
185 | \tableofcontents |
|
185 | \tableofcontents | |
186 | ((* endblock toc *)) |
|
186 | ((* endblock toc *)) | |
187 |
|
187 | |||
188 | ((* endblock bodyBegin *)) |
|
188 | ((* endblock bodyBegin *)) | |
189 | ((( super() ))) |
|
189 | ((( super() ))) | |
190 | ((* block bodyEnd *)) |
|
190 | ((* block bodyEnd *)) | |
191 |
|
191 | |||
192 | \renewcommand{\indexname}{Index} |
|
192 | \renewcommand{\indexname}{Index} | |
193 | \printindex |
|
193 | \printindex | |
194 |
|
194 | |||
195 | ((* block bibliography *)) |
|
195 | ((* block bibliography *)) | |
196 | ((* endblock bibliography *)) |
|
196 | ((* endblock bibliography *)) | |
197 |
|
197 | |||
198 | % End of document |
|
198 | % End of document | |
199 | \end{document} |
|
199 | \end{document} | |
200 | ((* endblock bodyEnd *)) |
|
200 | ((* endblock bodyEnd *)) | |
201 | ((* endblock body *)) |
|
201 | ((* endblock body *)) | |
202 |
|
202 | |||
203 | %============================================================================== |
|
203 | %============================================================================== | |
204 | % Footer |
|
204 | % Footer | |
205 | %============================================================================== |
|
205 | %============================================================================== | |
206 | ((* block footer *)) |
|
206 | ((* block footer *)) | |
207 | ((* endblock footer *)) |
|
207 | ((* endblock footer *)) | |
208 |
|
208 | |||
209 | %============================================================================== |
|
209 | %============================================================================== | |
210 | % Headings |
|
210 | % Headings | |
211 | % |
|
211 | % | |
212 | % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx |
|
212 | % Purpose: Format pynb headers as sphinx headers. Depending on the Sphinx | |
213 | % style that is active, this will change. Thus sphinx styles will |
|
213 | % style that is active, this will change. Thus sphinx styles will | |
214 | % override the values here. |
|
214 | % override the values here. | |
215 | %============================================================================== |
|
215 | %============================================================================== | |
216 | ((* block headingcell -*)) |
|
216 | ((* block headingcell -*)) | |
217 | \ |
|
217 | \ | |
218 | ((*- if cell.level == 1 -*)) |
|
218 | ((*- if cell.level == 1 -*)) | |
219 | ((* block h1 -*))part((* endblock h1 -*)) |
|
219 | ((* block h1 -*))part((* endblock h1 -*)) | |
220 | ((*- elif cell.level == 2 -*)) |
|
220 | ((*- elif cell.level == 2 -*)) | |
221 | ((* block h2 -*))chapter((* endblock h2 -*)) |
|
221 | ((* block h2 -*))chapter((* endblock h2 -*)) | |
222 | ((*- elif cell.level == 3 -*)) |
|
222 | ((*- elif cell.level == 3 -*)) | |
223 | ((* block h3 -*))section((* endblock h3 -*)) |
|
223 | ((* block h3 -*))section((* endblock h3 -*)) | |
224 | ((*- elif cell.level == 4 -*)) |
|
224 | ((*- elif cell.level == 4 -*)) | |
225 | ((* block h4 -*))subsection((* endblock h4 -*)) |
|
225 | ((* block h4 -*))subsection((* endblock h4 -*)) | |
226 | ((*- elif cell.level == 5 -*)) |
|
226 | ((*- elif cell.level == 5 -*)) | |
227 | ((* block h5 -*))subsubsection((* endblock h5 -*)) |
|
227 | ((* block h5 -*))subsubsection((* endblock h5 -*)) | |
228 | ((*- elif cell.level == 6 -*)) |
|
228 | ((*- elif cell.level == 6 -*)) | |
229 | ((* block h6 -*))paragraph((* endblock h6 -*)) |
|
229 | ((* block h6 -*))paragraph((* endblock h6 -*)) | |
230 |
|
230 | |||
231 | ((= It's important to make sure that underscores (which tend to be common |
|
231 | ((= It's important to make sure that underscores (which tend to be common | |
232 | in IPYNB file titles) do not make their way into latex. Sometimes this |
|
232 | in IPYNB file titles) do not make their way into latex. Sometimes this | |
233 | causes latex to barf. =)) |
|
233 | causes latex to barf. =)) | |
234 | ((*- endif -*)) |
|
234 | ((*- endif -*)) | |
235 | {((( cell.source | replace('\n', ' ') | citation2latex | markdown2latex )))} |
|
235 | {((( cell.source | replace('\n', ' ') | citation2latex | markdown2latex )))} | |
236 | ((*- endblock headingcell *)) |
|
236 | ((*- endblock headingcell *)) | |
237 |
|
237 | |||
238 | %============================================================================== |
|
238 | %============================================================================== | |
239 | % Markdown |
|
239 | % Markdown | |
240 | % |
|
240 | % | |
241 | % Purpose: Convert markdown to latex. Here markdown2latex is explicitly |
|
241 | % Purpose: Convert markdown to latex. Here markdown2latex is explicitly | |
242 | % called since we know we want latex output. |
|
242 | % called since we know we want latex output. | |
243 | %============================================================================== |
|
243 | %============================================================================== | |
244 | ((*- block markdowncell scoped-*)) |
|
244 | ((*- block markdowncell scoped-*)) | |
245 | ((( cell.source | citation2latex | markdown2latex ))) |
|
245 | ((( cell.source | citation2latex | markdown2latex ))) | |
246 | ((*- endblock markdowncell -*)) |
|
246 | ((*- endblock markdowncell -*)) | |
247 |
|
247 | |||
248 | %============================================================================== |
|
248 | %============================================================================== | |
249 | % Rawcell |
|
249 | % Rawcell | |
250 | % |
|
250 | % | |
251 | % Purpose: Raw text cells allow the user to manually inject document code that |
|
251 | % Purpose: Raw text cells allow the user to manually inject document code that | |
252 | % will not get touched by the templating system. |
|
252 | % will not get touched by the templating system. | |
253 | %============================================================================== |
|
253 | %============================================================================== | |
254 | ((*- block rawcell *)) |
|
254 | ((*- block rawcell *)) | |
255 | ((( cell.source | wrap_text(wrap_size) ))) |
|
255 | ((( cell.source | wrap_text(wrap_size) ))) | |
256 | ((* endblock rawcell -*)) |
|
256 | ((* endblock rawcell -*)) | |
257 |
|
257 | |||
258 | %============================================================================== |
|
258 | %============================================================================== | |
259 | % Unknowncell |
|
259 | % Unknowncell | |
260 | % |
|
260 | % | |
261 | % Purpose: This is the catch anything unhandled. To display this data, we |
|
261 | % Purpose: This is the catch anything unhandled. To display this data, we | |
262 | % remove all possible latex conflicts and wrap the characters so they |
|
262 | % remove all possible latex conflicts and wrap the characters so they | |
263 | % can't flow off of the page. |
|
263 | % can't flow off of the page. | |
264 | %============================================================================== |
|
264 | %============================================================================== | |
265 | ((* block unknowncell scoped*)) |
|
265 | ((* block unknowncell scoped*)) | |
266 | % Unsupported cell type, no formatting |
|
266 | % Unsupported cell type, no formatting | |
267 | ((( cell.source | wrap_text | escape_latex ))) |
|
267 | ((( cell.source | wrap_text | escape_latex ))) | |
268 | ((* endblock unknowncell *)) |
|
268 | ((* endblock unknowncell *)) | |
269 |
|
269 | |||
270 | %============================================================================== |
|
270 | %============================================================================== | |
271 | % Input |
|
271 | % Input | |
272 | %============================================================================== |
|
272 | %============================================================================== | |
273 | ((* block input *)) |
|
273 | ((* block input *)) | |
274 |
|
274 | |||
275 | % Make sure that atleast 4 lines are below the HR |
|
275 | % Make sure that atleast 4 lines are below the HR | |
276 | \needspace{((( min_header_lines )))\baselineskip} |
|
276 | \needspace{((( min_header_lines )))\baselineskip} | |
277 |
|
277 | |||
278 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
278 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |
279 |
|
279 | |||
280 | % Add a horizantal break, along with break title. |
|
280 | % Add a horizantal break, along with break title. | |
281 | \vspace{10pt} |
|
281 | \vspace{10pt} | |
282 | {\scriptsize Input}\\* |
|
282 | {\scriptsize Input}\\* | |
283 | \rule[10pt]{\linewidth}{0.5pt} |
|
283 | \rule[10pt]{\linewidth}{0.5pt} | |
284 | \vspace{-25pt} |
|
284 | \vspace{-25pt} | |
285 |
|
285 | |||
286 | % Add contents below. |
|
286 | % Add contents below. | |
287 |
((( cell |
|
287 | ((( cell | highlight2latex ))) | |
288 |
|
288 | |||
289 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
289 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
290 | \vspace{6pt} |
|
290 | \vspace{6pt} | |
291 | ((( write_prompt("In", cell.prompt_number, "nbframe-in-prompt") ))) |
|
291 | ((( write_prompt("In", cell.prompt_number, "nbframe-in-prompt") ))) | |
292 | \vspace{-2.65\baselineskip} |
|
292 | \vspace{-2.65\baselineskip} | |
293 | \begin{ColorVerbatim} |
|
293 | \begin{ColorVerbatim} | |
294 | \vspace{-0.7\baselineskip} |
|
294 | \vspace{-0.7\baselineskip} | |
295 |
((( cell |
|
295 | ((( cell | highlight2latex ))) | |
296 | ((* if cell.input == None or cell.input == '' *)) |
|
296 | ((* if cell.input == None or cell.input == '' *)) | |
297 | \vspace{0.3\baselineskip} |
|
297 | \vspace{0.3\baselineskip} | |
298 | ((* else *)) |
|
298 | ((* else *)) | |
299 | \vspace{-0.2\baselineskip} |
|
299 | \vspace{-0.2\baselineskip} | |
300 | ((* endif *)) |
|
300 | ((* endif *)) | |
301 | \end{ColorVerbatim} |
|
301 | \end{ColorVerbatim} | |
302 | ((* endif *)) |
|
302 | ((* endif *)) | |
303 | ((* endblock input *)) |
|
303 | ((* endblock input *)) | |
304 |
|
304 | |||
305 | %============================================================================== |
|
305 | %============================================================================== | |
306 | % Output_Group |
|
306 | % Output_Group | |
307 | % |
|
307 | % | |
308 | % Purpose: Make sure that only one header bar only attaches to the output |
|
308 | % Purpose: Make sure that only one header bar only attaches to the output | |
309 | % once. By keeping track of when an input group is started |
|
309 | % once. By keeping track of when an input group is started | |
310 | %============================================================================== |
|
310 | %============================================================================== | |
311 | ((* block output_group *)) |
|
311 | ((* block output_group *)) | |
312 | ((* if cell.outputs.__len__() > 0 *)) |
|
312 | ((* if cell.outputs.__len__() > 0 *)) | |
313 |
|
313 | |||
314 | % If the first block is an image, minipage the image. Else |
|
314 | % If the first block is an image, minipage the image. Else | |
315 | % request a certain amount of space for the input text. |
|
315 | % request a certain amount of space for the input text. | |
316 | ((( iff_figure(cell.outputs[0], "\\begin{minipage}{1.0\\textwidth}", "\\needspace{" ~ min_header_lines ~ "\\baselineskip}") ))) |
|
316 | ((( iff_figure(cell.outputs[0], "\\begin{minipage}{1.0\\textwidth}", "\\needspace{" ~ min_header_lines ~ "\\baselineskip}") ))) | |
317 |
|
317 | |||
318 | ((* if resources.sphinx.outputstyle == 'simple' *)) |
|
318 | ((* if resources.sphinx.outputstyle == 'simple' *)) | |
319 |
|
319 | |||
320 | % Add a horizantal break, along with break title. |
|
320 | % Add a horizantal break, along with break title. | |
321 | \vspace{10pt} |
|
321 | \vspace{10pt} | |
322 | {\scriptsize Output}\\* |
|
322 | {\scriptsize Output}\\* | |
323 | \rule[10pt]{\linewidth}{0.5pt} |
|
323 | \rule[10pt]{\linewidth}{0.5pt} | |
324 | \vspace{-20pt} |
|
324 | \vspace{-20pt} | |
325 |
|
325 | |||
326 | % Add the contents of the first block. |
|
326 | % Add the contents of the first block. | |
327 | ((( render_output(cell.outputs[0]) ))) |
|
327 | ((( render_output(cell.outputs[0]) ))) | |
328 |
|
328 | |||
329 | % Close the minipage. |
|
329 | % Close the minipage. | |
330 | ((( iff_figure(cell.outputs[0], "\\end{minipage}", "") ))) |
|
330 | ((( iff_figure(cell.outputs[0], "\\end{minipage}", "") ))) | |
331 |
|
331 | |||
332 | % Add remainer of the document contents below. |
|
332 | % Add remainer of the document contents below. | |
333 | ((* for output in cell.outputs[1:] *)) |
|
333 | ((* for output in cell.outputs[1:] *)) | |
334 | ((( render_output(output, cell.prompt_number) ))) |
|
334 | ((( render_output(output, cell.prompt_number) ))) | |
335 | ((* endfor *)) |
|
335 | ((* endfor *)) | |
336 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) |
|
336 | ((* elif resources.sphinx.outputstyle == 'notebook' *)) | |
337 |
|
337 | |||
338 | % Add document contents. |
|
338 | % Add document contents. | |
339 | ((* for output in cell.outputs *)) |
|
339 | ((* for output in cell.outputs *)) | |
340 | ((( render_output(output, cell.prompt_number) ))) |
|
340 | ((( render_output(output, cell.prompt_number) ))) | |
341 | ((* endfor *)) |
|
341 | ((* endfor *)) | |
342 | ((* endif *)) |
|
342 | ((* endif *)) | |
343 | ((* endif *)) |
|
343 | ((* endif *)) | |
344 | ((* endblock *)) |
|
344 | ((* endblock *)) | |
345 |
|
345 | |||
346 | %============================================================================== |
|
346 | %============================================================================== | |
347 | % Additional formating |
|
347 | % Additional formating | |
348 | %============================================================================== |
|
348 | %============================================================================== | |
349 | ((* block data_text *)) |
|
349 | ((* block data_text *)) | |
350 | ((( custom_verbatim(output.text) | ansi2latex ))) |
|
350 | ((( custom_verbatim(output.text) | ansi2latex ))) | |
351 | ((* endblock *)) |
|
351 | ((* endblock *)) | |
352 |
|
352 | |||
353 | ((* block traceback_line *)) |
|
353 | ((* block traceback_line *)) | |
354 | ((( conditionally_center_output( line | indent| strip_ansi ) ))) |
|
354 | ((( conditionally_center_output( line | indent| strip_ansi ) ))) | |
355 | ((* endblock traceback_line *)) |
|
355 | ((* endblock traceback_line *)) | |
356 |
|
356 | |||
357 | %============================================================================== |
|
357 | %============================================================================== | |
358 | % Supported image formats |
|
358 | % Supported image formats | |
359 | %============================================================================== |
|
359 | %============================================================================== | |
360 | ((*- block data_png -*)) |
|
360 | ((*- block data_png -*)) | |
361 | ((( conditionally_center_output(insert_graphics(output.png_filename | posix_path)) ))) |
|
361 | ((( conditionally_center_output(insert_graphics(output.png_filename | posix_path)) ))) | |
362 | ((*- endblock -*)) |
|
362 | ((*- endblock -*)) | |
363 |
|
363 | |||
364 | ((*- block data_jpg -*)) |
|
364 | ((*- block data_jpg -*)) | |
365 | ((( conditionally_center_output(insert_graphics(output.jpeg_filename | posix_path)) ))) |
|
365 | ((( conditionally_center_output(insert_graphics(output.jpeg_filename | posix_path)) ))) | |
366 | ((*- endblock -*)) |
|
366 | ((*- endblock -*)) | |
367 |
|
367 | |||
368 | ((*- block data_svg -*)) |
|
368 | ((*- block data_svg -*)) | |
369 | ((( conditionally_center_output(insert_graphics(output.svg_filename | posix_path)) ))) |
|
369 | ((( conditionally_center_output(insert_graphics(output.svg_filename | posix_path)) ))) | |
370 | ((*- endblock -*)) |
|
370 | ((*- endblock -*)) | |
371 |
|
371 | |||
372 | ((*- block data_pdf -*)) |
|
372 | ((*- block data_pdf -*)) | |
373 | ((( conditionally_center_output(insert_graphics(output.pdf_filename | posix_path)) ))) |
|
373 | ((( conditionally_center_output(insert_graphics(output.pdf_filename | posix_path)) ))) | |
374 | ((*- endblock -*)) |
|
374 | ((*- endblock -*)) | |
375 |
|
375 | |||
376 | ((*- block data_latex *)) |
|
376 | ((*- block data_latex *)) | |
377 | ((* if resources.sphinx.centeroutput *)) |
|
377 | ((* if resources.sphinx.centeroutput *)) | |
378 | \begin{center} |
|
378 | \begin{center} | |
379 | ((* endif -*)) |
|
379 | ((* endif -*)) | |
380 | ((( output.latex | strip_math_space ))) |
|
380 | ((( output.latex | strip_math_space ))) | |
381 | ((*- if resources.sphinx.centeroutput *)) |
|
381 | ((*- if resources.sphinx.centeroutput *)) | |
382 | \end{center} |
|
382 | \end{center} | |
383 | ((* endif -*)) |
|
383 | ((* endif -*)) | |
384 | ((*- endblock -*)) |
|
384 | ((*- endblock -*)) | |
385 |
|
385 | |||
386 | %============================================================================== |
|
386 | %============================================================================== | |
387 | % Support Macros |
|
387 | % Support Macros | |
388 | %============================================================================== |
|
388 | %============================================================================== | |
389 |
|
389 | |||
390 | % Name: write_prompt |
|
390 | % Name: write_prompt | |
391 | % Purpose: Renders an output/input prompt for notebook style pdfs |
|
391 | % Purpose: Renders an output/input prompt for notebook style pdfs | |
392 | ((* macro write_prompt(prompt, number, color) -*)) |
|
392 | ((* macro write_prompt(prompt, number, color) -*)) | |
393 | \makebox[0.1\linewidth]{\smaller\hfill\tt\color{((( color )))}((( prompt )))\hspace{4pt}{[}((( number ))){]}:\hspace{4pt}}\\* |
|
393 | \makebox[0.1\linewidth]{\smaller\hfill\tt\color{((( color )))}((( prompt )))\hspace{4pt}{[}((( number ))){]}:\hspace{4pt}}\\* | |
394 | ((*- endmacro *)) |
|
394 | ((*- endmacro *)) | |
395 |
|
395 | |||
396 | % Name: render_output |
|
396 | % Name: render_output | |
397 | % Purpose: Renders an output block appropriately. |
|
397 | % Purpose: Renders an output block appropriately. | |
398 | ((* macro render_output(output, prompt_number) -*)) |
|
398 | ((* macro render_output(output, prompt_number) -*)) | |
399 | ((*- if output.output_type == 'pyerr' -*)) |
|
399 | ((*- if output.output_type == 'pyerr' -*)) | |
400 | ((*- block pyerr scoped *)) |
|
400 | ((*- block pyerr scoped *)) | |
401 | ((( custom_verbatim(super()) ))) |
|
401 | ((( custom_verbatim(super()) ))) | |
402 | ((* endblock pyerr -*)) |
|
402 | ((* endblock pyerr -*)) | |
403 | ((*- else -*)) |
|
403 | ((*- else -*)) | |
404 |
|
404 | |||
405 | ((* if resources.sphinx.outputstyle == 'notebook' *)) |
|
405 | ((* if resources.sphinx.outputstyle == 'notebook' *)) | |
406 | ((*- if output.output_type == 'pyout' -*)) |
|
406 | ((*- if output.output_type == 'pyout' -*)) | |
407 | ((( write_prompt("Out", prompt_number, "nbframe-out-prompt") ))) |
|
407 | ((( write_prompt("Out", prompt_number, "nbframe-out-prompt") ))) | |
408 | \vspace{-2.55\baselineskip} |
|
408 | \vspace{-2.55\baselineskip} | |
409 | ((*- endif -*)) |
|
409 | ((*- endif -*)) | |
410 |
|
410 | |||
411 | \begin{InvisibleVerbatim} |
|
411 | \begin{InvisibleVerbatim} | |
412 | \vspace{-0.5\baselineskip} |
|
412 | \vspace{-0.5\baselineskip} | |
413 | ((*- endif -*)) |
|
413 | ((*- endif -*)) | |
414 |
|
414 | |||
415 | ((*- block display_data scoped -*)) |
|
415 | ((*- block display_data scoped -*)) | |
416 | ((( super() ))) |
|
416 | ((( super() ))) | |
417 | ((*- endblock display_data -*)) |
|
417 | ((*- endblock display_data -*)) | |
418 |
|
418 | |||
419 | ((* if resources.sphinx.outputstyle == 'notebook' *)) |
|
419 | ((* if resources.sphinx.outputstyle == 'notebook' *)) | |
420 | \end{InvisibleVerbatim} |
|
420 | \end{InvisibleVerbatim} | |
421 | ((*- endif -*)) |
|
421 | ((*- endif -*)) | |
422 | ((*- endif -*)) |
|
422 | ((*- endif -*)) | |
423 | ((*- endmacro *)) |
|
423 | ((*- endmacro *)) | |
424 |
|
424 | |||
425 | % Name: iff_figure |
|
425 | % Name: iff_figure | |
426 | % Purpose: If the output block provided is a figure type, the 'true_content' |
|
426 | % Purpose: If the output block provided is a figure type, the 'true_content' | |
427 | % parameter will be returned. Else, the 'false_content'. |
|
427 | % parameter will be returned. Else, the 'false_content'. | |
428 | ((* macro iff_figure(output, true_content, false_content) -*)) |
|
428 | ((* macro iff_figure(output, true_content, false_content) -*)) | |
429 | ((*- set is_figure = false -*)) |
|
429 | ((*- set is_figure = false -*)) | |
430 | ((*- for type in output | filter_data_type -*)) |
|
430 | ((*- for type in output | filter_data_type -*)) | |
431 | ((*- if type in ['pdf', 'svg', 'png', 'jpeg','html']*)) |
|
431 | ((*- if type in ['pdf', 'svg', 'png', 'jpeg','html']*)) | |
432 | ((*- set is_figure = true -*)) |
|
432 | ((*- set is_figure = true -*)) | |
433 | ((*- endif -*)) |
|
433 | ((*- endif -*)) | |
434 | ((*- endfor -*)) |
|
434 | ((*- endfor -*)) | |
435 |
|
435 | |||
436 | ((* if is_figure -*)) |
|
436 | ((* if is_figure -*)) | |
437 | ((( true_content ))) |
|
437 | ((( true_content ))) | |
438 | ((*- else -*)) |
|
438 | ((*- else -*)) | |
439 | ((( false_content ))) |
|
439 | ((( false_content ))) | |
440 | ((*- endif *)) |
|
440 | ((*- endif *)) | |
441 | ((*- endmacro *)) |
|
441 | ((*- endmacro *)) | |
442 |
|
442 | |||
443 | % Name: custom_verbatim |
|
443 | % Name: custom_verbatim | |
444 | % Purpose: This macro creates a verbatim style block that fits the existing |
|
444 | % Purpose: This macro creates a verbatim style block that fits the existing | |
445 | % sphinx style more readily than standard verbatim blocks. |
|
445 | % sphinx style more readily than standard verbatim blocks. | |
446 | ((* macro custom_verbatim(text) -*)) |
|
446 | ((* macro custom_verbatim(text) -*)) | |
447 | \begin{alltt} |
|
447 | \begin{alltt} | |
448 | ((*- if resources.sphinx.centeroutput *))\begin{center} ((* endif -*)) |
|
448 | ((*- if resources.sphinx.centeroutput *))\begin{center} ((* endif -*)) | |
449 | ((( text | wrap_text(wrap_size) | escape_latex ))) |
|
449 | ((( text | wrap_text(wrap_size) | escape_latex ))) | |
450 | ((*- if resources.sphinx.centeroutput *))\end{center}((* endif -*)) |
|
450 | ((*- if resources.sphinx.centeroutput *))\end{center}((* endif -*)) | |
451 | \end{alltt} |
|
451 | \end{alltt} | |
452 | ((*- endmacro *)) |
|
452 | ((*- endmacro *)) | |
453 |
|
453 | |||
454 | % Name: conditionally_center_output |
|
454 | % Name: conditionally_center_output | |
455 | % Purpose: This macro centers the output if the output centering is enabled. |
|
455 | % Purpose: This macro centers the output if the output centering is enabled. | |
456 | ((* macro conditionally_center_output(text) -*)) |
|
456 | ((* macro conditionally_center_output(text) -*)) | |
457 | ((* if resources.sphinx.centeroutput *)) |
|
457 | ((* if resources.sphinx.centeroutput *)) | |
458 | {\centering |
|
458 | {\centering | |
459 | ((* endif *)) |
|
459 | ((* endif *)) | |
460 | ((( text ))) |
|
460 | ((( text ))) | |
461 | ((* if resources.sphinx.centeroutput *))} |
|
461 | ((* if resources.sphinx.centeroutput *))} | |
462 | ((* endif *)) |
|
462 | ((* endif *)) | |
463 | ((*- endmacro *)) |
|
463 | ((*- endmacro *)) | |
464 |
|
464 | |||
465 | % Name: insert_graphics |
|
465 | % Name: insert_graphics | |
466 | % Purpose: This macro will insert an image in the latex document given a path. |
|
466 | % Purpose: This macro will insert an image in the latex document given a path. | |
467 | ((* macro insert_graphics(path) -*)) |
|
467 | ((* macro insert_graphics(path) -*)) | |
468 | \begin{center} |
|
468 | \begin{center} | |
469 | \includegraphics[max size={\textwidth}{\textheight}]{((( path )))} |
|
469 | \includegraphics[max size={\textwidth}{\textheight}]{((( path )))} | |
470 | \par |
|
470 | \par | |
471 | \end{center} |
|
471 | \end{center} | |
472 | ((*- endmacro *)) |
|
472 | ((*- endmacro *)) |
General Comments 0
You need to be logged in to leave comments.
Login now