From 7ec778d74756c7a7481e29762a03128e79ec6070 Mon Sep 17 00:00:00 2001 From: aarne Date: Fri, 17 Oct 2014 06:40:06 +0000 Subject: [PATCH] lexer for latex code: don't separate backslash from the macro name that it marks --- src/runtime/haskell/PGF/Lexing.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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