Skip to content

Commit b3ee360

Browse files
committed
MathML writer: improve formatting of aligned equations.
An EArray with alternating R,L alignments will be assumed to be aligned equations and rendered without padding. Closes #207.
1 parent cfbc274 commit b3ee360

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/Text/TeXMath/Writers/MathML.hs

+11-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import Text.XML.Light
2828
import Text.TeXMath.Types
2929
import Text.TeXMath.Unicode.ToUnicode
3030
import Data.Generics (everywhere, mkT)
31-
import Text.TeXMath.Shared (getMMLType, handleDownup, isUppercaseGreek)
31+
import Text.TeXMath.Shared (getMMLType, handleDownup,
32+
isUppercaseGreek, isRLSequence)
3233
import Text.TeXMath.Readers.MathML.MMLDict (getMathMLOperator)
3334
import qualified Data.Text as T
3435
import Text.Printf
@@ -116,14 +117,20 @@ makeArray tt as ls = unode "mtable" $
116117
-- see #205 on the need for style attributes:
117118
where setAlignment AlignLeft =
118119
withAttribute "columnalign" "left" .
119-
withAttribute "style" "text-align: left"
120+
withAttribute "style"
121+
(if isRLSequence as
122+
then "text-align: left; padding-left: 0"
123+
else "text-align: left")
120124
setAlignment AlignRight =
121125
withAttribute "columnalign" "right" .
122-
withAttribute "style" "text-align: right"
126+
withAttribute "style"
127+
(if isRLSequence as
128+
then "text-align: right; padding-right: 0"
129+
else "text-align: right")
123130
setAlignment AlignCenter =
124131
withAttribute "columnalign" "center" .
125132
withAttribute "style" "text-align: center"
126-
as' = as ++ cycle [AlignCenter]
133+
as' = as ++ repeat AlignCenter
127134

128135
-- Kept as String for Text.XML.Light
129136
withAttribute :: String -> T.Text -> Element -> Element

test/writer/mml/sphere_volume.test

+10-10
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<mo stretchy="false" form="postfix">}</mo>
156156
<mtable>
157157
<mtr>
158-
<mtd columnalign="right" style="text-align: right">
158+
<mtd columnalign="right" style="text-align: right; padding-right: 0">
159159
<mrow>
160160
<mi mathvariant="normal">V</mi>
161161
<mi mathvariant="normal">o</mi>
@@ -165,7 +165,7 @@
165165
<mi mathvariant="normal">e</mi>
166166
</mrow>
167167
</mtd>
168-
<mtd columnalign="left" style="text-align: left">
168+
<mtd columnalign="left" style="text-align: left; padding-left: 0">
169169
<mo>=</mo>
170170
<munder>
171171
<mo>∭</mo>
@@ -191,8 +191,8 @@
191191
</mtd>
192192
</mtr>
193193
<mtr>
194-
<mtd columnalign="right" style="text-align: right" />
195-
<mtd columnalign="left" style="text-align: left">
194+
<mtd columnalign="right" style="text-align: right; padding-right: 0" />
195+
<mtd columnalign="left" style="text-align: left; padding-left: 0">
196196
<mo>=</mo>
197197
<msubsup>
198198
<mo>∫</mo>
@@ -234,8 +234,8 @@
234234
</mtd>
235235
</mtr>
236236
<mtr>
237-
<mtd columnalign="right" style="text-align: right" />
238-
<mtd columnalign="left" style="text-align: left">
237+
<mtd columnalign="right" style="text-align: right; padding-right: 0" />
238+
<mtd columnalign="left" style="text-align: left; padding-left: 0">
239239
<mo>=</mo>
240240
<mi>ϕ</mi>
241241
<msubsup>
@@ -278,8 +278,8 @@
278278
</mtd>
279279
</mtr>
280280
<mtr>
281-
<mtd columnalign="right" style="text-align: right" />
282-
<mtd columnalign="left" style="text-align: left">
281+
<mtd columnalign="right" style="text-align: right; padding-right: 0" />
282+
<mtd columnalign="left" style="text-align: left; padding-left: 0">
283283
<mo>=</mo>
284284
<mn>2</mn>
285285
<mi>π</mi>
@@ -299,8 +299,8 @@
299299
</mtd>
300300
</mtr>
301301
<mtr>
302-
<mtd columnalign="right" style="text-align: right" />
303-
<mtd columnalign="left" style="text-align: left">
302+
<mtd columnalign="right" style="text-align: right; padding-right: 0" />
303+
<mtd columnalign="left" style="text-align: left; padding-left: 0">
304304
<mo>=</mo>
305305
<mstyle displaystyle="false">
306306
<mfrac>

0 commit comments

Comments
 (0)