{"id":142,"date":"2020-10-25T21:44:19","date_gmt":"2020-10-26T04:44:19","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/math-in-office\/?p=142"},"modified":"2020-11-25T12:04:06","modified_gmt":"2020-11-25T20:04:06","slug":"mathml-element-deprecated-on-web","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/math-in-office\/mathml-element-deprecated-on-web\/","title":{"rendered":"MathML mfenced element deprecated on web"},"content":{"rendered":"<p>The MathML working group is planning to <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/MathML\/Element\/mfenced\">deprecate the &lt;mfenced&gt; element<\/a> as well as the &lt;mo&gt; fence and separator attributes for use on the web. The justification is to simplify web implementations by deprecating MathML features that are redundant. This post explains how &lt;mfenced&gt; and the fence and separator attributes can be handled in other ways and it discusses the implications for <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/murrays\/officemath\">OfficeMath<\/a>.<\/p>\n<h2>Emulating &lt;mfenced&gt; with &lt;mrow&gt;<\/h2>\n<p>The MathML &lt;mfenced&gt; element is handy for representing a variety of delimited expressions, such as parenthesized, braced, and bracketed expressions. The expressions can contain separators. Examples are (\ud835\udc4e + \ud835\udc4f), (\ud835\udc4e + \ud835\udc4f], and the quantum mechanical expectation value \u27e8\ud835\udf13|\u210b|\ud835\udf13\u27e9, in which the \u2018|\u2019 is a separator. The &lt;mfenced&gt; element corresponds quite closely to the <a href=\"https:\/\/docs.microsoft.com\/en-us\/archive\/blogs\/murrays\/omml-specification-version-2\">OMML<\/a> delimiters element &lt;d&gt; used in Office app files, which is why the OfficeMath MathML writers use it.<\/p>\n<p>To show how &lt;mfenced&gt; can be emulated by an &lt;mrow&gt;, consider (\ud835\udc4e + \ud835\udc4f]. Using &lt;mfenced&gt;, it is represented by<\/p>\n<pre><code>\u00a0 \u00a0&lt;mfenced close=\"]\"&gt;\r\n<\/code> <code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;mi&gt;a&lt;\/mi&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mi&gt;b&lt;\/mi&gt;\r\n<\/code><code>\u00a0\u00a0 &lt;\/mfenced&gt;<\/code><\/pre>\n<p>Since left parenthesis is the default start delimiter, the &lt;mfenced&gt; doesn\u2019t need the attribute open=&#8221;(&#8220;, although it could have it. The equivalent &lt;mrow&gt; representation is<\/p>\n<pre><code>\u00a0\u00a0 &lt;mrow&gt;\r\n<\/code><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;mo&gt;(&lt;\/mo&gt;\r\n<\/code> <code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt; mi&gt;a&lt;\/mi&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mi&gt;b&lt;\/mi&gt;\r\n<\/code> <code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;mo&gt;]&lt;\/mo&gt;\r\n<\/code> <code> \u00a0&lt;\/mrow&gt;<\/code><\/pre>\n<p>Here the &lt;mo&gt; fence=&#8221;true&#8221; attribute isn\u2019t needed since the MathML operator dictionary assigns fence=&#8221;true&#8221; to parentheses, brackets, braces and other Unicode characters that are fences by default. You need the attribute fence=&#8221;false&#8221; or stretchy=&#8221;false&#8221; if you don\u2019t want the delimiters to grow to fit their content.<\/p>\n<p>Comparing these representations, we see that &lt;mfenced&gt; is more compact. On the other hand, the &lt;mrow&gt; emulation is more general in that you can include attributes like different math colors on the individual delimiters and you can embellish the delimiters with accents. If you want a delimited expression with just the open delimiter, e.g., {\ud835\udc4e + \ud835\udc4f, you omit the &lt;mo&gt; for the close delimiter. Similarly, a delimited expression with no open delimiter, e.g., \ud835\udc4e + \ud835\udc4f}, omits the open delimiter. For more discussion of &lt;mfenced&gt; and &lt;mrow&gt;, see the <a href=\"https:\/\/www.w3.org\/TR\/MathML3\/chapter3.html#presm.mo\">MathML 3.0 spec<\/a>.<\/p>\n<h2>Parsing &lt;mrow&gt; emulation of &lt;mfenced&gt;<\/h2>\n<p>The &lt;mfenced&gt; element is an example of Polish prefix notation: you know up front what kind of math object is involved. In contrast, you must parse an &lt;mrow&gt; emulation of &lt;mfenced&gt; to figure out what it represents. The parsing is a little tricky, but it\u2019s not that hard since the delimiter roles are implied by the order in which the delimiters appear inside the &lt;mrow&gt;.<\/p>\n<p>The basic principle is that the start and end delimiters are fences, and any delimiters in between are separators. The main OfficeMath MathML reader uses a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Simple_API_for_XML\">SAX parser<\/a>, which cannot look ahead. But the reader can store information for looking behind. The algorithm is: the first delimiter of an &lt;mrow&gt; is a start delimiter &lt;mo&gt; and other delimiters are marked as separators. When the parser comes to the end of the delimiter expression (&lt;\/mrow&gt;), it remarks the last delimiter as an end delimiter. If there are only two delimiters, there are no separators. If there\u2019s only one delimiter, it\u2019s a start delimiter unless it comes at the end. This algorithm converts &lt;mrow&gt; delimiter elements into the OfficeMath &lt;d&gt; equivalent. It will be used soon in Office apps since FireFox removed support of &lt;mfenced&gt; (OneNote counted on it in FireFox!) and the Chromium code base won\u2019t support it either. Yes, Chromium will support \u201ccore\u201d Presentation MathML. Many browsers are based on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chromium_(web_browser)\">Chromium<\/a>, e.g., Chrome and Edge.<\/p>\n<p>Some MathML elements are \u201cinferred mrow\u2019s\u201d in that they treat multiple children as a single argument and the algorithm works with them as well. Such elements include &lt;math&gt;, &lt;msqrt&gt;, &lt;menclose&gt;, &lt;mphantom&gt;, &lt;mpadded&gt; and &lt;mtd&gt;.<\/p>\n<h2>Poorly formed &lt;mrow&gt; expressions<\/h2>\n<p>Best practice &lt;mrow&gt; delimiter emulation restricts the contents of the &lt;mrow&gt; to the contents of the delimited expression. But what if there are other things inside an &lt;mrow&gt; such as in (note: &lt;math&gt; is an inferred &lt;mrow&gt;)<\/p>\n<pre style=\"padding-left: 40px;\">&lt;math &gt;\r\n   &lt;mo&gt;(&lt;\/mo&gt;\r\n   &lt;mi&gt;a&lt;\/mi&gt;\r\n   &lt;mo&gt;+&lt;\/mo&gt;\r\n   &lt;mi&gt;b&lt;\/mi&gt;\r\n   &lt;mo&gt;)&lt;\/mo&gt;\r\n   &lt;mo&gt;+&lt;\/mo&gt;\r\n   &lt;mo&gt;|&lt;\/mo&gt;\r\n   &lt;mi&gt;a&lt;\/mi&gt;\r\n   &lt;mo&gt;+&lt;\/mo&gt;\r\n   &lt;mi&gt;b&lt;\/mi&gt;\r\n   &lt;mo&gt;|&lt;\/mo&gt;\r\n&lt;\/math&gt;\r\n<\/pre>\n<p>Two tricks are useful: with no form-disambiguating attribute like \u201cform\u201d=\u201dprefix\u201d on the delimiter &lt;mo&gt;\u2019s (as in this example), use the default form value given in the MathML <a href=\"https:\/\/www.w3.org\/TR\/MathML3\/appendixc.html\">operator dictionary<\/a>. This works for all default delimiter pairs, but not for \u2018|\u2019 which can be used as a separator (infix), open delimiter (prefix), or close delimiter (postfix). For \u2018|\u2019 use the algorithm above with a small twist: when there is an active \u2018|\u2019 start delimiter, treat a \u2018|\u2019 as an end delimiter. When finished processing any delimiter expression, reset the state to \u201cno delimiters\u201d. As such \u2018|\u2019 is alternately a start delimiter and end delimiter. This algorithm cannot produce nested absolute-value expressions. To nest an absolute value, use appropriate form attributes, or, best practice, put the absolute value in its own &lt;mrow&gt;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The MathML working group is planning to deprecate the &lt;mfenced&gt; element as well as the &lt;mo&gt; fence and separator attributes for use on the web. The justification is to simplify web implementations by deprecating MathML features that are redundant. This post explains how &lt;mfenced&gt; and the fence and separator attributes can be handled in other [&hellip;]<\/p>\n","protected":false},"author":40611,"featured_media":55,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-math-in-office"],"acf":[],"blog_post_summary":"<p>The MathML working group is planning to deprecate the &lt;mfenced&gt; element as well as the &lt;mo&gt; fence and separator attributes for use on the web. The justification is to simplify web implementations by deprecating MathML features that are redundant. This post explains how &lt;mfenced&gt; and the fence and separator attributes can be handled in other [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/users\/40611"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/media\/55"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/math-in-office\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}