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