aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-02-06 13:48:59 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-02-06 13:48:59 -0800
commit66ac842456b209d42e079dd6d631703f79d2e3b0 (patch)
tree9dcb89fb7145947fa07c4ace10f96eb13ff4951d /src
parent408f975e4706a7dfb441fc1f0c6f737f383a7fc4 (diff)
downloadpandoc-66ac842456b209d42e079dd6d631703f79d2e3b0.tar.gz
LaTeX writer: prevent adjacent hyphens from forming ligatures.
This is important primarily for things like `--option`. Em and En dashes will produce '---' and '--' in LaTeX, but hyphens should not otherwise combine into dashes.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index dec6d3118..e99b20c60 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -170,26 +170,38 @@ elementToLaTeX opts (Sec level _ id' title' elements) = do
-- escape things as needed for LaTeX
stringToLaTeX :: Bool -> String -> String
-stringToLaTeX isUrl = escapeStringUsing latexEscapes
- where latexEscapes = backslashEscapes "{}$%&_#" ++
- [ ('~', "\\ensuremath{\\sim}") | not isUrl ] ++
- [ ('^', "\\^{}")
- , ('\\', "\\textbackslash{}")
- , ('€', "\\euro{}")
- , ('|', "\\textbar{}")
- , ('<', "\\textless{}")
- , ('>', "\\textgreater{}")
- , ('[', "{[}") -- to avoid interpretation as
- , (']', "{]}") -- optional arguments
- , ('\160', "~")
- , ('\x2018', "`")
- , ('\x2019', "'")
- , ('\x201C', "``")
- , ('\x201D', "''")
- , ('\x2026', "\\ldots{}")
- , ('\x2014', "---")
- , ('\x2013', "--")
- ]
+stringToLaTeX _ [] = ""
+stringToLaTeX isUrl (x:xs) =
+ case x of
+ '{' -> "\\{" ++ rest
+ '}' -> "\\}" ++ rest
+ '$' -> "\\$" ++ rest
+ '%' -> "\\%" ++ rest
+ '&' -> "\\&" ++ rest
+ '_' -> "\\_" ++ rest
+ '#' -> "\\#" ++ rest
+ '-' -> case xs of -- prevent adjacent hyphens from forming ligatures
+ ('-':_) -> "-{}" ++ rest
+ _ -> '-' : rest
+ '~' | not isUrl -> "\\ensuremath{\\sim}"
+ '^' -> "\\^{}" ++ rest
+ '\\' -> "\\textbackslash{}" ++ rest
+ '€' -> "\\euro{}" ++ rest
+ '|' -> "\\textbar{}" ++ rest
+ '<' -> "\\textless{}" ++ rest
+ '>' -> "\\textgreater{}" ++ rest
+ '[' -> "{[}" ++ rest -- to avoid interpretation as
+ ']' -> "{]}" ++ rest -- optional arguments
+ '\160' -> "~" ++ rest
+ '\x2018' -> "`" ++ rest
+ '\x2019' -> "'" ++ rest
+ '\x201C' -> "``" ++ rest
+ '\x201D' -> "''" ++ rest
+ '\x2026' -> "\\ldots{}" ++ rest
+ '\x2014' -> "---" ++ rest
+ '\x2013' -> "--" ++ rest
+ _ -> x : rest
+ where rest = stringToLaTeX isUrl xs
-- | Puts contents into LaTeX command.
inCmd :: String -> Doc -> Doc