##// END OF EJS Templates
Created filters namespace
Jonathan Frederic -
Show More
@@ -0,0 +1,72 b''
1 """Latex transformer.
2
3 Module that allows latex output notebooks to be conditioned before
4 they are converted.
5 """
6 #-----------------------------------------------------------------------------
7 # Copyright (c) 2013, the IPython Development Team.
8 #
9 # Distributed under the terms of the Modified BSD License.
10 #
11 # The full license is in the file COPYING.txt, distributed with this software.
12 #-----------------------------------------------------------------------------
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17 from __future__ import print_function
18
19 #-----------------------------------------------------------------------------
20 # Functions
21 #-----------------------------------------------------------------------------
22 def rm_math_space(text):
23 """
24 Remove the space between latex math commands and enclosing $ symbols.
25 """
26
27 # First, scan through the markdown looking for $. If
28 # a $ symbol is found, without a preceding \, assume
29 # it is the start of a math block. UNLESS that $ is
30 # not followed by another within two math_lines.
31 math_regions = []
32 math_lines = 0
33 within_math = False
34 math_start_index = 0
35 ptext = ''
36 last_character = ""
37 skip = False
38 for index, char in enumerate(text):
39
40 #Make sure the character isn't preceeded by a backslash
41 if (char == "$" and last_character != "\\"):
42
43 # Close the math region if this is an ending $
44 if within_math:
45 within_math = False
46 skip = True
47 ptext = ptext+'$'+text[math_start_index+1:index].strip()+'$'
48 math_regions.append([math_start_index, index+1])
49 else:
50
51 # Start a new math region
52 within_math = True
53 math_start_index = index
54 math_lines = 0
55
56 # If we are in a math region, count the number of lines parsed.
57 # Cancel the math region if we find two line breaks!
58 elif char == "\n":
59 if within_math:
60 math_lines += 1
61 if math_lines > 1:
62 within_math = False
63 ptext = ptext+text[math_start_index:index]
64
65 # Remember the last character so we can easily watch
66 # for backslashes
67 last_character = char
68 if not within_math and not skip:
69 ptext = ptext+char
70 if skip:
71 skip = False
72 return ptext
@@ -344,7 +344,7 b' class Exporter(Configurable):'
344 c.ExtractFigureTransformer.display_data_priority=['latex', 'svg', 'png', 'jpg', 'jpeg']
344 c.ExtractFigureTransformer.display_data_priority=['latex', 'svg', 'png', 'jpg', 'jpeg']
345 c.ExtractFigureTransformer.extra_ext_map={'svg':'pdf'}
345 c.ExtractFigureTransformer.extra_ext_map={'svg':'pdf'}
346 c.ExtractFigureTransformer.enabled=True
346 c.ExtractFigureTransformer.enabled=True
347
347
348 # Enable latex transformers (make markdown2latex work with math $.)
348 # Enable latex transformers (make markdown2latex work with math $.)
349 c.LatexTransformer.enabled=True
349 c.LatexTransformer.enabled=True
350 c.SphinxTransformer.enabled = True
350 c.SphinxTransformer.enabled = True
@@ -352,7 +352,7 b' class Exporter(Configurable):'
352 elif export_format == 'markdown':
352 elif export_format == 'markdown':
353 c.NbconvertApp.fileext='md'
353 c.NbconvertApp.fileext='md'
354 c.ExtractFigureTransformer.enabled=True
354 c.ExtractFigureTransformer.enabled=True
355
355
356 elif export_format == 'python':
356 elif export_format == 'python':
357 c.NbconvertApp.fileext='py'
357 c.NbconvertApp.fileext='py'
358
358
1 NO CONTENT: file renamed from utils/datatypefilter.py to filters/datatypefilter.py
NO CONTENT: file renamed from utils/datatypefilter.py to filters/datatypefilter.py
1 NO CONTENT: file renamed from utils/markdown.py to filters/markdown.py
NO CONTENT: file renamed from utils/markdown.py to filters/markdown.py
1 NO CONTENT: file renamed from utils/strings.py to filters/strings.py
NO CONTENT: file renamed from utils/strings.py to filters/strings.py
@@ -40,58 +40,3 b' class LatexTransformer(ActivatableTransformer):'
40 if hasattr(cell, "source") and cell.cell_type == "markdown":
40 if hasattr(cell, "source") and cell.cell_type == "markdown":
41 cell.source = rm_math_space(cell.source)
41 cell.source = rm_math_space(cell.source)
42 return cell, other
42 return cell, other
43
44 #-----------------------------------------------------------------------------
45 # Functions
46 #-----------------------------------------------------------------------------
47 def rm_math_space(text):
48 """
49 Remove the space between latex math commands and enclosing $ symbols.
50 """
51
52 # First, scan through the markdown looking for $. If
53 # a $ symbol is found, without a preceding \, assume
54 # it is the start of a math block. UNLESS that $ is
55 # not followed by another within two math_lines.
56 math_regions = []
57 math_lines = 0
58 within_math = False
59 math_start_index = 0
60 ptext = ''
61 last_character = ""
62 skip = False
63 for index, char in enumerate(text):
64
65 #Make sure the character isn't preceeded by a backslash
66 if (char == "$" and last_character != "\\"):
67
68 # Close the math region if this is an ending $
69 if within_math:
70 within_math = False
71 skip = True
72 ptext = ptext+'$'+text[math_start_index+1:index].strip()+'$'
73 math_regions.append([math_start_index, index+1])
74 else:
75
76 # Start a new math region
77 within_math = True
78 math_start_index = index
79 math_lines = 0
80
81 # If we are in a math region, count the number of lines parsed.
82 # Cancel the math region if we find two line breaks!
83 elif char == "\n":
84 if within_math:
85 math_lines += 1
86 if math_lines > 1:
87 within_math = False
88 ptext = ptext+text[math_start_index:index]
89
90 # Remember the last character so we can easily watch
91 # for backslashes
92 last_character = char
93 if not within_math and not skip:
94 ptext = ptext+char
95 if skip:
96 skip = False
97 return ptext
General Comments 0
You need to be logged in to leave comments. Login now