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.
This commit is contained in:
John MacFarlane
2013-01-12 10:21:19 -08:00
parent f2aa5fd661
commit 70e308f2f9
2 changed files with 15 additions and 2 deletions
+11 -2
View File
@@ -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
+4
View File
@@ -32,4 +32,8 @@ tests = [ testGroup "code blocks"
[ "in footnotes" =: note (para "hi" <> codeBlock "hi") =?>
"\\footnote{hi\n\n\\begin{Verbatim}\nhi\n\\end{Verbatim}\n}"
]
, testGroup "math"
[ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
"$\\sigma\\vert _{\\{x\\}}$"
]
]