Permalink
Browse files

Began super/sub parsing for MathML; added \limits for LaTeX.

  • Loading branch information...
1 parent 93f6774 commit 4a4a645fb94006854ef8dff25fc87d71e5007ab9 @jgm committed Mar 2, 2011
Showing with 26 additions and 32 deletions.
  1. +0 −32 TODO
  2. +1 −0 Text/HeX/Math/LaTeX.hs
  3. +25 −0 Text/HeX/Math/MathML.hs
View
32 TODO
@@ -1,36 +1,4 @@
_ sup/sub/limits:
- do in mathml module (obviously in latex it's easy)
- * limits command: set a special variable 'limits',
- parse an item, and unset it.
- the sup/sub parser will check for this variable and behave accordingly.
- * sub/sup parser:
- check to make sure special variable 'subsup' is not set
- if it is, exit; if not, set 'subsup'
- parse an item
- try parsing sub/super.
- render result
- unset 'subsup'
- NOTE: this won't work, because while subsup is set we won't get
- subscripts + superscripts, even in nested contents.
-
- of course, could just do the inefficient thing: first, a parser
- that parses something + limits/supscript; if that fails, go to
- regular parser. so everything gets parsed twice. but, besides
- inefficiency, this would have the problem that the supr/sup/limits
- parser would have to be the first parser applied -- limiting
- user's ability to add new math parsers.
-
- maybe it could work like this. have math unset the special
- variable. then define math' as like math, but not unsetting
- it. so math' won't keep the special variable set when we recurse
- in.
-
- another approach? wrap the whole math parser. parse something.
- then, check for a following sub/super, and modify output accordingly.
- (as in texmath) how to do the wrapping? could be in def of 'math',
- though this requires gumming up Tex.Hex with detailed math stuff.
- what about in addParser Math?
-
_ mathML:
_ arrays
_ superscript, subscript, limit
View
@@ -9,6 +9,7 @@ import Text.HeX.Math (defaultsFor)
defaults :: HeX ()
defaults = do
defaultsFor writer
+ latexCommand1 "limits"
register [Math] "textrm" $ (ctl "textrm" +++) <$> inline
register [Math] "text" $ (ctl "text" +++) <$> inline
register [Math] "textit" $ (ctl "textit" +++) <$> inline
View
@@ -11,6 +11,8 @@ defaults :: HeX ()
defaults = do
defaultsFor writer
addParser [Math] enclosure
+ updateState $ \st -> st{ hexParsers =
+ M.adjust (\x -> [subsup x]) Math $ hexParsers st }
register [Math] "textrm" $ asText "normal" <$> inline
register [Math] "text" $ asText "normal" <$> inline
register [Math] "mathrm" $ asText "normal" <$> math
@@ -462,6 +464,29 @@ scalers = M.fromList
, ("Bigl", "1.6")
]
+-- 'wraps' a parser in a check for super/subscript/limits
+subsup :: [HeX Doc] -> HeX Doc
+subsup parsers = do
+ limits <- limitsIndicator
+ sub <- option Nothing subscript
+ sup <- option Nothing superscript
+ res <- choice parsers
+ case (sub, sup) of
+ (Nothing, Nothing) -> return res
+ (Just x, Nothing) -> fail "unimplemented"
+ (Nothing, Just y) -> fail "unimplemented"
+ (Just x, Just y) -> fail "unimplemented"
+
+limitsIndicator :: HeX Bool
+limitsIndicator = return False -- TODO
+
+subscript :: HeX (Maybe Doc)
+subscript = fail "unimplemented"
+
+superscript :: HeX (Maybe Doc)
+superscript = fail "unimplemented"
+
+
{-
-- limits <- limitsIndicator
-- subSup limits a <|> superOrSubscripted limits a <|> return a

0 comments on commit 4a4a645

Please sign in to comment.