From 3f1937f78e656f54c65fa4b4f4cedd6a126fb349 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 4 Jul 2013 15:06:23 -0700 Subject: LaTeX writer: Don't use ligatures in escaping inline code. --- src/Text/Pandoc/Writers/LaTeX.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 76ec31d58..2b4a608a7 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -172,13 +172,19 @@ elementToLaTeX opts (Sec level _ (id',classes,_) title' elements) = do innerContents <- mapM (elementToLaTeX opts) elements return $ vsep (header' : innerContents) +data StringContext = TextString + | URLString + | CodeString + deriving (Eq) + -- escape things as needed for LaTeX -stringToLaTeX :: Bool -> String -> State WriterState String +stringToLaTeX :: StringContext -> String -> State WriterState String stringToLaTeX _ [] = return "" -stringToLaTeX isUrl (x:xs) = do +stringToLaTeX ctx (x:xs) = do opts <- gets stOptions - rest <- stringToLaTeX isUrl xs - let ligatures = writerTeXLigatures opts + rest <- stringToLaTeX ctx xs + let ligatures = writerTeXLigatures opts && not (ctx == CodeString) + let isUrl = ctx == URLString when (x == '€') $ modify $ \st -> st{ stUsesEuro = True } return $ @@ -589,7 +595,7 @@ inlineToLaTeX (Code (_,classes,_) str) = do Just h -> modify (\st -> st{ stHighlighting = True }) >> return (text h) rawCode = liftM (text . (\s -> "\\texttt{" ++ s ++ "}")) - $ stringToLaTeX False str + $ stringToLaTeX CodeString str inlineToLaTeX (Quoted qt lst) = do contents <- inlineListToLaTeX lst csquotes <- liftM stCsquotes get @@ -613,7 +619,7 @@ inlineToLaTeX (Quoted qt lst) = do if writerTeXLigatures opts then char '`' <> inner <> char '\'' else char '\x2018' <> inner <> char '\x2019' -inlineToLaTeX (Str str) = liftM text $ stringToLaTeX False str +inlineToLaTeX (Str str) = liftM text $ stringToLaTeX TextString str inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$' inlineToLaTeX (Math DisplayMath str) = @@ -625,16 +631,16 @@ inlineToLaTeX (LineBreak) = return "\\\\" inlineToLaTeX Space = return space inlineToLaTeX (Link txt ('#':ident, _)) = do contents <- inlineListToLaTeX txt - ident' <- stringToLaTeX True ident + ident' <- stringToLaTeX URLString ident return $ text "\\hyperref" <> brackets (text ident') <> braces contents inlineToLaTeX (Link txt (src, _)) = case txt of [Str x] | x == src -> -- autolink do modify $ \s -> s{ stUrl = True } - src' <- stringToLaTeX True x + src' <- stringToLaTeX URLString x return $ text $ "\\url{" ++ src' ++ "}" _ -> do contents <- inlineListToLaTeX txt - src' <- stringToLaTeX True src + src' <- stringToLaTeX URLString src return $ text ("\\href{" ++ src' ++ "}{") <> contents <> char '}' inlineToLaTeX (Image _ (source, _)) = do -- cgit v1.2.3