File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,27 @@ type TP = Parser
52
52
-- The parser
53
53
54
54
expr1 :: TP Exp
55
- expr1 = choice
55
+ expr1 = do
56
+ e <- expr2
57
+ -- check for primes and add them as a subscript
58
+ -- in TeX ' is shorthand for ^{\prime}
59
+ primes <- many (char ' \' ' )
60
+ let getPrimes cs = case cs of
61
+ " " -> " "
62
+ " '" -> " \x2032 "
63
+ " ''" -> " \x2033 "
64
+ " '''" -> " \x2034 "
65
+ " ''''" -> " \x2057 "
66
+ _ -> " \x2057 " ++ getPrimes (drop 4 cs)
67
+ ignorable
68
+ case getPrimes primes of
69
+ " " -> return e
70
+ cs -> return $ case e of
71
+ ESub b sub -> ESubsup b sub (ESymbol Ord (T. pack cs))
72
+ _ -> ESuper e (ESymbol Ord (T. pack cs))
73
+
74
+ expr2 :: TP Exp
75
+ expr2 = choice
56
76
[ inbraces
57
77
, variable
58
78
, number
@@ -62,7 +82,7 @@ expr1 = choice
62
82
, enclosure
63
83
, hyperref
64
84
, command
65
- ] <* ignorable
85
+ ]
66
86
67
87
-- | Parse a formula, returning a list of 'Exp'.
68
88
readTeX :: Text -> Either Text [Exp ]
@@ -233,7 +253,7 @@ operatorname = do
233
253
ctrlseq " operatorname"
234
254
-- these are slightly different but we won't worry about that here...
235
255
convertible <- (char ' *' >> spaces >> return True ) <|> return False
236
- tok' <- texToken
256
+ tok' <- texSymbol <|> braces (manyExp expr2) <|> texChar
237
257
tok'' <- (EMathOperator <$> (expToOperatorName tok'))
238
258
<|> return (EStyled TextNormal [tok'])
239
259
return (tok'', convertible)
Original file line number Diff line number Diff line change @@ -3,15 +3,13 @@ u'' + p(x)u' + q(x)u=f(x),\quad x>a
3
3
4
4
5
5
>>> native
6
- [ EIdentifier "u"
7
- , ESymbol Ord "\8243"
6
+ [ ESuper (EIdentifier "u") (ESymbol Ord "\8243")
8
7
, ESymbol Bin "+"
9
8
, EIdentifier "p"
10
9
, ESymbol Open "("
11
10
, EIdentifier "x"
12
11
, ESymbol Close ")"
13
- , EIdentifier "u"
14
- , ESymbol Ord "\8242"
12
+ , ESuper (EIdentifier "u") (ESymbol Ord "\8242")
15
13
, ESymbol Bin "+"
16
14
, EIdentifier "q"
17
15
, ESymbol Open "("
You can’t perform that action at this time.
0 commit comments