@@ -170,26 +170,38 @@ elementToLaTeX opts (Sec level _ id' title' elements) = do
171-- escape things as needed for LaTeX
171-- escape things as needed for LaTeX
172stringToLaTeX :: Bool -> String -> String
172stringToLaTeX :: Bool -> String -> String
173−stringToLaTeX isUrl = escapeStringUsing latexEscapes
173+stringToLaTeX _ [] = ""
174− where latexEscapes = backslashEscapes "{}$%&_#" ++
174+stringToLaTeX isUrl (x:xs) =
176+ '{' -> "\\{" ++ rest
177+ '}' -> "\\}" ++ rest
178+ '$' -> "\\$" ++ rest
179+ '%' -> "\\%" ++ rest
180+ '&' -> "\\&" ++ rest
181+ '_' -> "\\_" ++ rest
182+ '#' -> "\\#" ++ rest
183+ '-' -> case xs of -- prevent adjacent hyphens from forming ligatures
184+ ('-':_) -> "-{}" ++ rest
175− [ ('~', "\\ensuremath{\\sim}") | not isUrl ] ++
186+ '~' | not isUrl -> "\\ensuremath{\\sim}"
176− [ ('^', "\\^{}")
187+ '^' -> "\\^{}" ++ rest
177− , ('\\', "\\textbackslash{}")
188+ '\\' -> "\\textbackslash{}" ++ rest
178− , ('€', "\\euro{}")
189+ '€' -> "\\euro{}" ++ rest
179− , ('|', "\\textbar{}")
190+ '|' -> "\\textbar{}" ++ rest
180− , ('<', "\\textless{}")
191+ '<' -> "\\textless{}" ++ rest
181− , ('>', "\\textgreater{}")
192+ '>' -> "\\textgreater{}" ++ rest
182− , ('[', "{[}") -- to avoid interpretation as
193+ '[' -> "{[}" ++ rest -- to avoid interpretation as
183− , (']', "{]}") -- optional arguments
194+ ']' -> "{]}" ++ rest -- optional arguments
184− , ('\160', "~")
195+ '\160' -> "~" ++ rest
185− , ('\x2018', "`")
196+ '\x2018' -> "`" ++ rest
186− , ('\x2019', "'")
197+ '\x2019' -> "'" ++ rest
187− , ('\x201C', "``")
198+ '\x201C' -> "``" ++ rest
188− , ('\x201D', "''")
199+ '\x201D' -> "''" ++ rest
189− , ('\x2026', "\\ldots{}")
200+ '\x2026' -> "\\ldots{}" ++ rest
190− , ('\x2014', "---")
201+ '\x2014' -> "---" ++ rest
191− , ('\x2013', "--")
202+ '\x2013' -> "--" ++ rest
204+ where rest = stringToLaTeX isUrl xs
194-- | Puts contents into LaTeX command.
206-- | Puts contents into LaTeX command.
195inCmd :: String -> Doc -> Doc
207inCmd :: String -> Doc -> Doc