[LyX/master] MathML: make InsetMathHull::mathmlize easier to read while doing less work

Thibaut Cuvelier tcuvelier at lyx.org
Sat Jan 21 23:49:46 UTC 2023


commit d066a66a51b423ece3588198b6d29a9a67ac49b5
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Jan 22 01:49:03 2023 +0100

    MathML: make InsetMathHull::mathmlize easier to read while doing less work
    
    If `havetable == true`, a lot of the code didn't make any sense: in particular, it was outputting a level of <m:mrow> too many.
    
    Also, add some comments and rewrite the comment about mlabeledtr.
    
    Contributed by lynx: https://www.lyx.org/trac/ticket/12629
---
 src/mathed/InsetMathHull.cpp |   52 ++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 8fbd5c2..9c4e6e9 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2532,33 +2532,37 @@ void InsetMathHull::mathmlize(MathMLStream & ms) const
 {
 	bool const havetable = haveNumbers() || nrows() > 1 || ncols() > 1;
 
-    if (havetable) {
-        if (getType() == hullSimple) {
-	        ms << MTag("mtable");
-        } else if (getType() >= hullAlign && getType() <= hullXXAlignAt) {
-            string alignment;
-            for (col_type col = 0; col < ncols(); ++col) {
-                alignment += (col % 2) ? "left " : "right ";
-            }
-            ms << MTag("mtable", "displaystyle='true' columnalign='" + alignment + "'");
-	    } else {
-	        ms << MTag("mtable", "displaystyle='true'");
+	// Simplest case: single row, single column, no numbering.
+	if (!havetable) {
+		ms << cell(index(0, 0));
+		return;
+	}
+
+	// More complex case: wrap elements in a table.
+    if (getType() == hullSimple) {
+        ms << MTag("mtable");
+    } else if (getType() >= hullAlign && getType() <= hullXXAlignAt) {
+		// hullAlign, hullAlignAt, hullXAlignAt, hullXXAlignAt
+        string alignment;
+        for (col_type col = 0; col < ncols(); ++col) {
+            alignment += (col % 2) ? "left " : "right ";
         }
+        ms << MTag("mtable", "displaystyle='true' columnalign='" + alignment + "'");
+    } else {
+        ms << MTag("mtable", "displaystyle='true'");
     }
 
-	char const * const celltag = havetable ? "mtd" : "mrow";
-	// FIXME There does not seem to be wide support at the moment
-	// for mlabeledtr, so we have to use just mtr for now.
-	// char const * const rowtag = haveNumbers() ? "mlabeledtr" : "mtr";
-	char const * const rowtag = "mtr";
 	for (row_type row = 0; row < nrows(); ++row) {
-		if (havetable)
-			ms << MTag(rowtag);
+		// No Wed browser supports mlabeledtr in 2023, even though it has been introduced in
+		// MathML 2 (2003). Moreover, it is not supported in MathML 4 Core.
+		ms << MTag("mtr");
+
 		for (col_type col = 0; col < ncols(); ++col) {
-			ms << MTag(celltag)
+			ms << MTag("mtd")
 			   << cell(index(row, col))
-			   << ETag(celltag);
+			   << ETag("mtd");
 		}
+
 		// fleqn?
 		if (haveNumbers()) {
 			ms << MTag("mtd");
@@ -2567,11 +2571,11 @@ void InsetMathHull::mathmlize(MathMLStream & ms) const
 				ms << MTagInline("mtext") << '(' << num << ')' << ETagInline("mtext");
 		    ms << ETag("mtd");
 		}
-		if (havetable)
-			ms << ETag(rowtag);
+
+		ms << ETag("mtr");
 	}
-	if (havetable)
-		ms << ETag("mtable");
+
+	ms << ETag("mtable");
 }
 
 


More information about the lyx-cvs mailing list