##// END OF EJS Templates
Revert "Escape latex fixes"...
Jonathan Frederic -
Show More
@@ -13,8 +13,7 b' Module of useful filters for processing Latex within Jinja latex templates.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16 import re
17 from ansi import strip_ansi
18
17
19 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
20 # Globals and constants
19 # Globals and constants
@@ -27,14 +26,12 b' LATEX_SUBS = {'
27 '%': r'\%',
26 '%': r'\%',
28 '$': r'\$',
27 '$': r'\$',
29 '#': r'\#',
28 '#': r'\#',
30 '_': r'\_',
29 '_': r'\letterunderscore{}',
31 '{': r'\{',
30 '{': r'\letteropenbrace{}',
32 '}': r'\}',
31 '}': r'\letterclosebrace{}',
33 '~': r'\textasciitilde{}',
32 '~': r'\lettertilde{}',
34 '^': r'\^{}',
33 '^': r'\letterhat{}',
35 '\\': r'\textbackslash{}',
34 '\\': r'\letterbackslash{}'}
36 '...': r'\ldots{}',
37 }
38
35
39
36
40 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
@@ -46,7 +43,7 b" __all__ = ['escape_latex',"
46
43
47 def escape_latex(text):
44 def escape_latex(text):
48 """
45 """
49 Remove ansi codes and escape characters that may conflict with latex.
46 Escape characters that may conflict with latex.
50
47
51 Parameters
48 Parameters
52 ----------
49 ----------
@@ -54,14 +51,7 b' def escape_latex(text):'
54 Text containing characters that may conflict with Latex
51 Text containing characters that may conflict with Latex
55 """
52 """
56
53
57 # Remove the ansi coloring from the text and then escape it. Escape single
54 return ''.join([LATEX_SUBS.get(c, c) for c in text])
58 # characters first and then multiple characters.
59 text = strip_ansi(text)
60 text = ''.join([LATEX_SUBS.get(c, c) for c in text])
61 for search, replace in LATEX_SUBS.items():
62 if len(search) > 1:
63 text = text.replace(search,replace)
64 return text
65
55
66
56
67 def strip_math_space(text):
57 def strip_math_space(text):
@@ -28,10 +28,9 b' class TestLatex(TestsBase):'
28 def test_escape_latex(self):
28 def test_escape_latex(self):
29 """escape_latex test"""
29 """escape_latex test"""
30 tests = [
30 tests = [
31 (r'How are \you doing today?', r'How are \textbackslash{}you doing today?'),
31 (r'How are \you doing today?', r'How are \letterbackslash{}you doing today?'),
32 (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslash{}escapechar=`\textbackslash{}A\textbackslash{}catcode`\textbackslash{}|=0 |string|foo'),
32 (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\letterbackslash{}escapechar=`\letterbackslash{}A\letterbackslash{}catcode`\letterbackslash{}|=0 |string|foo'),
33 (r'# $ % & ~ _ ^ \ { }', r'\# \$ \% \& \textasciitilde{} \_ \^{} \textbackslash{} \{ \}'),
33 (r'# $ % & ~ _ ^ \ { }', r'\# \$ \% \& \lettertilde{} \letterunderscore{} \letterhat{} \letterbackslash{} \letteropenbrace{} \letterclosebrace{}'),
34 (r"This SHOULD work... If not, I'm wrong.", "This SHOULD work\ldots{} If not, I'm wrong."),
35 ('','')]
34 ('','')]
36
35
37 for test in tests:
36 for test in tests:
General Comments 0
You need to be logged in to leave comments. Login now