Skip to content

Commit

Permalink
Added array environments to MathML.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Apr 3, 2011
1 parent 32b3035 commit b5e912b
Showing 1 changed file with 13 additions and 59 deletions.
72 changes: 13 additions & 59 deletions Text/HeX/Math/MathML.hs
Expand Up @@ -339,6 +339,11 @@ defaults = do
arrayEnv "Bmatrix" $ matrix '{' '}' arrayEnv "Bmatrix" $ matrix '{' '}'
arrayEnv "vmatrix" $ matrix '\x2223' '\x2223' arrayEnv "vmatrix" $ matrix '\x2223' '\x2223'
arrayEnv "Vmatrix" $ matrix '\x2225' '\x2225' arrayEnv "Vmatrix" $ matrix '\x2225' '\x2225'
arrayEnv "array" stdarray
arrayEnv "eqnarray" $ \_ -> stdarray [AlignRight, AlignCenter, AlignLeft]
arrayEnv "align" $ \_ -> stdarray [AlignRight, AlignLeft]
arrayEnv "cases" cases



writer :: MathWriter writer :: MathWriter
writer = MathWriter{ writer = MathWriter{
Expand Down Expand Up @@ -572,6 +577,14 @@ matrix :: Char -> Char -> [Alignment] -> [[Doc]] -> Doc
matrix opendelim closedelim aligns rows = matrix opendelim closedelim aligns rows =
mrow $ stretchy opendelim +++ arrayRows aligns rows +++ stretchy closedelim mrow $ stretchy opendelim +++ arrayRows aligns rows +++ stretchy closedelim


cases :: [Alignment] -> [[Doc]] -> Doc
cases aligns rows =
mrow $ stretchy '{' +++ arrayRows aligns rows

stdarray :: [Alignment] -> [[Doc]] -> Doc
stdarray aligns rows =
mrow $ arrayRows aligns rows

arrayRows :: [Alignment] -> [[Doc]] -> Doc arrayRows :: [Alignment] -> [[Doc]] -> Doc
arrayRows aligns = mconcat . map (arrayRow aligns) arrayRows aligns = mconcat . map (arrayRow aligns)


Expand All @@ -590,62 +603,3 @@ arrayCell align cell = inTags "mtd" align' cell
stretchy :: Char -> Doc stretchy :: Char -> Doc
stretchy c = inTags "mo" [("stretchy","true")] $ rawc c stretchy c = inTags "mo" [("stretchy","true")] $ rawc c




{-
endLine :: GenParser Char st Char
endLine = try $ do
symbol "\\\\"
optional inbrackets -- can contain e.g. [1.0in] for a line height, not yet supported
return '\n'
arrayLine :: GenParser Char st ArrayLine
arrayLine = notFollowedBy (try $ char '\\' >> symbol "end" >> return '\n') >>
sepBy1 (many (notFollowedBy endLine >> expr)) (symbol "&")
array :: GenParser Char st Exp
array = stdarray <|> eqnarray <|> align <|> cases <|> matrix
stdarray :: GenParser Char st Exp
stdarray = inEnvironment "array" $ do
aligns <- option [] arrayAlignments
liftM (EArray aligns) $ sepEndBy1 arrayLine endLine
eqnarray :: GenParser Char st Exp
eqnarray = inEnvironment "eqnarray" $
liftM (EArray [AlignRight, AlignCenter, AlignLeft]) $
sepEndBy1 arrayLine endLine
align :: GenParser Char st Exp
align = inEnvironment "align" $
liftM (EArray [AlignRight, AlignLeft]) $
sepEndBy1 arrayLine endLine
cases :: GenParser Char st Exp
cases = inEnvironment "cases" $ do
rs <- sepEndBy1 arrayLine endLine
return $ EGrouped [EStretchy (ESymbol Open "{"), EArray [] rs]
inEnvironment :: String
-> GenParser Char st Exp
-> GenParser Char st Exp
inEnvironment envType p = do
try $ do char '\\'
symbol "begin"
braces $ symbol envType >> optional (symbol "*")
result <- p
char '\\'
symbol "end"
braces $ symbol envType >> optional (symbol "*")
return result
-}

0 comments on commit b5e912b

Please sign in to comment.