texmath 0.6.0.3 → 0.6.0.4
raw patch · 6 files changed
+52/−28 lines, 6 filesdep ~parsec
Dependency ranges changed: parsec
Files
- Text/TeXMath/Macros.hs +12/−9
- Text/TeXMath/Parser.hs +16/−6
- tests/macros.omml +12/−4
- tests/macros.tex +6/−5
- tests/macros.xhtml +4/−2
- texmath.cabal +2/−2
Text/TeXMath/Macros.hs view
@@ -90,22 +90,23 @@ Left _ -> s -- just return original on error where tok = try $ do skipComment- choice [ escaped "\\"- , choice (map macroParser ms)+ choice [ choice (map macroParser ms) , ctrlseq , count 1 anyChar ]- ctrlseq = do- char '\\'- res <- many1 letter <|> count 1 anyChar- return $ '\\' : res +ctrlseq :: GenParser Char st String+ctrlseq = do+ char '\\'+ res <- many1 letter <|> count 1 anyChar+ return $ '\\' : res+ newcommand :: GenParser Char st Macro newcommand = try $ do char '\\' optional $ try $ string "re" string "newcommand" pSkipSpaceComments- name <- inbraces+ name <- inbraces <|> ctrlseq guard (take 1 name == "\\") let name' = drop 1 name pSkipSpaceComments@@ -118,7 +119,7 @@ Just _ -> numargs - 1 Nothing -> numargs pSkipSpaceComments- body <- inbraces+ body <- inbraces <|> ctrlseq let defn = "\\newcommand{" ++ name ++ "}" ++ (if numargs > 0 then ("[" ++ show numargs ++ "]") else "") ++ case optarg of { Nothing -> ""; Just x -> "[" ++ x ++ "]"} ++@@ -128,10 +129,12 @@ string name' when (all isLetter name') $ notFollowedBy letter+ pSkipSpaceComments opt <- case optarg of Nothing -> return Nothing Just _ -> liftM (`mplus` optarg) optArg- args <- count numargs' inbraces+ args <- count numargs' (pSkipSpaceComments >>+ (inbraces <|> ctrlseq <|> count 1 anyChar)) let args' = case opt of Just x -> x : args Nothing -> args
Text/TeXMath/Parser.hs view
@@ -23,7 +23,7 @@ where import Control.Monad-import Data.Char (isAlphaNum, isDigit, isAscii)+import Data.Char (isDigit, isAscii) import qualified Data.Map as M import Text.ParserCombinators.Parsec import qualified Text.ParserCombinators.Parsec.Token as P@@ -82,6 +82,7 @@ expr :: TP Exp expr = do+ optional (try $ symbol "\\displaystyle") a <- expr1 limits <- limitsIndicator subSup limits a <|> superOrSubscripted limits a <|> return a@@ -161,7 +162,7 @@ return '\n' arrayLine :: TP ArrayLine-arrayLine = notFollowedBy (try $ char '\\' >> symbol "end" >> return '\n') >>+arrayLine = notFollowedBy (try $ symbol "\\end" >> return '\n') >> sepBy1 (many (notFollowedBy endLine >> expr)) (symbol "&") arrayAlignments :: TP [Alignment]@@ -175,13 +176,12 @@ environment :: TP Exp environment = try $ do- char '\\'- symbol "begin"+ symbol "\\begin" name <- char '{' *> manyTill anyChar (char '}') spaces let name' = filter (/='*') name case M.lookup name' environments of- Just env -> env <* spaces <* char '\\' <* symbol "end"+ Just env -> env <* spaces <* symbol "\\end" <* braces (string name) <* spaces Nothing -> mzero @@ -288,7 +288,17 @@ escaped :: TP Exp escaped = lexeme $ try $ char '\\' >>- liftM (ESymbol Ord . (:[])) (satisfy $ not . isAlphaNum)+ liftM (ESymbol Ord . (:[])) (satisfy isEscapable)+ where isEscapable '{' = True+ isEscapable '}' = True+ isEscapable '$' = True+ isEscapable '%' = True+ isEscapable '&' = True+ isEscapable '_' = True+ isEscapable '#' = True+ isEscapable '^' = True -- actually only if followed by {}+ isEscapable ' ' = True+ isEscapable _ = False unicode :: TP Exp unicode = lexeme $ liftM (ESymbol Ord . (:[])) $ satisfy (not . isAscii)
tests/macros.omml view
@@ -6,18 +6,26 @@ <m:oMath> <m:r> <m:rPr />- <m:t>2</m:t>+ <m:t>25</m:t> </m:r> <m:r> <m:rPr />- <m:t>5</m:t>+ <m:t>y</m:t> </m:r> <m:r> <m:rPr />- <m:t>y</m:t>+ <m:t>+</m:t> </m:r> <m:r> <m:rPr />+ <m:t>3</m:t>+ </m:r>+ <m:r>+ <m:rPr />+ <m:t>x</m:t>+ </m:r>+ <m:r>+ <m:rPr /> <m:t>+</m:t> </m:r> <m:r>@@ -34,7 +42,7 @@ </m:r> <m:r> <m:rPr />- <m:t>3</m:t>+ <m:t>α</m:t> </m:r> </m:oMath> </m:oMathPara>
tests/macros.tex view
@@ -1,5 +1,5 @@ \newcommand{\abc}{5}-\newcommand{\def}[2][x]{%+\newcommand{\xyz}[2][x]{% #1 + #2% } \renewcommand{%@@ -8,11 +8,12 @@ \theta% } % comment-\newcommand{\a}{\b{2}}-\renewcommand{\phi}{\a}+\newcommand{\aaa}{\b{2}}+\renewcommand{\phi}{\aaa} \newcommand{\b}[1]{#1} \phi \abc-\def[y]{3}-\def{3}+\xyz[y] {3}+\xyz 3+\xyz \alpha
tests/macros.xhtml view
@@ -6,14 +6,16 @@ <body> <math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> <mrow>- <mn>2</mn>- <mn>5</mn>+ <mn>25</mn> <mi>y</mi> <mo>+</mo> <mn>3</mn> <mi>x</mi> <mo>+</mo> <mn>3</mn>+ <mi>x</mi>+ <mo>+</mo>+ <mi>α</mi> </mrow> </math> </body>
texmath.cabal view
@@ -1,5 +1,5 @@ Name: texmath-Version: 0.6.0.3+Version: 0.6.0.4 Cabal-Version: >= 1.6 Build-type: Custom Synopsis: Conversion of LaTeX math formulas to MathML or OMML.@@ -74,7 +74,7 @@ default: False Library- Build-depends: xml, parsec >= 2, containers+ Build-depends: xml, parsec >= 3, containers if impl(ghc >= 6.10) Build-depends: base >= 4 && < 5, syb else