git.iko.soy/typeable/pandoc
on master help sign in
Simplified special character escaping code in LaTeX writer.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@705 788f1e2b-df1e-0410-8736-df70ead52e1b

commit8ce4b2fb62ffa6d9893f9fa54d5fd0016bcdfc5b authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 14 Jul 2007, 17:59 (19 years ago) parentab74f97
1 file changed+18−12
src/Text/Pandoc/Writers/LaTeX.hs+18−12
src/Text/Pandoc/Writers/LaTeX.hs+18−12
@@ -77,21 +77,27 @@ latexHeader options (Meta title authors date) =
7777
7878-- escape things as needed for LaTeX
7979
80−escapeBrackets = backslashEscape "{}"
81−escapeSpecial = backslashEscape "$%&~_#"
82−
83−escapeBackslash = substitute "\\" "\\textbackslash{}"
84−fixBackslash = substitute "\\textbackslash\\{\\}" "\\textbackslash{}"
85−escapeHat = substitute "^" "\\^{}"
86−escapeBar = substitute "|" "\\textbar{}"
87−escapeLt = substitute "<" "\\textless{}"
88−escapeGt = substitute ">" "\\textgreater{}"
80+escapeCharForLaTeX :: Char -> String
81+escapeCharForLaTeX ch =
82+ case ch of
83+ '\\' -> "\\textbackslash{}"
84+ '{' -> "\\{"
85+ '}' -> "\\}"
86+ '$' -> "\\$"
87+ '%' -> "\\%"
88+ '&' -> "\\&"
89+ '~' -> "\\~"
90+ '_' -> "\\_"
91+ '#' -> "\\#"
92+ '^' -> "\\^{}"
93+ '|' -> "\\textbar{}"
94+ '<' -> "\\textless{}"
95+ '>' -> "\\textgreater{}"
96+ x -> [x]
8997
9098-- | Escape string for LaTeX
9199stringToLaTeX :: String -> String
92−stringToLaTeX = escapeGt . escapeLt . escapeBar . escapeHat .
93− escapeSpecial . fixBackslash . escapeBrackets .
94− escapeBackslash
100+stringToLaTeX = concatMap escapeCharForLaTeX
95101
96102-- | Remove all code elements from list of inline elements
97103-- (because it's illegal to have a \\verb inside a command argument)