@@ -172,13 +172,19 @@ elementToLaTeX opts (Sec level _ (id',classes,_) title' elements) = do
172172 innerContents <- mapM (elementToLaTeX opts) elements
173173 return $ vsep (header' : innerContents)
174174
175+data StringContext = TextString
176+ | URLString
177+ | CodeString
178+ deriving (Eq)
179+
175180-- escape things as needed for LaTeX
176−stringToLaTeX :: Bool -> String -> State WriterState String
181+stringToLaTeX :: StringContext -> String -> State WriterState String
177182stringToLaTeX _ [] = return ""
178−stringToLaTeX isUrl (x:xs) = do
183+stringToLaTeX ctx (x:xs) = do
179184 opts <- gets stOptions
180− rest <- stringToLaTeX isUrl xs
181− let ligatures = writerTeXLigatures opts
185+ rest <- stringToLaTeX ctx xs
186+ let ligatures = writerTeXLigatures opts && not (ctx == CodeString)
187+ let isUrl = ctx == URLString
182188 when (x == '€') $
183189 modify $ \st -> st{ stUsesEuro = True }
184190 return $
@@ -589,7 +595,7 @@ inlineToLaTeX (Code (_,classes,_) str) = do
589595 Just h -> modify (\st -> st{ stHighlighting = True }) >>
590596 return (text h)
591597 rawCode = liftM (text . (\s -> "\\texttt{" ++ s ++ "}"))
592− $ stringToLaTeX False str
598+ $ stringToLaTeX CodeString str
593599inlineToLaTeX (Quoted qt lst) = do
594600 contents <- inlineListToLaTeX lst
595601 csquotes <- liftM stCsquotes get
@@ -613,7 +619,7 @@ inlineToLaTeX (Quoted qt lst) = do
613619 if writerTeXLigatures opts
614620 then char '`' <> inner <> char '\''
615621 else char '\x2018' <> inner <> char '\x2019'
616−inlineToLaTeX (Str str) = liftM text $ stringToLaTeX False str
622+inlineToLaTeX (Str str) = liftM text $ stringToLaTeX TextString str
617623inlineToLaTeX (Math InlineMath str) =
618624 return $ char '$' <> text str <> char '$'
619625inlineToLaTeX (Math DisplayMath str) =
@@ -625,16 +631,16 @@ inlineToLaTeX (LineBreak) = return "\\\\"
625631inlineToLaTeX Space = return space
626632inlineToLaTeX (Link txt ('#':ident, _)) = do
627633 contents <- inlineListToLaTeX txt
628− ident' <- stringToLaTeX True ident
634+ ident' <- stringToLaTeX URLString ident
629635 return $ text "\\hyperref" <> brackets (text ident') <> braces contents
630636inlineToLaTeX (Link txt (src, _)) =
631637 case txt of
632638 [Str x] | x == src -> -- autolink
633639 do modify $ \s -> s{ stUrl = True }
634− src' <- stringToLaTeX True x
640+ src' <- stringToLaTeX URLString x
635641 return $ text $ "\\url{" ++ src' ++ "}"
636642 _ -> do contents <- inlineListToLaTeX txt
637− src' <- stringToLaTeX True src
643+ src' <- stringToLaTeX URLString src
638644 return $ text ("\\href{" ++ src' ++ "}{") <>
639645 contents <> char '}'
640646inlineToLaTeX (Image _ (source, _)) = do