git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Don't use ligatures in escaping inline code.
3f1937fJohn MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+15−9
@@ -172,13 +172,19 @@ elementToLaTeX opts (Sec level _ (id',classes,_) title' elements) = do
172 innerContents <- mapM (elementToLaTeX opts) elements
172 innerContents <- mapM (elementToLaTeX opts) elements
173 return $ vsep (header' : innerContents)
173 return $ vsep (header' : innerContents)
174
174
175+data StringContext = TextString
176+ | URLString
177+ | CodeString
178+ deriving (Eq)
179+
175-- escape things as needed for LaTeX
180-- escape things as needed for LaTeX
176−stringToLaTeX :: Bool -> String -> State WriterState String
181+stringToLaTeX :: StringContext -> String -> State WriterState String
177stringToLaTeX _ [] = return ""
182stringToLaTeX _ [] = return ""
178−stringToLaTeX isUrl (x:xs) = do
183+stringToLaTeX ctx (x:xs) = do
179 opts <- gets stOptions
184 opts <- gets stOptions
180− rest <- stringToLaTeX isUrl xs
185+ rest <- stringToLaTeX ctx xs
181− let ligatures = writerTeXLigatures opts
186+ let ligatures = writerTeXLigatures opts && not (ctx == CodeString)
187+ let isUrl = ctx == URLString
182 when (x == '€') $
188 when (x == '€') $
183 modify $ \st -> st{ stUsesEuro = True }
189 modify $ \st -> st{ stUsesEuro = True }
184 return $
190 return $
@@ -589,7 +595,7 @@ inlineToLaTeX (Code (_,classes,_) str) = do
589 Just h -> modify (\st -> st{ stHighlighting = True }) >>
595 Just h -> modify (\st -> st{ stHighlighting = True }) >>
590 return (text h)
596 return (text h)
591 rawCode = liftM (text . (\s -> "\\texttt{" ++ s ++ "}"))
597 rawCode = liftM (text . (\s -> "\\texttt{" ++ s ++ "}"))
592− $ stringToLaTeX False str
598+ $ stringToLaTeX CodeString str
593inlineToLaTeX (Quoted qt lst) = do
599inlineToLaTeX (Quoted qt lst) = do
594 contents <- inlineListToLaTeX lst
600 contents <- inlineListToLaTeX lst
595 csquotes <- liftM stCsquotes get
601 csquotes <- liftM stCsquotes get
@@ -613,7 +619,7 @@ inlineToLaTeX (Quoted qt lst) = do
613 if writerTeXLigatures opts
619 if writerTeXLigatures opts
614 then char '`' <> inner <> char '\''
620 then char '`' <> inner <> char '\''
615 else char '\x2018' <> inner <> char '\x2019'
621 else char '\x2018' <> inner <> char '\x2019'
616−inlineToLaTeX (Str str) = liftM text $ stringToLaTeX False str
622+inlineToLaTeX (Str str) = liftM text $ stringToLaTeX TextString str
617inlineToLaTeX (Math InlineMath str) =
623inlineToLaTeX (Math InlineMath str) =
618 return $ char '$' <> text str <> char '$'
624 return $ char '$' <> text str <> char '$'
619inlineToLaTeX (Math DisplayMath str) =
625inlineToLaTeX (Math DisplayMath str) =
@@ -625,16 +631,16 @@ inlineToLaTeX (LineBreak) = return "\\\\"
625inlineToLaTeX Space = return space
631inlineToLaTeX Space = return space
626inlineToLaTeX (Link txt ('#':ident, _)) = do
632inlineToLaTeX (Link txt ('#':ident, _)) = do
627 contents <- inlineListToLaTeX txt
633 contents <- inlineListToLaTeX txt
628− ident' <- stringToLaTeX True ident
634+ ident' <- stringToLaTeX URLString ident
629 return $ text "\\hyperref" <> brackets (text ident') <> braces contents
635 return $ text "\\hyperref" <> brackets (text ident') <> braces contents
630inlineToLaTeX (Link txt (src, _)) =
636inlineToLaTeX (Link txt (src, _)) =
631 case txt of
637 case txt of
632 [Str x] | x == src -> -- autolink
638 [Str x] | x == src -> -- autolink
633 do modify $ \s -> s{ stUrl = True }
639 do modify $ \s -> s{ stUrl = True }
634− src' <- stringToLaTeX True x
640+ src' <- stringToLaTeX URLString x
635 return $ text $ "\\url{" ++ src' ++ "}"
641 return $ text $ "\\url{" ++ src' ++ "}"
636 _ -> do contents <- inlineListToLaTeX txt
642 _ -> do contents <- inlineListToLaTeX txt
637− src' <- stringToLaTeX True src
643+ src' <- stringToLaTeX URLString src
638 return $ text ("\\href{" ++ src' ++ "}{") <>
644 return $ text ("\\href{" ++ src' ++ "}{") <>
639 contents <> char '}'
645 contents <> char '}'
640inlineToLaTeX (Image _ (source, _)) = do
646inlineToLaTeX (Image _ (source, _)) = do