diff options
| author | aarne <aarne@chalmers.se> | 2014-10-17 06:40:06 +0000 |
|---|---|---|
| committer | aarne <aarne@chalmers.se> | 2014-10-17 06:40:06 +0000 |
| commit | 42cfacbf867184ae5bc495a247fa6fbeb8c90639 (patch) | |
| tree | 83efec0bf214dd54db3d5da9e98645e6845227d9 | |
| parent | 6375bacc73c5ba2f0dd660fab18b590506027822 (diff) | |
lexer for latex code: don't separate backslash from the macro name that it marks
| -rw-r--r-- | src/runtime/haskell/PGF/Lexing.hs | 12 |
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 |
