mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-26 02:06:32 +00:00
Simplified special character escaping code in LaTeX writer.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@705 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user