summaryrefslogtreecommitdiff
path: root/src/runtime/haskell
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/haskell')
-rw-r--r--src/runtime/haskell/PGF/Lexing.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/runtime/haskell/PGF/Lexing.hs b/src/runtime/haskell/PGF/Lexing.hs
index 782757b03..d5286a478 100644
--- a/src/runtime/haskell/PGF/Lexing.hs
+++ b/src/runtime/haskell/PGF/Lexing.hs
@@ -54,6 +54,16 @@ unlexCode s = case s of
_ -> []
+-- | LaTeX lexer in the math mode: \ should not be separated from the next word
+
+lexLatexCode :: String -> [String]
+lexLatexCode = restoreBackslash . lexCode where --- quick hack: postprocess Haskell's lex
+ restoreBackslash ws = case ws of
+ "\\":"\\":ww -> "\\\\":restoreBackslash ww
+ "\\":w:ww -> ("\\" ++ w) : restoreBackslash ww
+ w:ww -> w:restoreBackslash ww
+ _ -> ws
+
-- * Mixed lexing
-- | LaTeX style lexer, with "math" environment using Code between $...$
@@ -64,7 +74,7 @@ lexMixed = concat . alternate False where
(t,[]) -> lex env t : []
(t,c:m) -> lex env t : [[c]] : alternate (not env) m
_ -> []
- lex env = if env then lexCode else lexText
+ lex env = if env then lexLatexCode else lexText
unlexMixed :: [String] -> String
unlexMixed = capitInit . concat . alternate False where