From 66ac842456b209d42e079dd6d631703f79d2e3b0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 6 Feb 2012 13:48:59 -0800 Subject: 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. --- src/Text/Pandoc/Writers/LaTeX.hs | 52 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'src/Text/Pandoc') 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 -- cgit v1.2.3