Repository: KaTeX/KaTeX (js)

Issue:
Display mode doesn't work for MathML output
**Describe the bug:**
Display mode does not work for MathML output (it does for HTML output).

**To Reproduce:**
Render any expression, using the options `{displayMode: true, output: 'mathml'}`.
See [JSFiddle](https://jsfiddle.net/2b497Ls0/).

**Expected behavior:**
Expression renders in display mode, i.e.&nbsp;display-style math centred on its own line.

**Actual behavior:**
Expression appears to render in inline mode.

**Screenshot:**
<img src="https://user-images.githubusercontent.com/48375680/77227660-cfa5e180-6bbc-11ea-9d99-977e65fff34a.png" width="300px">

**Environment:**
 - KaTeX Version: 0.11.1
 - Browser: any browser which supports MathML


Pull request:
Support MathML display mode
Fix #2219.

Patch:
diff --git a/src/buildMathML.js b/src/buildMathML.js
index 70bc0dd4..4bde4934 100644
--- a/src/buildMathML.js
+++ b/src/buildMathML.js
@@ -238,6 +238,7 @@ export default function buildMathML(
     tree: AnyParseNode[],
     texExpression: string,
     options: Options,
+    isDisplayMode: boolean,
     forMathmlOnly: boolean,
 ): DomSpan {
     const expression = buildExpression(tree, options);
@@ -263,6 +264,9 @@ export default function buildMathML(
 
     const math = new mathMLTree.MathNode("math", [semantics]);
     math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
+    if (isDisplayMode) {
+        math.setAttribute("display", "block");
+    }
 
     // You can't style <math> nodes, so we wrap the node in a span.
     // NOTE: The span class is not typed to have <math> nodes as children, and
diff --git a/src/buildTree.js b/src/buildTree.js
index 61d301ac..d7ad29c7 100644
--- a/src/buildTree.js
+++ b/src/buildTree.js
@@ -39,12 +39,13 @@ export const buildTree = function(
     const options = optionsFromSettings(settings);
     let katexNode;
     if (settings.output === "mathml") {
-        return  buildMathML(tree, expression, options, true);
+        return  buildMathML(tree, expression, options, settings.displayMode, true);
     } else if (settings.output === "html") {
         const htmlNode = buildHTML(tree, options);
         katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
     } else {
-        const mathMLNode = buildMathML(tree, expression, options, false);
+        const mathMLNode = buildMathML(tree, expression, options,
+            settings.displayMode, false);
         const htmlNode = buildHTML(tree, options);
         katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, htmlNode]);
     }


Test patch:
diff --git a/test/__snapshots__/mathml-spec.js.snap b/test/__snapshots__/mathml-spec.js.snap
index 535de1f0..9f4c3401 100644
--- a/test/__snapshots__/mathml-spec.js.snap
+++ b/test/__snapshots__/mathml-spec.js.snap
@@ -359,7 +359,9 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} correc
 
 exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} in displaymode correctly 1`] = `
 
-<math xmlns="http://www.w3.org/1998/Math/MathML">
+<math xmlns="http://www.w3.org/1998/Math/MathML"
+      display="block"
+>
   <semantics>
     <mrow>
       <munder>
@@ -766,7 +768,9 @@ exports[`A MathML builder special spaces render specially 1`] = `
 
 exports[`A MathML builder tags use <mlabeledtr> 1`] = `
 
-<math xmlns="http://www.w3.org/1998/Math/MathML">
+<math xmlns="http://www.w3.org/1998/Math/MathML"
+      display="block"
+>
   <semantics>
     <mtable width="100%">
       <mtr>
diff --git a/test/mathml-spec.js b/test/mathml-spec.js
index 5a1314ac..4180342f 100644
--- a/test/mathml-spec.js
+++ b/test/mathml-spec.js
@@ -20,7 +20,8 @@ const getMathML = function(expr, settings = new Settings()) {
         maxSize: Infinity,
     });
 
-    const built = buildMathML(parseTree(expr, settings), expr, options);
+    const built = buildMathML(parseTree(expr, settings), expr, options,
+        settings.displayMode);
 
     // Strip off the surrounding <span>
     return built.children[0].toMarkup();