aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-12 10:21:19 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-12 10:21:19 -0800
commit70e308f2f9673cdf13bb42be4ad9b68265c02df1 (patch)
tree8af81ce283121cc98b9aa8dd922d400d394c3091 /src/Text/Pandoc
parentf2aa5fd661cc74326ebc40f80c8854564e386b74 (diff)
downloadpandoc-70e308f2f9673cdf13bb42be4ad9b68265c02df1.tar.gz
Escape `|` as `\vert` in LaTeX math.
This avoids a clash with highlighting-kate's macros, which redefine | as a short verbatim delimiter. Thanks to Björn Peemöller for raising this issue.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index aede568b6..035a98170 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -214,6 +214,13 @@ stringToLaTeX isUrl (x:xs) = do
'\x2013' | ligatures -> "--" ++ rest
_ -> x : rest
+-- This is needed because | in math mode interacts badly with
+-- highlighting-kate, which redefines | as a short verb command.
+escapeMath :: String -> String
+escapeMath ('|':xs) = "\\vert " ++ escapeMath xs
+escapeMath (x:xs) = x : escapeMath xs
+escapeMath [] = ""
+
-- | Puts contents into LaTeX command.
inCmd :: String -> Doc -> Doc
inCmd cmd contents = char '\\' <> text cmd <> braces contents
@@ -603,8 +610,10 @@ inlineToLaTeX (Quoted qt lst) = do
then char '`' <> inner <> char '\''
else char '\x2018' <> inner <> char '\x2019'
inlineToLaTeX (Str str) = liftM text $ stringToLaTeX False str
-inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$'
-inlineToLaTeX (Math DisplayMath str) = return $ "\\[" <> text str <> "\\]"
+inlineToLaTeX (Math InlineMath str) =
+ return $ char '$' <> text (escapeMath str) <> char '$'
+inlineToLaTeX (Math DisplayMath str) =
+ return $ "\\[" <> text (escapeMath str) <> "\\]"
inlineToLaTeX (RawInline "latex" str) = return $ text str
inlineToLaTeX (RawInline "tex" str) = return $ text str
inlineToLaTeX (RawInline _ _) = return empty