git.iko.soy/typeable/pandoc
on master help sign in
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.

commit70e308f2f9673cdf13bb42be4ad9b68265c02df1 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 12 Jan 2013, 10:21 (14 years ago) parentf2aa5fd
2 files changed+15−2
src/Text/Pandoc/Writers/LaTeX.hs+11−2 tests/Tests/Writers/LaTeX.hs+4
src/Text/Pandoc/Writers/LaTeX.hs+11−2
@@ -214,6 +214,13 @@ stringToLaTeX isUrl (x:xs) = do
214214 '\x2013' | ligatures -> "--" ++ rest
215215 _ -> x : rest
216216
217+-- This is needed because | in math mode interacts badly with
218+-- highlighting-kate, which redefines | as a short verb command.
219+escapeMath :: String -> String
220+escapeMath ('|':xs) = "\\vert " ++ escapeMath xs
221+escapeMath (x:xs) = x : escapeMath xs
222+escapeMath [] = ""
223+
217224-- | Puts contents into LaTeX command.
218225inCmd :: String -> Doc -> Doc
219226inCmd cmd contents = char '\\' <> text cmd <> braces contents
@@ -603,8 +610,10 @@ inlineToLaTeX (Quoted qt lst) = do
603610 then char '`' <> inner <> char '\''
604611 else char '\x2018' <> inner <> char '\x2019'
605612inlineToLaTeX (Str str) = liftM text $ stringToLaTeX False str
606−inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$'
607−inlineToLaTeX (Math DisplayMath str) = return $ "\\[" <> text str <> "\\]"
613+inlineToLaTeX (Math InlineMath str) =
614+ return $ char '$' <> text (escapeMath str) <> char '$'
615+inlineToLaTeX (Math DisplayMath str) =
616+ return $ "\\[" <> text (escapeMath str) <> "\\]"
608617inlineToLaTeX (RawInline "latex" str) = return $ text str
609618inlineToLaTeX (RawInline "tex" str) = return $ text str
610619inlineToLaTeX (RawInline _ _) = return empty
tests/Tests/Writers/LaTeX.hs+4
@@ -32,4 +32,8 @@ tests = [ testGroup "code blocks"
3232 [ "in footnotes" =: note (para "hi" <> codeBlock "hi") =?>
3333 "\\footnote{hi\n\n\\begin{Verbatim}\nhi\n\\end{Verbatim}\n}"
3434 ]
35+ , testGroup "math"
36+ [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
37+ "$\\sigma\\vert _{\\{x\\}}$"
38+ ]
3539 ]