Show More
@@ -37,6 +37,7 b' __all__ = [' | |||
|
37 | 37 | 'highlight2latex' |
|
38 | 38 | ] |
|
39 | 39 | |
|
40 | ||
|
40 | 41 | def highlight2html(source, language='ipython', metadata=None): |
|
41 | 42 | """ |
|
42 | 43 | Return a syntax-highlighted version of the input source as html output. |
@@ -44,30 +45,37 b" def highlight2html(source, language='ipython', metadata=None):" | |||
|
44 | 45 | Parameters |
|
45 | 46 | ---------- |
|
46 | 47 | source : str |
|
47 |
source of the cell to highlight |
|
|
48 | source of the cell to highlight | |
|
48 | 49 | language : str |
|
49 |
|
|
|
50 | language to highlight the syntax of | |
|
50 | 51 | metadata : NotebookNode cell metadata |
|
51 |
metadata of the cell to highlight |
|
|
52 | metadata of the cell to highlight | |
|
52 | 53 | """ |
|
53 | 54 | |
|
54 | 55 | return _pygment_highlight(source, HtmlFormatter(), language, metadata) |
|
55 | 56 | |
|
56 | 57 | |
|
57 | def highlight2latex(source, language='ipython', metadata=None): | |
|
58 | def highlight2latex(source, language='ipython', metadata=None, strip_verbatim=False): | |
|
58 | 59 | """ |
|
59 | 60 | Return a syntax-highlighted version of the input source as latex output. |
|
60 | 61 | |
|
61 | 62 | Parameters |
|
62 | 63 | ---------- |
|
63 | 64 | source : str |
|
64 |
source of the cell to highlight |
|
|
65 | source of the cell to highlight | |
|
65 | 66 | language : str |
|
66 |
|
|
|
67 | language to highlight the syntax of | |
|
67 | 68 | metadata : NotebookNode cell metadata |
|
68 |
metadata of the cell to highlight |
|
|
69 | metadata of the cell to highlight | |
|
70 | strip_verbatim : bool | |
|
71 | remove the Verbatim environment that pygments provides by default | |
|
69 | 72 | """ |
|
70 |
|
|
|
73 | latex = _pygment_highlight(source, LatexFormatter(), language, metadata) | |
|
74 | if strip_verbatim: | |
|
75 | latex = latex.replace(r'\begin{Verbatim}[commandchars=\\\{\}]' + '\n', '') | |
|
76 | return latex.replace('\n\\end{Verbatim}\n', '') | |
|
77 | else: | |
|
78 | return latex | |
|
71 | 79 | |
|
72 | 80 | |
|
73 | 81 | |
@@ -78,12 +86,12 b" def _pygment_highlight(source, output_formatter, language='ipython', metadata=No" | |||
|
78 | 86 | Parameters |
|
79 | 87 | ---------- |
|
80 | 88 | source : str |
|
81 |
source of the cell to highlight |
|
|
89 | source of the cell to highlight | |
|
82 | 90 | output_formatter : Pygments formatter |
|
83 | 91 | language : str |
|
84 |
|
|
|
92 | language to highlight the syntax of | |
|
85 | 93 | metadata : NotebookNode cell metadata |
|
86 |
metadata of the cell to highlight |
|
|
94 | metadata of the cell to highlight | |
|
87 | 95 | """ |
|
88 | 96 | |
|
89 | 97 | # If the cell uses a magic extension language, |
@@ -16,6 +16,6 b'' | |||
|
16 | 16 | |
|
17 | 17 | ((* block input scoped *)) |
|
18 | 18 | \begin{Verbatim}[commandchars=\\\{\}] |
|
19 | ((( cell.input | highlight2latex | replace('\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n', '') | replace('\n\\end{Verbatim}\n', '') | add_prompts ))) | |
|
19 | ((( cell.input | highlight2latex(strip_verbatim=True) | add_prompts ))) | |
|
20 | 20 | \end{Verbatim} |
|
21 | 21 | ((* endblock input *)) |
General Comments 0
You need to be logged in to leave comments.
Login now