Skip to content

Commit e7ada90

Browse files
committed
MathML writer: use mi for EMathOperator.
Also: insert the unicode 0x2061 "function application" character after a math operator, unless it's already there. Ensure that all 0x2061 characters are in mo rather than mi.
1 parent b4ba4eb commit e7ada90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+548
-398
lines changed

src/Text/TeXMath/Writers/MathML.hs

+26-13
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ makeText a s = case (leadingSp, trailingSp) of
112112
makeArray :: Maybe TextType -> [Alignment] -> [ArrayLine] -> Element
113113
makeArray tt as ls = unode "mtable" $
114114
map (unode "mtr" .
115-
zipWith (\a -> setAlignment a . unode "mtd". map (showExp tt)) as') ls
115+
zipWith (\a -> setAlignment a . unode "mtd". showExps tt) as') ls
116116
-- see #205 on the need for style attributes:
117117
where setAlignment AlignLeft =
118118
withAttribute "columnalign" "left" .
@@ -148,6 +148,17 @@ showExp' tt e =
148148
in withAttribute "accent" isaccent $ tunode "mo" x
149149
_ -> showExp tt e
150150

151+
showExps :: Maybe TextType -> [Exp] -> [Element]
152+
showExps tt = map (showExp tt) . insertFunctionApps
153+
154+
insertFunctionApps :: [Exp] -> [Exp]
155+
insertFunctionApps [] = []
156+
insertFunctionApps (e@EMathOperator{} : ESymbol _ "\x2061" : es) =
157+
e : ESymbol Pun "\x2061" : insertFunctionApps es
158+
insertFunctionApps (e@EMathOperator{} : es) =
159+
e : ESymbol Pun "\x2061" : insertFunctionApps es
160+
insertFunctionApps (e:es) = e : insertFunctionApps es
161+
151162
showExp :: Maybe TextType -> Exp -> Element
152163
showExp tt e =
153164
let toUnicodeMaybe :: TextType -> T.Text -> Maybe T.Text
@@ -173,30 +184,32 @@ showExp tt e =
173184
in case e of
174185
ENumber x -> vnode "mn" x
175186
EGrouped [x] -> showExp tt x
176-
EGrouped xs -> mrow $ map (showExp tt) xs
187+
EGrouped xs -> mrow $ showExps tt xs
177188
EDelimited start end xs -> mrow $
178189
[ makeStretchy FPrefix (vnode "mo" start) | not (T.null start) ] ++
179190
map (either (makeStretchy FInfix . vnode "mo") (showExp tt)) xs ++
180191
[ makeStretchy FPostfix (vnode "mo" end)
181192
| not (T.null end) ]
182193
EIdentifier x -> vnode "mi" x
183-
EMathOperator x -> vnode "mo" x
194+
EMathOperator x -> vnode "mi" x -- see #257
184195
ESymbol Open x -> makeFence FPrefix $ vnode "mo" x
185196
ESymbol Close x -> makeFence FPostfix $ vnode "mo" x
186-
ESymbol Ord x -> vnode "mi" x
197+
ESymbol Ord x
198+
| x == "\x2061" -> vnode "mo" x
199+
| otherwise -> vnode "mi" x
187200
ESymbol _ x -> vnode "mo" x
188201
ESpace x -> spaceWidth x
189202
EFraction ft x y -> showFraction tt ft x y
190-
ESub x y -> unode "msub" $ map (showExp tt) [x, y]
191-
ESuper x y -> unode "msup" $ map (showExp tt) [x, y]
192-
ESubsup x y z -> unode "msubsup" $ map (showExp tt) [x, y, z]
193-
EUnder _ x y -> unode "munder" [showExp tt x, showExp' tt y]
203+
ESub x y -> unode "msub" $ showExps tt [x, y]
204+
ESuper x y -> unode "msup" $ showExps tt [x, y]
205+
ESubsup x y z -> unode "msubsup" $ showExps tt [x, y, z]
206+
EUnder _ x y -> unode "munder" $ showExps tt [x] ++ [showExp' tt y]
194207
EOver _ x (ESymbol Accent "\8407") -- see #218, gives better rendering for vectors
195-
-> unode "mover" [showExp tt x, showExp' tt (ESymbol Accent "\8594")]
196-
EOver _ x y -> unode "mover" [showExp tt x, showExp' tt y]
197-
EUnderover _ x y z -> unode "munderover"
198-
[showExp tt x, showExp' tt y, showExp' tt z]
199-
EPhantom x -> unode "mphantom" $ showExp tt x
208+
-> unode "mover" $ showExps tt [x] ++ [showExp' tt (ESymbol Accent "\8594")]
209+
EOver _ x y -> unode "mover" $ showExps tt [x] ++ [showExp' tt y]
210+
EUnderover _ x y z -> unode "munderover" $
211+
showExps tt [x] ++ [showExp' tt y, showExp' tt z]
212+
EPhantom x -> unode "mphantom" $ showExps tt [x]
200213
EBoxed x -> withAttribute "notation" "box" .
201214
unode "menclose" $ showExp tt x
202215
ESqrt x -> unode "msqrt" $ showExp tt x

test/writer/mml/00000_C0_Controls_and_Basic_Latin.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@
224224
<mi>*</mi>
225225
</mtd>
226226
<mtd columnalign="center" style="text-align: center">
227-
<mo></mo>
227+
<mi></mi>
228+
<mo>&#8289;</mo>
228229
</mtd>
229230
<mtd columnalign="center" style="text-align: center">
230231
<mi>0</mi>

test/writer/mml/02000_General_Punctuation.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
<mi>⁑</mi>
242242
</mtd>
243243
<mtd columnalign="center" style="text-align: center">
244-
<mi>&#8289;</mi>
244+
<mo>&#8289;</mo>
245245
</mtd>
246246
</mtr>
247247
<mtr>

test/writer/mml/08.test

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
<mi>n</mi>
7474
</msup>
7575
<mo>,</mo>
76-
<mo>arg</mo>
76+
<mi>arg</mi>
77+
<mo>&#8289;</mo>
7778
<mrow>
7879
<mo stretchy="true" form="prefix">(</mo>
7980
<msup>
@@ -84,7 +85,8 @@
8485
</mrow>
8586
<mo>=</mo>
8687
<mi>n</mi>
87-
<mo>arg</mo>
88+
<mi>arg</mi>
89+
<mo>&#8289;</mo>
8890
<mrow>
8991
<mo stretchy="true" form="prefix">(</mo>
9092
<mi>z</mi>

test/writer/mml/09.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
2020
<mrow>
2121
<munder>
22-
<mo>lim</mo>
22+
<mi>lim</mi>
23+
<mo>&#8289;</mo>
2324
<mrow>
2425
<mi>z</mi>
2526
<mo>→</mo>

test/writer/mml/10.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
</msubsup>
7777
<mfrac>
7878
<mrow>
79-
<mo>sin</mo>
79+
<mi>sin</mi>
80+
<mo>&#8289;</mo>
8081
<mrow>
8182
<mo stretchy="true" form="prefix">(</mo>
8283
<mi>κ</mi>

test/writer/mml/a.test

+4-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@
138138
<mtext mathvariant="normal">acE</mtext>
139139
</mtd>
140140
<mtd columnalign="center" style="text-align: center">
141-
<mo>∾̳</mo>
141+
<mi>∾̳</mi>
142+
<mo>&#8289;</mo>
142143
</mtd>
143144
</mtr>
144145
<mtr>
@@ -202,7 +203,7 @@
202203
<mtext mathvariant="normal">af</mtext>
203204
</mtd>
204205
<mtd columnalign="center" style="text-align: center">
205-
<mi>&#8289;</mi>
206+
<mo>&#8289;</mo>
206207
</mtd>
207208
</mtr>
208209
<mtr>
@@ -562,7 +563,7 @@
562563
<mtext mathvariant="normal">ApplyFunction</mtext>
563564
</mtd>
564565
<mtd columnalign="center" style="text-align: center">
565-
<mi>&#8289;</mi>
566+
<mo>&#8289;</mo>
566567
</mtd>
567568
</mtr>
568569
<mtr>

test/writer/mml/b.test

+4-2
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,17 @@
577577
<mtext mathvariant="normal">bne</mtext>
578578
</mtd>
579579
<mtd columnalign="center" style="text-align: center">
580-
<mo>=⃥</mo>
580+
<mi>=⃥</mi>
581+
<mo>&#8289;</mo>
581582
</mtd>
582583
</mtr>
583584
<mtr>
584585
<mtd columnalign="center" style="text-align: center">
585586
<mtext mathvariant="normal">bnequiv</mtext>
586587
</mtd>
587588
<mtd columnalign="center" style="text-align: center">
588-
<mo>≡⃥</mo>
589+
<mi>≡⃥</mi>
590+
<mo>&#8289;</mo>
589591
</mtd>
590592
</mtr>
591593
<mtr>

test/writer/mml/c.test

+4-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@
237237
<mtext mathvariant="normal">caps</mtext>
238238
</mtd>
239239
<mtd columnalign="center" style="text-align: center">
240-
<mo>∩︀</mo>
240+
<mi>∩︀</mi>
241+
<mo>&#8289;</mo>
241242
</mtd>
242243
</mtr>
243244
<mtr>
@@ -1037,7 +1038,8 @@
10371038
<mtext mathvariant="normal">cups</mtext>
10381039
</mtd>
10391040
<mtd columnalign="center" style="text-align: center">
1040-
<mo>∪︀</mo>
1041+
<mi>∪︀</mi>
1042+
<mo>&#8289;</mo>
10411043
</mtd>
10421044
</mtr>
10431045
<mtr>

0 commit comments

Comments
 (0)