Skip to content

Commit d821b96

Browse files
committed
MathML writer: use mathattribute instead of finding unicode substitutes.
See #280, #205, and 3c746ad for background. Previously, renderers didn't support mathvariant consistently, so we converted to unicode styled characters instead of using mathvariant. This workaround is no longer necessary.
1 parent aee6b49 commit d821b96

27 files changed

+387
-396
lines changed

src/Text/TeXMath/Writers/MathML.hs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,20 @@ dropTrailing0s t = case T.unsnoc t of -- T.spanEnd does not exist
9494
Just (_, '.') -> T.snoc x '0'
9595
_ -> x
9696

97-
-- Note: Converts strings to unicode directly, as few renderers support those mathvariants.
9897
makeText :: TextType -> T.Text -> Element
9998
makeText a s = case (leadingSp, trailingSp) of
10099
(False, False) -> s'
101100
(True, False) -> mrow [sp, s']
102101
(False, True) -> mrow [s', sp]
103102
(True, True) -> mrow [sp, s', sp]
104103
where sp = spaceWidth (1/3)
105-
s' = withAttribute "mathvariant" attr $ tunode "mtext" $ toUnicode a s
104+
s' = withAttribute "mathvariant" (getMMLType a) $ tunode "mtext" s
106105
trailingSp = case T.unsnoc s of
107106
Just (_, c) -> T.any (== c) " \t"
108107
_ -> False
109108
leadingSp = case T.uncons s of
110109
Just (c, _) -> T.any (== c) " \t"
111110
_ -> False
112-
attr = getMMLType a
113111

114112
makeArray :: Maybe TextType -> [Alignment] -> [ArrayLine] -> Element
115113
makeArray tt as ls = unode "mtable" $
@@ -187,10 +185,7 @@ insertFunctionApps es' = go es'
187185

188186
showExp :: Maybe TextType -> Exp -> Element
189187
showExp tt e =
190-
let toUnicodeMaybe :: TextType -> T.Text -> Maybe T.Text
191-
toUnicodeMaybe textStyle t =
192-
T.pack <$> mapM (toUnicodeChar . (textStyle,)) (T.unpack t)
193-
-- variant node: tries to convert text to appropriate unicode
188+
let -- variant node: tries to convert text to appropriate unicode
194189
-- characters depending on style
195190
vnode :: String -> T.Text -> Element
196191
vnode elname t
@@ -201,12 +196,8 @@ showExp tt e =
201196
else tunode elname t
202197
Just TextNormal -> withAttribute "mathvariant" "normal" $
203198
tunode elname t
204-
Just textStyle ->
205-
case toUnicodeMaybe textStyle t of
206-
-- if we can't find unicode equivalents, rely on mathvariant:
207-
Nothing -> withAttribute "mathvariant" (getMMLType textStyle) $
208-
tunode elname t
209-
Just t' -> tunode elname t'
199+
Just textStyle -> withAttribute "mathvariant" (getMMLType textStyle) $
200+
tunode elname t
210201
in case e of
211202
ENumber x -> vnode "mn" x
212203
EGrouped [x] -> showExp tt x

test/writer/mml/20.test

Lines changed: 115 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -119,120 +119,120 @@
119119
<?xml version='1.0' ?>
120120
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
121121
<mrow>
122-
<mi>𝒜</mi>
123-
<mi>ℬ</mi>
124-
<mi>𝒞</mi>
125-
<mi>𝒟</mi>
126-
<mi>ℰ</mi>
127-
<mi>ℱ</mi>
128-
<mi>𝒢</mi>
129-
<mi>ℋ</mi>
130-
<mi>ℐ</mi>
131-
<mi>𝒥</mi>
132-
<mi>𝒦</mi>
133-
<mi>ℒ</mi>
134-
<mi>ℳ</mi>
135-
<mi>𝒩</mi>
136-
<mi>𝒪</mi>
137-
<mi>𝒫</mi>
138-
<mi>𝒬</mi>
139-
<mi>ℛ</mi>
140-
<mi>𝒮</mi>
141-
<mi>𝒯</mi>
142-
<mi>𝒰</mi>
143-
<mi>𝒱</mi>
144-
<mi>𝒲</mi>
145-
<mi>𝒳</mi>
146-
<mi>𝒴</mi>
147-
<mi>𝒵</mi>
148-
<mi>𝒶</mi>
149-
<mi>𝒷</mi>
150-
<mi>𝒸</mi>
151-
<mi>𝒹</mi>
152-
<mi>ℯ</mi>
153-
<mi>𝒻</mi>
154-
<mi>ℊ</mi>
155-
<mi>𝒽</mi>
156-
<mi>𝒾</mi>
157-
<mi>𝒿</mi>
158-
<mi>𝓀</mi>
159-
<mi>𝓁</mi>
160-
<mi>𝓂</mi>
161-
<mi>𝓃</mi>
162-
<mi>ℴ</mi>
163-
<mi>𝓅</mi>
164-
<mi>𝓆</mi>
165-
<mi>𝓇</mi>
166-
<mi>𝓈</mi>
167-
<mi>𝓉</mi>
168-
<mi>𝓊</mi>
169-
<mi>𝓋</mi>
170-
<mi>𝓌</mi>
171-
<mi>𝓍</mi>
172-
<mi>𝓎</mi>
173-
<mi>𝓏</mi>
174-
<mi>𝔸</mi>
175-
<mi>𝔹</mi>
176-
<mi>ℂ</mi>
177-
<mi>𝔻</mi>
178-
<mi>𝔼</mi>
179-
<mi>𝔽</mi>
180-
<mi>𝔾</mi>
181-
<mi>ℍ</mi>
182-
<mi>𝕀</mi>
183-
<mi>𝕁</mi>
184-
<mi>𝕂</mi>
185-
<mi>𝕃</mi>
186-
<mi>𝕄</mi>
187-
<mi>ℕ</mi>
188-
<mi>𝕆</mi>
189-
<mi>ℙ</mi>
190-
<mi>ℚ</mi>
191-
<mi>ℝ</mi>
192-
<mi>𝕊</mi>
193-
<mi>𝕋</mi>
194-
<mi>𝕌</mi>
195-
<mi>𝕍</mi>
196-
<mi>𝕎</mi>
197-
<mi>𝕏</mi>
198-
<mi>𝕐</mi>
199-
<mi>ℤ</mi>
200-
<mi>𝕒</mi>
201-
<mi>𝕓</mi>
202-
<mi>𝕔</mi>
203-
<mi>𝕕</mi>
204-
<mi>𝕖</mi>
205-
<mi>𝕗</mi>
206-
<mi>𝕘</mi>
207-
<mi>𝕙</mi>
208-
<mi>𝕚</mi>
209-
<mi>𝕛</mi>
210-
<mi>𝕜</mi>
211-
<mi>𝕝</mi>
212-
<mi>𝕞</mi>
213-
<mi>𝕟</mi>
214-
<mi>𝕠</mi>
215-
<mi>𝕡</mi>
216-
<mi>𝕢</mi>
217-
<mi>𝕣</mi>
218-
<mi>𝕤</mi>
219-
<mi>𝕥</mi>
220-
<mi>𝕦</mi>
221-
<mi>𝕧</mi>
222-
<mi>𝕨</mi>
223-
<mi>𝕩</mi>
224-
<mi>𝕪</mi>
225-
<mi>𝕫</mi>
226-
<mn>𝟘</mn>
227-
<mn>𝟙</mn>
228-
<mn>𝟚</mn>
229-
<mn>𝟛</mn>
230-
<mn>𝟜</mn>
231-
<mn>𝟝</mn>
232-
<mn>𝟞</mn>
233-
<mn>𝟟</mn>
234-
<mn>𝟠</mn>
235-
<mn>𝟡</mn>
236-
<mn>𝟘</mn>
122+
<mi mathvariant="script">A</mi>
123+
<mi mathvariant="script">B</mi>
124+
<mi mathvariant="script">C</mi>
125+
<mi mathvariant="script">D</mi>
126+
<mi mathvariant="script">E</mi>
127+
<mi mathvariant="script">F</mi>
128+
<mi mathvariant="script">G</mi>
129+
<mi mathvariant="script">H</mi>
130+
<mi mathvariant="script">I</mi>
131+
<mi mathvariant="script">J</mi>
132+
<mi mathvariant="script">K</mi>
133+
<mi mathvariant="script">L</mi>
134+
<mi mathvariant="script">M</mi>
135+
<mi mathvariant="script">N</mi>
136+
<mi mathvariant="script">O</mi>
137+
<mi mathvariant="script">P</mi>
138+
<mi mathvariant="script">Q</mi>
139+
<mi mathvariant="script">R</mi>
140+
<mi mathvariant="script">S</mi>
141+
<mi mathvariant="script">T</mi>
142+
<mi mathvariant="script">U</mi>
143+
<mi mathvariant="script">V</mi>
144+
<mi mathvariant="script">W</mi>
145+
<mi mathvariant="script">X</mi>
146+
<mi mathvariant="script">Y</mi>
147+
<mi mathvariant="script">Z</mi>
148+
<mi mathvariant="script">a</mi>
149+
<mi mathvariant="script">b</mi>
150+
<mi mathvariant="script">c</mi>
151+
<mi mathvariant="script">d</mi>
152+
<mi mathvariant="script">e</mi>
153+
<mi mathvariant="script">f</mi>
154+
<mi mathvariant="script">g</mi>
155+
<mi mathvariant="script">h</mi>
156+
<mi mathvariant="script">i</mi>
157+
<mi mathvariant="script">j</mi>
158+
<mi mathvariant="script">k</mi>
159+
<mi mathvariant="script">l</mi>
160+
<mi mathvariant="script">m</mi>
161+
<mi mathvariant="script">n</mi>
162+
<mi mathvariant="script">o</mi>
163+
<mi mathvariant="script">p</mi>
164+
<mi mathvariant="script">q</mi>
165+
<mi mathvariant="script">r</mi>
166+
<mi mathvariant="script">s</mi>
167+
<mi mathvariant="script">t</mi>
168+
<mi mathvariant="script">u</mi>
169+
<mi mathvariant="script">v</mi>
170+
<mi mathvariant="script">w</mi>
171+
<mi mathvariant="script">x</mi>
172+
<mi mathvariant="script">y</mi>
173+
<mi mathvariant="script">z</mi>
174+
<mi mathvariant="double-struck">A</mi>
175+
<mi mathvariant="double-struck">B</mi>
176+
<mi mathvariant="double-struck">C</mi>
177+
<mi mathvariant="double-struck">D</mi>
178+
<mi mathvariant="double-struck">E</mi>
179+
<mi mathvariant="double-struck">F</mi>
180+
<mi mathvariant="double-struck">G</mi>
181+
<mi mathvariant="double-struck">H</mi>
182+
<mi mathvariant="double-struck">I</mi>
183+
<mi mathvariant="double-struck">J</mi>
184+
<mi mathvariant="double-struck">K</mi>
185+
<mi mathvariant="double-struck">L</mi>
186+
<mi mathvariant="double-struck">M</mi>
187+
<mi mathvariant="double-struck">N</mi>
188+
<mi mathvariant="double-struck">O</mi>
189+
<mi mathvariant="double-struck">P</mi>
190+
<mi mathvariant="double-struck">Q</mi>
191+
<mi mathvariant="double-struck">R</mi>
192+
<mi mathvariant="double-struck">S</mi>
193+
<mi mathvariant="double-struck">T</mi>
194+
<mi mathvariant="double-struck">U</mi>
195+
<mi mathvariant="double-struck">V</mi>
196+
<mi mathvariant="double-struck">W</mi>
197+
<mi mathvariant="double-struck">X</mi>
198+
<mi mathvariant="double-struck">Y</mi>
199+
<mi mathvariant="double-struck">Z</mi>
200+
<mi mathvariant="double-struck">a</mi>
201+
<mi mathvariant="double-struck">b</mi>
202+
<mi mathvariant="double-struck">c</mi>
203+
<mi mathvariant="double-struck">d</mi>
204+
<mi mathvariant="double-struck">e</mi>
205+
<mi mathvariant="double-struck">f</mi>
206+
<mi mathvariant="double-struck">g</mi>
207+
<mi mathvariant="double-struck">h</mi>
208+
<mi mathvariant="double-struck">i</mi>
209+
<mi mathvariant="double-struck">j</mi>
210+
<mi mathvariant="double-struck">k</mi>
211+
<mi mathvariant="double-struck">l</mi>
212+
<mi mathvariant="double-struck">m</mi>
213+
<mi mathvariant="double-struck">n</mi>
214+
<mi mathvariant="double-struck">o</mi>
215+
<mi mathvariant="double-struck">p</mi>
216+
<mi mathvariant="double-struck">q</mi>
217+
<mi mathvariant="double-struck">r</mi>
218+
<mi mathvariant="double-struck">s</mi>
219+
<mi mathvariant="double-struck">t</mi>
220+
<mi mathvariant="double-struck">u</mi>
221+
<mi mathvariant="double-struck">v</mi>
222+
<mi mathvariant="double-struck">w</mi>
223+
<mi mathvariant="double-struck">x</mi>
224+
<mi mathvariant="double-struck">y</mi>
225+
<mi mathvariant="double-struck">z</mi>
226+
<mn mathvariant="double-struck">0</mn>
227+
<mn mathvariant="double-struck">1</mn>
228+
<mn mathvariant="double-struck">2</mn>
229+
<mn mathvariant="double-struck">3</mn>
230+
<mn mathvariant="double-struck">4</mn>
231+
<mn mathvariant="double-struck">5</mn>
232+
<mn mathvariant="double-struck">6</mn>
233+
<mn mathvariant="double-struck">7</mn>
234+
<mn mathvariant="double-struck">8</mn>
235+
<mn mathvariant="double-struck">9</mn>
236+
<mn mathvariant="double-struck">0</mn>
237237
</mrow>
238238
</math>

0 commit comments

Comments
 (0)