Show More
@@ -66,6 +66,7 b' default_filters = {' | |||
|
66 | 66 | 'rm_ansi': nbconvert.filters.ansi.remove_ansi, |
|
67 | 67 | 'rm_dollars': nbconvert.filters.strings.strip_dollars, |
|
68 | 68 | 'rm_fake': nbconvert.filters.strings.rm_fake, |
|
69 | 'rm_consoleesc': nbconvert.filters.strings.rm_consoleesc, | |
|
69 | 70 | 'rm_math_space': nbconvert.filters.latex.rm_math_space, |
|
70 | 71 | 'wrap': nbconvert.filters.strings.wrap |
|
71 | 72 | } |
@@ -21,6 +21,7 b' import re' | |||
|
21 | 21 | |
|
22 | 22 | #Latex substitutions for escaping latex. |
|
23 | 23 | LATEX_SUBS = ( |
|
24 | (re.compile('\033\[[0-9;]+m'),''), # handle console escapes | |
|
24 | 25 | (re.compile(r'\\'), r'\\textbackslash'), |
|
25 | 26 | (re.compile(r'([{}_#%&$])'), r'\\\1'), |
|
26 | 27 | (re.compile(r'~'), r'\~{}'), |
@@ -14,6 +14,7 b' templates.' | |||
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | import re | |
|
17 | 18 | |
|
18 | 19 | # Our own imports |
|
19 | 20 | import textwrap |
@@ -54,6 +55,18 b' def strip_dollars(text):' | |||
|
54 | 55 | return text.strip('$') |
|
55 | 56 | |
|
56 | 57 | |
|
58 | def rm_consoleesc(text): | |
|
59 | """ | |
|
60 | Remove console escapes from text | |
|
61 | ||
|
62 | Parameters | |
|
63 | ---------- | |
|
64 | text : str | |
|
65 | Text to remove '/files/' from | |
|
66 | """ | |
|
67 | r= re.compile("\033\[[0-9;]+m") | |
|
68 | return r.sub('', text) | |
|
69 | ||
|
57 | 70 | def rm_fake(text): |
|
58 | 71 | """ |
|
59 | 72 | Remove all occurrences of '/files/' from text |
@@ -71,22 +71,38 b' it introduces a new line' | |||
|
71 | 71 | ((* endblock *)) |
|
72 | 72 | |
|
73 | 73 | ((* block data_latex -*)) |
|
74 | \begin{equation*} | |
|
74 | ((*- if output.latex.startswith('$'): -*)) \begin{equation*} | |
|
75 | 75 | ((( output.latex | rm_dollars))) |
|
76 | 76 | \end{equation*} |
|
77 | ((*- else -*)) ((( output.latex ))) ((*- endif *)) | |
|
77 | 78 | ((* endblock *)) |
|
78 | 79 | |
|
79 | 80 | ((* block stream *)) |
|
80 | 81 | \begin{verbatim} |
|
81 | ((( output.text))) | |
|
82 | ((( output.text | rm_consoleesc))) | |
|
82 | 83 | \end{verbatim} |
|
83 | 84 | ((* endblock stream *)) |
|
84 | 85 | |
|
85 | 86 | ((* block markdowncell scoped *))((( cell.source | markdown2latex ))) |
|
86 | 87 | ((* endblock markdowncell *)) |
|
87 | 88 | |
|
88 | ((* block headingcell scoped *)) | |
|
89 | \section{((( cell.source | markdown2latex)))} | |
|
89 | ((* block headingcell scoped -*)) | |
|
90 | \ | |
|
91 | ((*- if cell.level == 1 -*)) | |
|
92 | ((* block h1 -*))section((* endblock h1 -*)) | |
|
93 | ((*- elif cell.level == 2 -*)) | |
|
94 | ((* block h2 -*))subsection((* endblock h2 -*)) | |
|
95 | ((*- elif cell.level == 3 -*)) | |
|
96 | ((* block h3 -*))subsubsection((* endblock h3 -*)) | |
|
97 | ((*- elif cell.level == 4 -*)) | |
|
98 | ((* block h4 -*))paragraph((* endblock h4 -*)) | |
|
99 | ((*- elif cell.level == 5 -*)) | |
|
100 | ((* block h5 -*))subparagraph((* endblock h5 -*)) | |
|
101 | ((*- elif cell.level == 6 -*)) | |
|
102 | ((* block h6 -*))subparagraph((* endblock h6 -*)) | |
|
103 | ((= 6th level not available in standard latex =)) | |
|
104 | ||
|
105 | ((*- endif -*)){((( cell.source | markdown2latex )))} | |
|
90 | 106 | ((* endblock headingcell *)) |
|
91 | 107 | |
|
92 | 108 | ((* block rawcell scoped *)) |
General Comments 0
You need to be logged in to leave comments.
Login now