Elementary math

This page contains some tests for the MathML elementary math elements. These are rendered via the 'elemMath.js' polyfill.

mstack examples from MathML spec (some general examples)

  1. Simple addition with operator on the left
    ImageMathML
    2d addition problem 424 + 33
  2. Simple addition with operator on the right
    ImageMathML
    2d addition problem with plus on right 123 456 + 579
  3. Two examples showing carries and crossouts
    ImageMathML
    2d subtraction problem with borrows above 2 12 2,327 - 1,156 1,171
    2d subtraction problem with borrows to northwest 2 1 2,327 - 1,156 1,171
  4. Carries and crossouts, but with multiple digits in carry and underlined
    ImageMathML
    2d subtraction problem with underlined borrow 10 52 - 7 45
  5. Simple multiplication (uses msgroup)
    ImageMathML
    2d multiplication 123 ×321 123 246 369
  6. This example has multiple rows of carries. It also (somewhat artificially) includes commas (",") as digit separators. The encoding includes these separators in the spacing attribute value.
    ImageMathML
    2d multiplication problem with carries 11 11 1,234 ×4,321 1 1 1 1 1 1,234 24,68 370,2 4,936 5,332,114
  7. Repeating decimals (line over 3): 0.3333
  8. Repeating decimals (line over fractional part): 0.142857
  9. Repeating decimals (line under fractional part): 0.142857
  10. Repeating decimals (dots over start and end of fractional part): . . 0.142857

mstack

Test with different number of args

  1. mstack with no elements (should be empty, no console warnings):
  2. mstack with a single number (should just be a number): 123
  3. 2 arguments (simple stack of numbers): 123 456

Test with different attr args/values

align

Not implemented

stackalign (alignment of stack of elements

  1. left 2123.4 456.018 + 2579.418
  2. center 2123.4 456.018 + 2579.418
  3. right 2123.4 456.018 + 2579.418
  4. decimal 2123.4 456.018 + 2579.418
  5. decimal (default value) 2123.4 456.018 + 2579.418
  6. decimal (default value, using inherited value set by mstyle) 2123, 456,018 + 2579,418

charalign (alignment of character in a column)

  1. left 12 wide 1
  2. center 12 wide 1
  3. right 12 wide 1
  4. default (right) 12 wide 1

charspacing

  1. loose 432 +33
  2. medium 432 + 33
  3. tight 432 + 33
  4. value (1em -- really wide) 432 + 33
  5. tight with a none value 4321 + 33

msgroup tests

Test with different number of args

  1. msgroup with no elements (should be empty, no console warnings):
  2. msgroup with a single number (position=2, shift=1 -- visually not much but two empty columns on right): 123
  3. msgroup with 2 arguments (position=-1, shift=2 -- visually '1's should align): 123 321
  4. Nested msgroups (position=-1, shift=2, with position=-1, shift=1 nested inside (rows 4-6)-- visually all digits should align): 123 234 345 567 456 345 0123

Test with different attr args/values

position

  1. two msgroups (position=1, position=-1) -- the '3's should align: 123 345
  2. two msgroups (1st two lines position=1, last two lines position=-1) -- the '3's should align. 123 123 345 345

shift

  1. 2 msgroups (shift=1, shift=-1) -- the digits should align. The first group should shift to the left; the second group should shift to the right: 345 234 123 345 456 567
  2. 2 msgroups (position='-2' shift='-2' and position ='-6' shift='2') with 123 above and below the groups -- the digits should align. The first group should shift to the right by two digits each line; the second group should similarly shift to the left: 123 345 567 789 789 567 345 123

msrow tests

Test with different number of args

  1. msrow with a single number -- visually not much: 123
  2. msrow with 3 arguments -- the two decimal numbers should align: 123.45 | 456 123.45

Test with different attr args/values

position

  1. mrow with no elements (position=2) -- should be empty, no console warnings:
  2. msrow with a single number (position='-2') -- visually not much (should be two blank cells on left): 123
  3. msrows (position=1, position=-1) -- the '3's should align: 123 345

mscarries tests

Test with different number of args

  1. mscarries with no elements (position=2) -- should see just '123', no padding, no console warnings: 123
  2. mscarries with no elements and no following line (position=2) -- should not see anything, no console warnings:
  3. mscarries with one child and no following line (position=2) -- should see a small 9, no console warnings: 9
  4. mscarries with two children, should see 8 over 2, 9 over the 3: 8 9 123
  5. mscarries with two children (position=2), should see 1 over empty space, 9 over the 2: 1 2 9
  6. two rows of mscarries over each other, should see carry '1' over carry '2' over '9': 1 2 789
  7. three rows of mscarries over each other, should see carry '1' over carry '2' over carry '3' over '9': 1 2 3 789
  8. two rows of numbers with a carry between them (3's should align, with middle one small, not crash together or crash into line): 123 3 543

Test with different attr args/values

position

  1. mscarries with single child (position=-1), should see 9 one column to the right of 3: 9 123
  2. mscarries with single child (position=1), should see 9 over 2: 9 123
  3. mscarries with single child and no position give should see 9 over 1: 9 123

location

  1. 'w': 8 and 9 should be before 2 and 3 respectivly 8 9 123
  2. 'nw': 8 and 9 should be pre-superscripts before 2 and 3 respectivly 8 9 123
  3. 'n': 8 and 9 should be above 2 and 3 respectivly 8 9 123
  4. 'ne': 8 and 9 should be superscripts to 2 and 3 respectivly 8 9 123
  5. 'e': 8 and 9 should be after 2 and 3 respectivly 8 9 123
  6. 'se': 8 and 9 should be subscripts to 2 and 3 respectivly 8 9 123
  7. 's': 8 and 9 should be below 2 and 3 respectivly 8 9 123
  8. 'sw': 8 and 9 should be presubscripts before 2 and 3 respectivly 8 9 123
  9. default ('n'): 8 and 9 should be above 2 and 3 respectivly 8 9 123

crossout

test individually and in combinations
  1. No cross out ('none') (carry 'n': 9 should be above 3) 9 123
  2. Crossout is updiagonalstrike (carry 'ne': 9 should be superscript to 3) 9 123
  3. Crossout is downdiagonalstrike (carry 'nw': 9 should be superscript to 3) 9 123
  4. Cross out is verticalstrike (carry 'n': 9 should be above 3) 9 123
  5. Crossout is horizontalstrike (carry 'ne': 9 should be superscript to 3) 9 123
  6. Crossout is both downdiagonalstrike and updiagonalstrike (carry 'nw': 9 should be superscript to 3) 9 123
  7. Crossout is all four (carry 'n, position=1': 9 should be above the 2) 9 123
  8. Crossout is both downdiagonalstrike (twice) and updiagonalstrike (carry 'nw': 9 should be superscript to 3) -- lots of extra spaces in attr value 9 123

scriptsizemultiplier

  1. .4 -- should be smaller than normal (compare to second line of carries) 8 9 12345 8 9 123
  2. 1.5 -- should be bigger than normal (compare to second line of carries) and overflow into each other 8 9 12345 8 9 123
  3. .4 -- should be smaller than normal (value inherited from mstyle). Both rows of carries should be small. 8 9 12345 8 9 123

mscarry tests

Test with different number of args

  1. mscarry with no child -- should see no change (just 123): 123
  2. mscarry with single child and no position give should see 9 over 3: 9 123
  3. mscarry with multiple digits over '2' -- should overflow to other columns and not change spacing: 789 123

Test with different attr args/values

location

  1. mscarry with location starting a 'w' (on left) ending with 'sw' and finally default inheritance of 'n' over 9; nothing should be over the '+': 0 0 0 0 0 0 0 0 0 + 123456789
  2. mscarry with location starting a 'w' (on left) ending with 'sw' and finally default inheritance of 'nw' over 9; nothing should be over the '+': 0 0 0 0 0 0 0 0 0 + 123456789

crossout

  1. mscarry with crossout starting at "none", "updiagonalstrike", "downdiagonalstrike", "verticalstrike", "horizontalstrike", with the default of diag up/down over the '9': + 56789

msline tests

Test with different number of args

  1. only a msline (length=3) -- should display as a line, perhaps somewhat short due to cells having a small width:
  2. msline first line (position='1' length='2') -- should be above 1 and 2: 123

Test with different attr args/values

position

  1. msline (position=1, length unspecified) -- should draw line under all digits: 123
  2. msline (position=1, length=1) -- should draw line under '2'': 123
  3. msline (position=4, length=1) -- should draw line before '1'': 123
  4. msline (position=-1, length=1) -- should draw line after '3': 123

length

  1. Both lines should be all the way across (default value) 123 ×321 123 246 369
  2. Both lines should be all the way across (length=0) 123 ×321 123 246 369
  3. First line only to '×' (length=4); second only under 369 (length=3, position=2) 123 ×321 123 246 369
  4. line extends beyond number one column on each side (length=5, position=-1) 123

leftoverhang

Not implemented

rightoverhang

Not implemented

mslinethickness

  1. thin 123
  2. medium 123
  3. thick 123
  4. default (medium) 123
  5. 3ex (very fat) 123

inherited value of mathcolor

  1. the number and line should be gray 123
  2. mstyle inside of mstyle -- numbers should be gray, the second should be a fat blue line 123

mlongdiv

Long division examples from MathML spec (the polyfill supports a 'decimalpoint' attr on 'mlongdiv'/'mstack', which is not part of MathML 3; see this issue for why)

longdivstyle lefttop stackedrightright mediumstackedrightright shortstackedrightright righttop
Image from spec US long division example French long division example Russian division example Brazilian long division example Chinese long division example
Polyfill rendering 3 435.3 1306 12 10 9 16 15 1.0 9 1 3 435,3 1306 12 10 9 16 15 1,0 9 1
longdivstyle left/\right left)(right :right=right stackedleftleft stackedleftlinetop
Image from spec Dutch long division example Indian long division example German long division example Arabic long division example Alternate Arabic long division example
Polyfill rendering ٣ ٤٣٥٫٣ ١٣٠٦ ١٢ ١٠ ٩ ١٦ ١٥ ١٫٠ ٩ ١

Long divsion with too few arguments

  1. three arguments 1 2 3

No arguments

One argument

  1. 11.1

Two arguments

  1. 11.1 22.2

Three arguments

  1. 11.1 22.2 33.3