diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-14 17:59:06 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-14 17:59:06 +0000 |
commit | 8ce4b2fb62ffa6d9893f9fa54d5fd0016bcdfc5b (patch) | |
tree | 86bbe945dd0ceb7f32a69e04a6abeca270e42331 /src | |
parent | ab74f9742251db883890cadce1bf2b039c8321d9 (diff) | |
download | pandoc-8ce4b2fb62ffa6d9893f9fa54d5fd0016bcdfc5b.tar.gz |
Simplified special character escaping code in LaTeX writer.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@705 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 230e75414..c16a80fac 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -77,21 +77,27 @@ latexHeader options (Meta title authors date) = -- escape things as needed for LaTeX -escapeBrackets = backslashEscape "{}" -escapeSpecial = backslashEscape "$%&~_#" - -escapeBackslash = substitute "\\" "\\textbackslash{}" -fixBackslash = substitute "\\textbackslash\\{\\}" "\\textbackslash{}" -escapeHat = substitute "^" "\\^{}" -escapeBar = substitute "|" "\\textbar{}" -escapeLt = substitute "<" "\\textless{}" -escapeGt = substitute ">" "\\textgreater{}" +escapeCharForLaTeX :: Char -> String +escapeCharForLaTeX ch = + case ch of + '\\' -> "\\textbackslash{}" + '{' -> "\\{" + '}' -> "\\}" + '$' -> "\\$" + '%' -> "\\%" + '&' -> "\\&" + '~' -> "\\~" + '_' -> "\\_" + '#' -> "\\#" + '^' -> "\\^{}" + '|' -> "\\textbar{}" + '<' -> "\\textless{}" + '>' -> "\\textgreater{}" + x -> [x] -- | Escape string for LaTeX stringToLaTeX :: String -> String -stringToLaTeX = escapeGt . escapeLt . escapeBar . escapeHat . - escapeSpecial . fixBackslash . escapeBrackets . - escapeBackslash +stringToLaTeX = concatMap escapeCharForLaTeX -- | Remove all code elements from list of inline elements -- (because it's illegal to have a \\verb inside a command argument) |