-
Notifications
You must be signed in to change notification settings - Fork 14
/
spec.html
6263 lines (6247 loc) · 301 KB
/
spec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MathML Core</title>
<link class="removeOnSave" href="https://test.csswg.org/harness/stylesheets/annotate.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove">
</script>
<script src="tables/sorttable.js"></script>
<script class="remove" src="wpt/data-tests.js"></script>
<script class="remove" src="wpt/spec-implementation-report.js"></script>
<script class="remove">
var respecConfig = {
specStatus: "ED",
// crEnd: "2022-12-31",
// previousPublishDate: "2021-08-16",
// previousPublishDate: "2022-05-04",
previousPublishDate: "2023-11-27",
previousMaturity: "WD",
editors: [{
name: "David Carlisle",
url: "https://github.com/davidcarlisle",
company: "NAG",
w3cid: 4238
}, {
name: "Frédéric Wang",
url: "https://frederic-wang.fr",
company: "Igalia",
w3cid: 112458
}],
formerEditors: [{
name: "Patrick Ion",
url: "http://www-personal.umich.edu/~pion/",
company: "Mathematical Reviews, American Mathematical Society"
}, {
name: "Robert Miner (deceased)",
company: "Design Science, Inc."
}],
group: "math",
edDraftURI: "https://w3c.github.io/mathml-core/",
shortName: "mathml-core",
github: "w3c/mathml-core",
mdn: false,
testSuiteURI: "https://github.com/web-platform-tests/wpt/tree/master/mathml/",
implementationReportURI: "https://wpt.fyi/results/?label=master&label=experimental&aligned&q=math%20%20not%28path%3A%2Fjs%29",
xref: ['html', 'infra', 'css-display-3', 'css-text-3', 'web-animations', 'css-fonts-4', 'dom', 'cssom-view', 'css-sizing-3', 'css-align-3', 'css-box-4', 'css-values-4', 'css-backgrounds-3', 'css-text-decor-4', 'svg', 'css-writing-modes-4', 'css-color-4', 'css-box-4', 'css-pseudo-4'],
localBiblio: {
"MATHML4": {
title: "Mathematical Markup Language (MathML) Version 4.0",
authors: [
"David Carlisle et al."
],
status: "ED",
href: "https://w3c.github.io/mathml/"
},
"HOUDINI": {
title: "CSS-TAG Houdini Editor Drafts",
href: "https://drafts.css-houdini.org/"
},
"TEXBOOK": {
title: "The TeXBook",
date: "1984",
authors: [
"Knuth, Donald E."
],
publisher: "Addison-Wesley Professional",
id: "ISBN9780201134483"
},
"OPEN-TYPE-MATH-ILLUMINATED": {
title: "OpenType Math Illuminated",
date: "2009",
authors: [
"Ulrik Vieth"
],
href: "https://www.tug.org/TUGboat/tb30-1/tb94vieth.pdf",
},
"OPEN-TYPE-MATH-IN-HARFBUZZ": {
title: "OpenType MATH in HarfBuzz",
authors: [
"Frédéric Wang"
],
href: "https://frederic-wang.fr/2016/04/16/opentype-math-in-harfbuzz/"
}
},
preProcess: [initReport],
postProcess: [sorttable.init, loadWebPlaformTestsResults]
};
</script>
</head>
<body>
<div id="implementation-report"></div>
<section id="abstract">
<p>
This specification defines a core subset of Mathematical Markup
Language, or MathML, that is suitable for browser implementation.
MathML is a markup language for describing mathematical notation
and capturing both its structure and content. The goal of MathML is to
enable mathematics to be served, received, and processed on the World
Wide Web, just as HTML has enabled this functionality for text.
</p>
</section>
<section id="sotd">
</section>
<section class="informative">
<h2>Introduction</h2>
<p>
The [[MATHML3]] specification has several shortcomings that make it
hard to implement consistently across web rendering engines or to
extend with user-defined constructions, e.g.:
</p>
<ul>
<li>It is a huge and standalone specification.</li>
<li>It does not contain any detailed rendering rules.</li>
<li>It is not driven by browser-implementation.</li>
<li>It lacks automated testing.</li>
</ul>
<p>
This MathML Core specification intends to address these issues by
being as accurate as possible on the visual rendering of mathematical
formulas using additional rules from the TeXBook’s Appendix G
[[?TEXBOOK]] and from the Open Font Format [[OPEN-FONT-FORMAT]],
[[OPEN-TYPE-MATH-ILLUMINATED]]. It also relies on modern browser
implementations and web technologies [[HTML]] [[SVG]] [[CSS2]] [[DOM]],
clarifying interactions
with them when needed or introducing new low-level primitives to
improve the web platform layering.
</p>
<p>
Parts of MathML3 that do not fit well in this framework or are less
fundamental have been omitted. Instead, they are described in a
separate and larger [[MATHML4]] specification. The details of which
math feature will be included in future versions of MathML Core or
implemented as polyfills is still open. This question and other
potential improvements are <a href="https://github.com/w3c/mathml/issues?q=is%3Aissue+is%3Aopen+label%3A%22MathML+Core%22">tracked on GitHub</a>.
</p>
<p>
By increasing the level of implementation details, focusing on a
workable subset, following a browser-driven design and relying on
automated web platform tests, this specification is expected to
greatly improve MathML interoperability. Moreover, effort on MathML
layering will enable users to implement the rest of the MathML 4
specification, or more generally to extend MathML Core, using
modern web technologies such as
<a>shadow trees</a>,
<a>custom elements</a> or
APIs from [[HOUDINI]].
</p>
</section>
<section class="normative">
<h2>MathML Fundamentals</h2>
<section id="mathml-elements-and-attributes">
<h3>Elements and attributes</h3>
<p id="mathml-elements">
The term <dfn>MathML element</dfn> refers to any element in the
<a>MathML namespace</a>.
The MathML elements defined in this specification are called the
<dfn>MathML Core elements</dfn> and are listed below.
Any MathML element that is not listed below is called an
<dfn>Unknown MathML element</dfn>.
</p>
<ol>
<li>[^annotation^]</li>
<li>[^annotation-xml^]</li>
<li>[^maction^]</li>
<li>[^math^]</li>
<li>[^merror^]</li>
<li>[^mfrac^]</li>
<li>[^mi^]</li>
<li>[^mmultiscripts^]</li>
<li>[^mn^]</li>
<li>[^mo^]</li>
<li>[^mover^]</li>
<li>[^mpadded^]</li>
<li>[^mphantom^]</li>
<li>[^mprescripts^]</li>
<li>[^mroot^]</li>
<li>[^mrow^]</li>
<li>[^ms^]</li>
<li>[^mspace^]</li>
<li>[^msqrt^]</li>
<li>[^mstyle^]</li>
<li>[^msub^]</li>
<li>[^msubsup^]</li>
<li>[^msup^]</li>
<li>[^mtable^]</li>
<li>[^mtd^]</li>
<li>[^mtext^]</li>
<li>[^mtr^]</li>
<li>[^munder^]</li>
<li>[^munderover^]</li>
<li>[^semantics^]</li>
</ol>
<p>The <dfn>grouping elements</dfn> are
[^maction^],
[^math^],
[^merror^],
[^mphantom^],
[^mprescripts^],
[^mrow^],
[^mstyle^],
[^semantics^] and <a>unknown MathML elements</a>.</p>
<p>The <dfn>scripted elements</dfn> are
[^mmultiscripts^],
[^mover^],
[^msub^],
[^msubsup^],
[^msup^],
[^munder^] and
[^munderover^].
</p>
<p>The <dfn>radical elements</dfn> are
[^mroot^] and [^msqrt^].
</p>
<p>
The attributes defined in this specification have no namespace
and are called <dfn>MathML attributes</dfn>:
</p>
<ul>
<li><a href="#global-attributes">Global attributes</a></li>
<li><a href="#legacy-maction-attributes">Legacy <code>maction</code> attributes</a></li>
<li><a href="#mo-attributes"><code>mo</code> attributes</a></li>
<li><a href="#mpadded-attributes"><code>mpadded</code> attributes</a></li>
<li><a href="#mspace-attributes"><code>mspace</code> attributes</a></li>
<li><a href="#munderover-attributes"><code>munderover</code> attributes</a></li>
<li><a href="#mtd-attributes"><code>mtd</code> attributes</a></li>
<li>[^annotation/encoding^]</li>
<li>[^math/display^]</li>
<li>[^mfrac/linethickness^]</li>
</ul>
<section id="the-top-level-math-element">
<h4>The Top-Level <code><math></code> Element</h4>
<p>MathML specifies a single top-level or root
<dfn class="element">math</dfn> element, which encapsulates each
instance of MathML markup within a document. All other MathML content
must be contained in a <code><math></code> element.
</p>
<p>
The <code><math></code>
element accepts the attributes described
in <a href="#global-attributes"></a> as well as the
following attributes:
</p>
<ul>
<li>[^math/display^]</li>
<li>[^math/alttext^]</li>
</ul>
<p>
The
<dfn class="element-attr" data-dfn-for="math">display</dfn>
attribute, if present,
must be an
<a>ASCII case-insensitive</a>
match
to <code>block</code> or <code>inline</code>.
The user agent stylesheet
described in <a href="#user-agent-stylesheet"></a>
contains rules for this attribute that affect the
default values for the [^math/display^]
(<code>block math</code> or <code>inline math</code>)
and <a><code>math-style</code></a>
(<code>normal</code> or <code>compact</code>) properties.
If the <code>display</code>
attribute is absent or has an invalid value, the User Agent
stylesheet treats it the same as <code>inline</code>.
</p>
<p>
This specification does not define any observable behavior that is
specific to the <dfn class="element-attr" data-dfn-for="math">alttext</dfn> attribute.
</p>
<div class="note">
The [^math/alttext^] attribute may be used as
alternative text by some legacy systems that do not
implement math layout.</div>
<p>
If the <code><math></code> element does not have its computed
[^math/display^] property equal to
<code>block math</code> or <code>inline math</code>
then it is laid out according to the CSS specification where
the corresponding value is described.
Otherwise the layout algorithm of the
[^mrow^] element is used to produce a
<a>math content box</a>. That <a>math content box</a> is used as the content for the layout of
the element, as described by CSS for <code>display: block</code>
(if the computed value is <code>block math</code>) or
<code>display: inline</code>
(if the computed value is <code>inline math</code>).
Additionally, if the computed
[^math/display^] property is equal to
<code>block math</code> then that <a>math content box</a> is rendered
horizontally centered within the content box.
</p>
<div class="note">
T<sub>E</sub>X's display mode <code>$$...$$</code>
and inline mode <code>$...$</code> correspond to
<code>display="block"</code> and <code>display="inline"</code>
respectively.
</div>
<div class="example" id="math-example">
<p>In the following example, a [^math^] formula
is rendered in display mode on a new line and taking full width,
with the math content centered within the container:</p>
<pre data-include="examples/example-math-display-block.html"
data-include-format="text"></pre>
<img src="examples/example-math-display-block.png" alt="math example (display)">
<p>As a comparison, the same formula would look as follows in
inline mode. The formula is embedded in the paragraph of text
without forced line breaking.
The baselines specified by the layout algorithm of the
[^mrow^] are used for vertical
alignment. Note that
the middle of sum and equal symbols or fractions are all aligned,
but not with the alphabetical baseline of the surrounding
text.</p>
<img src="examples/example-math-display-inline.png" alt="math example (inline)">
</div>
<p>Because good mathematical rendering requires use of mathematical
fonts, the
<a>user agent stylesheet</a>
should set the
<a data-xref-type="css-property">font-family</a>
to the
<a data-xref-for="font-family" data-xref-type="css-value">math</a>
value on the <code><math></code> element instead of inheriting
it. Additionally, several CSS properties that can be set on
a parent container such as
<code>font-style</code>, <code>font-weight</code>,
<code>direction</code> or <code>text-indent</code> etc
are not expected to apply to the math formula and so the
<a>user agent stylesheet</a>
has rules to reset them by default.
</p>
<pre class="css" data-include="user-agent-stylesheet/math.css"></pre>
</section>
<section id="types-for-mathml-attribute-values">
<h4>Types for MathML Attribute Values</h4>
<p>In addition to CSS data types, some MathML attributes rely on the following MathML-specific types:</p>
<dl>
<dt><dfn>unsigned-integer</dfn></dt>
<dd>An
<a data-xref-type="css-type" href="https://www.w3.org/TR/css-values-4/#integer-value"><integer></a> value as defined in
[[CSS-VALUES-4]], whose first character is neither
U+002D HYPHEN-MINUS character (-) nor
U+002B PLUS SIGN (+).
</dd>
<dt><dfn>boolean</dfn></dt>
<dd>A string that is an
<a>ASCII case-insensitive</a>
match to <code>true</code> or
<code>false</code>.
</dd>
</dl>
</section>
<section>
<h4>Global Attributes</h4>
<p>
The following attributes are common to and may be specified on all MathML
elements:
</p>
<ul>
<li><a><code>autofocus</code></a></li>
<li><a><code>class</code></a></li>
<li><a><code>data-*</code></a></li>
<li><a><code>dir</code></a></li>
<li><a><code>displaystyle</code></a></li>
<li><a><code>id</code></a></li>
<li><a><code>mathbackground</code></a></li>
<li><a><code>mathcolor</code></a></li>
<li><a><code>mathsize</code></a></li>
<li><a><code>nonce</code></a></li>
<li><a><code>scriptlevel</code></a></li>
<li><a><code>style</code></a></li>
<li><a><code>tabindex</code></a></li>
<li><a href="#event-handler-content-attributes"><code>on*</code> event handler attributes</a></li>
<li>additional attributes, as described in <a href="#other-valid-attributes"></a></li>
</ul>
</section>
<section id="attributes-common-to-html-and-mathml-elements">
<h4>Attributes common to HTML and MathML elements</h4>
<p>
The
<dfn class="element-attr no-export">id</dfn>,
<dfn class="element-attr no-export">class</dfn>,
<dfn class="element-attr no-export">style</dfn>,
<dfn class="no-export"><code>data-*</code></dfn>,
<dfn class="element-attr no-export">autofocus</dfn> and
<dfn class="element-attr no-export">nonce</dfn> and
<dfn class="element-attr no-export">tabindex</dfn>
attributes have the same syntax and semantics as defined for
[^global/id^],
[^global/class^],
[^html-global/style^],
<a data-cite="HTML/../#embedding-custom-non-visible-data-with-the-data-*-attributes">data-*</a>,
[^htmlsvg-global/autofocus^],
[^htmlsvg-global/nonce^] and
[^htmlsvg-global/tabindex^]
attributes on HTML elements.
</p>
<p>
The
<dfn class="element-attr">dir</dfn>
attribute, if present,
must be an
<a>ASCII case-insensitive</a> match
to <code>ltr</code> or <code>rtl</code>.
In that case, the user agent is expected to treat the attribute as a
<a data-cite="HTML/../#presentational-hints">presentational hint</a> setting the element's
<a data-xref-type="css-property">direction</a>
property to the corresponding value.
More precisely, an
<a>ASCII case-insensitive</a> match
to <code>rtl</code> is mapped to <code>rtl</code> while
an <a>ASCII case-insensitive</a> match to <code>ltr</code> is mapped to <code>ltr</code>.
</p>
<div class="note">
The <a>dir</a> attribute is used to set the directionality of math
formulas, which is often <code>rtl</code> in Arabic speaking world.
However, languages written from right to left often embed math
written from left to right and so the
<a>user agent stylesheet</a> resets
the
<a data-xref-type="css-property">direction</a>
property accordingly on the [^math^]
elements.
</div>
<div class="example" id="dir-example">
<p>
In the following example, the <a>dir</a> attribute
is used to render "𞸎 plus 𞸑 raised to the power of
(٢ over, 𞸟 plus ١)" from right-to-left.
</p>
<pre data-include="examples/example-dir.html"
data-include-format="text"></pre>
<img src="examples/example-dir.png" alt="dir example">
</div>
<p id="event-handler-content-attributes">
All MathML elements support event handler content attributes,
as described in <a>event handler content attributes</a> in HTML.
</p>
<p>
All event handler content attributes
<a data-cite="HTML/../#event-handlers-on-elements,-document-objects,-and-window-objects">noted by HTML as being supported by all HTMLElements</a>
are supported by all MathML elements as well, as defined in the <a href="#dom-and-javascript">MathMLElement IDL</a>.
</p>
</section>
<section id="legacy-mathml-style-attributes">
<h4>Legacy MathML Style Attributes</h4>
<p>
The
<dfn class="element-attr">mathcolor</dfn>
and
<dfn class="element-attr">mathbackground</dfn>
attributes, if present, must
have a value that is a
<a data-xref-type="css-type" href="https://www.w3.org/TR/css-color-4/#propdef-color"><color></a>.
In that case, the user agent is expected to treat these attributes as a
<a data-cite="HTML/../#presentational-hints">presentational hint</a> setting the element's
<a data-xref-type="css-property">color</a> and
<a data-xref-type="css-property">background-color</a>
properties to the corresponding values.
The <code>mathcolor</code> attribute describes the foreground fill
color of MathML text, bars etc
while the <code>mathbackground</code>
attribute describes the background color of an element.
</p>
<p>
The
<dfn class="element-attr">mathsize</dfn>
attribute, if present, must
have a value that is a valid <a data-xref-type="css-type" href="https://www.w3.org/TR/css-values-4/#typedef-length-percentage"><length-percentage></a>.
In that case, the user agent is expected to treat the attribute as a
<a data-cite="HTML/../#presentational-hints">presentational hint</a> setting the element's
<a data-xref-type="css-property">font-size</a>
property to the corresponding value.
The <code>mathsize</code> property indicates the desired height
of glyphs in math formulas but also scales other parts (spacing, shifts,
line thickness of bars etc) accordingly.
</p>
<div class="note">
The above attributes are implemented for compatibility with full MathML. Authors whose only target is MathML Core are encouraged to use CSS for styling.
</div>
</section>
<section id="the-displaystyle-and-scriptlevel-attributes">
<h4>The <code>displaystyle</code> and <code>scriptlevel</code> attributes</h4>
<p>
The
<dfn class="element-attr">displaystyle</dfn>
attribute, if present, must have a value that is a <a>boolean</a>.
In that case, the user agent is expected to treat the attribute as a
<a data-cite="HTML/../#presentational-hints">presentational hint</a> setting the element's
<a><code>math-style</code></a>
property to the corresponding value.
More precisely, an
<a>ASCII case-insensitive</a> match
to <code>true</code> is mapped to <code>normal</code> while
an <a>ASCII case-insensitive</a> match to <code>false</code> is mapped to <code>compact</code>.
This attribute indicates whether formulas should try to minimize
the logical height (value is <code>false</code>) or not
(value is <code>true</code>) e.g. by changing the size of content or
the layout of scripts.
</p>
<p>
The
<dfn class="element-attr">scriptlevel</dfn>
attribute, if present, must have value
<code>+<U></code>, <code>-<U></code> or <code><U></code>
where <code><U></code> is an
<a>unsigned-integer</a>.
In that case
the user agent is expected to treat the <code>scriptlevel</code>
attribute as a
<a data-cite="HTML/../#presentational-hints">presentational hint</a> setting the element's
<a><code>math-depth</code></a>
property to the corresponding value.
More precisely,
<code>+<U></code>, <code>-<U></code> and
<code><U></code>
are respectively mapped to
<code>add(<U>)</code>
<code>add(<-U>)</code>
and <code><U></code>.
</p>
<p>
<a><code>displaystyle</code></a> and <a><code>scriptlevel</code></a> values
are automatically adjusted within MathML elements.
To fully implement these attributes, additional CSS properties must be
specified in the user agent stylesheet
as described in <a href="#user-agent-stylesheet"></a>.
In particular, for all MathML elements a default
<code>font-size: math</code> is specified to ensure that
<code>scriptlevel</code> changes are taken into account.
</p>
<div class="example" id="displaystyle-scriptlevel-example">
<p>
In this example, an [^munder^]
element is used to attach a
script "A" to a base "∑". By default, the summation
symbol is rendered with the font-size inherited from its
parent and the A as a scaled down subscript.
If <a>displaystyle</a> is true, the summation symbol is drawn
bigger and the "A" becomes an underscript.
If <a>scriptlevel</a> is reset to 0 on the "A", then it will
use the same font-size as the top-level <code>math</code> root.
</p>
<pre data-include="examples/example-displaystyle-scriptlevel.html"
data-include-format="text"></pre>
<img src="examples/example-displaystyle-scriptlevel.png" alt="displaystyle-scriptlevel example">
</div>
<div class="note">
T<sub>E</sub>X's <code>\displaystyle</code>, <code>\textstyle</code>,
<code>\scriptstyle</code>, and <code>\scriptscriptstyle</code> correspond
to <a><code>displaystyle</code></a> and <a><code>scriptlevel</code></a> as
<code>true</code> and <code>0</code>,
<code>false</code> and <code>0</code>,
<code>false</code> and <code>1</code>,
and <code>false</code> and 2, respectively.
</div>
</section>
<section id="other-valid-attributes">
<h4>Attributes Reserved as Valid</h4>
<p>The attributes
<dfn class="element-attr">intent</dfn> and <dfn class="element-attr">arg</dfn>
are reserved as valid attributes.</p>
<p>
This specification does not define any observable behavior that is
specific to the <a><code>intent</code></a> and <a><code>arg</code></a> attributes.
</p>
<div class="note">
These attributes are described in [[MATHML4]] and
future versions of this specification may or may not
define them. Authors should be aware that they are currently
in development and subject to change.
</div>
</section>
</section>
<section>
<h3>Integration in the Web Platform</h3>
<section id="html-and-svg">
<h4>HTML and SVG</h4>
<p>
MathML can be mixed with HTML and SVG as described in the relevant
specifications [[HTML]] [[SVG]].
</p>
<p>
When evaluating the SVG [^svg/requiredExtensions^]
attribute, user agents must claim support for the language extension
identified by the
<a>MathML namespace</a>.
</p>
<div class="example" id="html-svg-example">
<p>
In this example, inline MathML and SVG elements are used inside
an HTML document. SVG elements <code><switch></code> and
<code><foreignObject></code> (with
proper <code><requiredExtensions></code>) are used to
embed a MathML formula with a text fallback, inside a diagram.
HTML <code>input</code> element is used within the
[^mtext^]
to include an interactive input field inside a mathematical
formula. See also <a href="#semantics-and-presentation"></a>
for an example of SVG and HTML inside an [^annotation-xml^]
element.
</p>
<pre data-include="examples/example-html-svg.html"
data-include-format="text"></pre>
<img src="examples/example-html-svg.png" alt="html-svg example">
</div>
</section>
<section id="css-styling">
<h4>CSS styling</h4>
<p>User agents must support various CSS features mentioned in this
specification, including new ones described in
<a href="#css-extensions-for-math-layout"></a>.
They must follow the computation rule for
<a data-cite="CSS-DISPLAY-3#unbox-mathml">display: contents</a>.
</p>
<div class="example" id="style-example">
<p>
In this example, the MathML formula inherits the CSS color of its
parent and uses the <code>font-family</code> specified via the
<a>style</a> attribute.
</p>
<pre data-include="examples/example-style.html"
data-include-format="text"></pre>
<img src="examples/example-style.png" alt="style example">
</div>
<p>
All documents containing <a>MathML Core elements</a> must include
CSS rules described in <a href="#user-agent-stylesheet"></a>
as part of user-agent level style sheet defaults.
In particular, this adds <code>!important</code> rules to force
<a>writing mode</a>
to <code>horizontal-lr</code> on all MathML elements.
</p>
<p>
The <a data-cite="CSS22" data-xref-type="css-property">float</a>
property does
not create floating of elements whose parent's computed
<code>display</code> value is
<code>block math</code> or <code>inline math</code>,
and does not take them out-of-flow.
</p>
<p>
The <a data-xref-type="css-selector">::first-line</a> and
<a data-xref-type="css-selector">::first-letter</a>
pseudo-elements do not apply to elements whose computed
<code>display</code> value is
<code>block math</code> or <code>inline math</code>, and such
elements do not contribute a first formatted line or first letter
to their ancestors.
</p>
<p>
The following CSS features are not supported and must be ignored:
</p>
<ul>
<li>
Line breaking inside math formulas:
<code>white-space</code>
is treated as <code>nowrap</code> on all MathML elements.
</li>
<li>
Alignment properties:
<code>align-content</code>, <code>justify-content</code>,
<code>align-self</code>, <code>justify-self</code> have
no effects on MathML elements.
</li>
</ul>
<div class="note">
These features might be handled in future versions of this document.
For now, authors are discouraged from setting a different value for
these properties as that might lead to backward incompatibility
issues.
</div>
</section>
<section id="dom-and-javascript">
<h4>DOM and JavaScript</h4>
<p>
User agents supporting
<a data-cite="HTML/../#webappapis">Web application APIs</a>
must ensure that they keep the visual rendering of MathML
synchronized with the [[DOM]] tree, in particular perform necessary
updates when <a>MathML attributes</a> are modified dynamically.
</p>
<p>
All the nodes representing <a>MathML elements</a> in the DOM
must implement, and expose to scripts, the following
<dfn class="interface">MathMLElement</dfn> interface.
</p>
<pre class="idl" data-include="webidl/MathMLElement.idl"></pre>
<p>The {{GlobalEventHandlers}} and
<dfn class="interface" data-cite="HTML/../#htmlorsvgelement"><code>HTMLOrForeignElement</code></dfn>
interfaces are defined in [[HTML]].</p>
<div class="example" id="dom-idl-example">
<p>
In the following example, a MathML formula is used to render
the fraction "α over 2". When clicking the red α, it is changed
into a blue β.
</p>
<pre data-include="examples/example-dom-idl.html"
data-include-format="text"></pre>
<img src="examples/example-dom-idl.png" alt="dom-idl example">
</div>
<div class="issue">
<a href="https://github.com/whatwg/html/pull/5248">Rename
HTMLOrSVGElement</a> and define MathMLElement in [[HTML]].
</div>
</section>
<section id="text-layout">
<h4>Text layout</h4>
<p>
Because math fonts generally contain very tall glyphs such as big
integrals, using typographic metrics is important to avoid
excessive line spacing of text. As a consequence,
user agents must take into account the USE_TYPO_METRICS flag from
the OS/2 table [[OPEN-FONT-FORMAT]] when performing text layout.
</p>
</section>
<section id="focus">
<h4>Focus</h4>
<p>
MathML provides the ability for authors to allow for
interactivity in supporting interactive user agents
using the same concepts, approach and guidance to
<a data-cite="HTML/../#focus"><code>Focus</code></a>
as described in HTML, with modifications or
clarifications regarding application
for MathML as described in this section.
</p>
<p>
When an element is focused, all applicable CSS
focus-related pseudo-classes as defined in
<a data-cite="SELECT#title">Selectors Level 3</a>
apply, as defined in that specification.
</p>
<p>
The contents of embedded [^math^] elements
(including HTML elements inside token elements)
contribute to the sequential focus order of the containing owner HTML
document (combined sequential focus order).
</p>
</section>
</section>
</section>
<section class="normative">
<h2>Presentation Markup</h2>
<section>
<h3>Visual formatting model</h3>
<section>
<h4>Box Model</h4>
<p>
The default [^math/display^] property
is described in <a href="#user-agent-stylesheet"></a>:
</p>
<ul>
<li>
For the <code><math></code> root,
it is equal to <code>inline math</code> or <code>block math</code>
according to the value of the [^math/display^] attribute.
</li>
<li>
For <a href="#tabular-math">Tabular MathML elements</a>
[^mtable^],
[^mtr^],
[^mtd^] it is respectively equal to
<code>inline-table</code>,
<code>table-row</code> and
<code>table-cell</code>.
</li>
<li>For all but the first children of the [^maction^]
and [^semantics^] elements, it is equal to
<code>none</code>.
</li>
<li>
For all the other <a>MathML elements</a> it is equal
to <code>block math</code>.
</li>
</ul>
<p>
In order to specify math layout in different
<a>writing modes</a>,
this specification uses concepts from [[CSS-WRITING-MODES-4]]:
</p>
<ul>
<li>
<a>abstract dimensions</a>:
<a>block dimension</a>,
<a>inline dimension</a>,
<a>block axis</a>,
<a>inline axis</a>,
<a>block size</a>,
<a>inline size</a>.
</li>
<li>
<a>flow-relative directions</a>:
<a>inline-start</a>,
<a>inline-end</a>,
<a>block-start</a>.
</li>
<li>
<a>line-relative directions</a>:
<a>line-left</a>,
<a>line-over</a>,
<a>line-under</a>.
</li>
</ul>
<div class="note">
Unless specified otherwise,
the figures in this specification use a
<a>writing mode</a>
of <code>horizontal-lr</code> and <code>ltr</code>.
See <a href="#box-model-horizontal-tb-rtl"></a>,
<a href="#box-model-vertical-lr"></a> and
<a href="#box-model-vertical-rl"></a> for examples of other
writing modes that are sometimes used for math layout.
</div>
<p>
Boxes used for MathML elements rely on several parameters in order to perform layout
in a way that is compatible with CSS but also to take into account
very accurate positions and spacing within math formulas:
</p>
<ol>
<li>Inline metrics.
<a>min-content inline size</a>,
<a>max-content inline size</a> and
<a>inline size</a>
from CSS. See <a href="#box-model-generic"></a>.
<figure id="box-model-generic">
<img src="figures/horizontal-tb-ltr.svg">
<figcaption>Generic Box Model for MathML elements</figcaption>
</figure>
</li>
<li>
<p>
Block metrics.
The <a>block size</a>,
<a>first baseline set</a>
and
<a>last baseline set</a>.
The following <a>baselines</a> are defined for MathML boxes:
</p>
<ol>
<li>
The <dfn>alphabetic baseline</dfn>
which typically aligns with the bottom of uppercase Latin
glyphs. The algebraic distance from the
<a>alphabetic baseline</a> to the <a>line-over</a> edge of the box is called the
<dfn>line-ascent</dfn>. The algebraic distance from the
<a>line-under</a> edge to the <a>alphabetic baseline</a> of the box
is called the <dfn>line-descent</dfn>.
</li>
<li>
The <dfn>mathematical baseline</dfn>, also called
<dfn>math axis</dfn>, which typically aligns with the fraction
bar, middle of fences and binary operators. It is shifted away from the <a>alphabetic baseline</a> by <a>AxisHeight</a> towards the <a>line-over</a>.
</li>
<li>
The <dfn>ink-over baseline</dfn>, indicating the <a>line-over</a>
theorical limit of the math content drawn, excluding any
extra space.
If not specified, it is aligned with the <a>line-over</a> edge.
The algebraic distance from the <a>alphabetic baseline</a> to
the <a>ink-over baseline</a> is called the
<dfn>ink line-ascent</dfn>.
</li>
<li>
The <dfn>ink-under baseline</dfn>, indicating the <a>line-under</a>
theorical limit of the math content drawn, excluding any
extra space.
If not specified, it is aligned with the <a>line-under</a> edge.
The algebraic distance from the <a>ink-under baseline</a>
to the <a>alphabetic baseline</a> is called the
<dfn>ink line-descent</dfn>.
</li>
</ol>
<div class="note">
For math layout, it is very important to rely on the ink extent
when positioning text. This is not the case for more complex
notations (e.g. square root).
Although ink-ascent and ink-descent are defined for
all MathML elements they are really only used for the token
elements. In other cases, they just match normal ascent and
descent.
</div>
Unless specified otherwise, the <a>last baseline set</a> is equal to the
<a>first baseline set</a> for MathML boxes.
</li>
<li>
An optional <dfn>italic correction</dfn>
which provides a measure of how much the text of a box is
slanted along the <a>inline axis</a>.
See <a href="#figure-italic-correction"></a>.
<figure id="figure-italic-correction">
<img src="figures/italcorr.svg">
<figcaption>Examples of italic correction for italic f and large integral</figcaption>
</figure>
If it is requested during calculation of
<a>min-content inline size</a> and
<a>max-content inline size</a> or during layout
then 0 is used as a fallback value.
</li>
<li>
An optional <dfn>top accent attachment</dfn>
which provides a reference offset on the
<a>inline axis</a> of a box that should be used when
positioning that box as an accent.
See <a href="#figure-top-accent-attachment"></a>.
<figure id="figure-top-accent-attachment">
<img src="figures/topaccent.svg">
<figcaption>Example of top accent attachment for a circumflex accent</figcaption>
</figure>
If it is requested during calculation of
<a>min-content inline size</a>
(respectively <a>max-content inline size</a>) then half the
<a>min-content inline size</a> (respectively <a>max-content inline size</a>) is used as a
fallback value.
If it is requested during layout then half the
inline size of the box is used as a fallback value.
</li>
</ol>
<p>Given a MathML box, the following offsets are defined:</p>
<ul>
<li>The <dfn>inline offset</dfn> of a child box
is the offset between the
<a>inline-start</a> edge of
the parent box and the
<a>inline-start</a> edge
of the child box.</li>
<li>The <dfn>block offset</dfn> of a child box
is the offset between the <a>block-start</a> edge of
the parent box and the
<a>block-start</a> edge
of the child box.</li>
<li>The <dfn>line-left offset</dfn> of a child box
is the offset between the <a>line-left</a> edge of
the parent box and the
<a>line-left</a> edge
of the child box.</li>
</ul>
<figure id="box-model-horizontal-tb-rtl">
<img src="figures/horizontal-tb-rtl.svg">
<figcaption>Box model for writing mode <code>horizontal-tb</code> and <code>rtl</code> that may be used in e.g. Arabic math.</figcaption>
</figure>
<figure id="box-model-vertical-lr">
<img src="figures/vertical-lr.svg">
<figcaption>Box model for writing mode <code>vertical-lr</code> and <code>ltr</code> that may be used in e.g. Mongolian math.</figcaption>
</figure>
<figure id="box-model-vertical-rl">
<img src="figures/vertical-rl.svg">
<figcaption>Box model for writing mode <code>vertical-rl</code> and <code>ltr</code> that may be used in e.g. Japanese math.</figcaption>
</figure>
<div class="note">
The position of child boxes and graphical items inside a MathML
box are expressed using the <a>inline offset</a>
and <a>block offset</a>.
For convenience, the layout algorithms may describe offsets using
flow-relative directions, line-relative directions or
the <a>alphabetic baseline</a>.
It is always possible to pass from one description to the other
because position of child boxes is always performed after the
metrics of the box and of its child boxes are calculated.
</div>
<div class="example">
<p>Here are examples of offsets obtained from line-relative
metrics:</p>
<ul>
<li>
The <a>inline offset</a> of a child box is
the <a>line-left offset</a> if the CSS property
<a data-xref-type="css-property">direction</a>
is <code>ltr</code> and
is the <a>inline size</a> of the box −
(<a>line-left offset</a> + <a>inline size</a> of
the child box) otherwise.
</li>
<li>
The <a>block offset</a> of the <a>alphabetic baseline</a> of a box
is the <a>line-ascent</a>
if the CSS property
<a data-xref-type="css-property">writing-mode</a>
is <code>horizontal-lr</code>,
<code>vertical-rl</code> or <code>sideways-rl</code>
and is the <a>line-descent</a> otherwise.
</li>
</ul>
</div>
<div class="issue" data-number="78">Improve definition of ink ascent/descent?</div>
</section>
<section id="layout-algorithms">
<h4>Layout Algorithms</h4>
<p>
Each MathML element has an associated <dfn>math content box</dfn>, which is
calculated as described in this chapter's layout algorithms using the following
structure:
</p>
<ol>
<li>