From 0271602b8d2e2b6e5b4767d28ad2a0f0da823066 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Tue, 18 Apr 2017 23:53:27 +0200 Subject: [PATCH] - backport fix for bug #10466 Handle the command \multicolumn correctly in math macros --- src/mathed/InsetMathAMSArray.h | 3 ++ src/mathed/InsetMathArray.h | 3 ++ src/mathed/InsetMathCases.h | 3 ++ src/mathed/InsetMathGrid.h | 2 ++ src/mathed/InsetMathHull.cpp | 1 - src/mathed/InsetMathMatrix.h | 2 ++ src/mathed/InsetMathSplit.cpp | 5 ---- src/mathed/InsetMathTabular.h | 2 ++ src/mathed/MathParser.cpp | 55 ++++++++++++++++++---------------- status.22x | 4 ++- 10 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/mathed/InsetMathAMSArray.h b/src/mathed/InsetMathAMSArray.h index ceb3069c28..e5151f11bb 100644 --- a/src/mathed/InsetMathAMSArray.h +++ b/src/mathed/InsetMathAMSArray.h @@ -54,6 +54,9 @@ public: char const * name_left() const; /// char const * name_right() const; + /// + bool handlesMulticolumn() const { return true; } //override + private: virtual Inset * clone() const; /// diff --git a/src/mathed/InsetMathArray.h b/src/mathed/InsetMathArray.h index 79236882c7..f01887ca29 100644 --- a/src/mathed/InsetMathArray.h +++ b/src/mathed/InsetMathArray.h @@ -51,6 +51,9 @@ public: void validate(LaTeXFeatures & features) const; /// InsetCode lyxCode() const { return MATH_ARRAY_CODE; } + /// + bool handlesMulticolumn() const { return true; } //override + private: virtual Inset * clone() const; /// diff --git a/src/mathed/InsetMathCases.h b/src/mathed/InsetMathCases.h index 7820922f07..c0d9abfef7 100644 --- a/src/mathed/InsetMathCases.h +++ b/src/mathed/InsetMathCases.h @@ -54,6 +54,9 @@ public: InsetCode lyxCode() const { return MATH_CASES_CODE; } /// int displayColSpace(col_type) const; + /// see e.g. https://tex.stackexchange.com/a/133283/87201 + bool handlesMulticolumn() const { return true; } //override + private: virtual Inset * clone() const; }; diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 426d941f19..1ea2e2781c 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -221,6 +221,8 @@ public: virtual int vlinesep() const; /// virtual int border() const; + /// + virtual bool handlesMulticolumn() const { return false; } /// void write(WriteStream & os) const; diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index cd069c3da5..d82e934d17 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -15,7 +15,6 @@ #include "InsetMathChar.h" #include "InsetMathColor.h" #include "InsetMathFrac.h" -#include "InsetMathGrid.h" #include "InsetMathNest.h" #include "InsetMathScript.h" #include "MathExtern.h" diff --git a/src/mathed/InsetMathMatrix.h b/src/mathed/InsetMathMatrix.h index 26a8544026..95829ac239 100644 --- a/src/mathed/InsetMathMatrix.h +++ b/src/mathed/InsetMathMatrix.h @@ -47,6 +47,8 @@ public: void octave(OctaveStream &) const; /// InsetCode lyxCode() const { return MATH_MATRIX_CODE; } + /// + bool handlesMulticolumn() const { return true; } //override private: virtual Inset * clone() const; diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp index e385e0a09a..fb2ecbe083 100644 --- a/src/mathed/InsetMathSplit.cpp +++ b/src/mathed/InsetMathSplit.cpp @@ -48,11 +48,6 @@ Inset * InsetMathSplit::clone() const } -// FIXME: InsetMathGrid should be changed to let the real column alignment be -// given by a virtual method like displayColAlign, because the values produced -// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect -// that for the moment the values produced by defaultColAlign are not used, -// notably because alignment is not implemented in the LyXHTML output. char InsetMathSplit::defaultColAlign(col_type col) { if (name_ == "gathered") diff --git a/src/mathed/InsetMathTabular.h b/src/mathed/InsetMathTabular.h index a4aa50f1b9..8fb06bd2c9 100644 --- a/src/mathed/InsetMathTabular.h +++ b/src/mathed/InsetMathTabular.h @@ -47,6 +47,8 @@ public: void maple(MapleStream &) const; /// InsetCode lyxCode() const { return MATH_TABULAR_CODE; } + /// + bool handlesMulticolumn() const { return true; } //override private: Inset * clone() const; diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index f05af6438d..a2094c920e 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -1361,36 +1361,39 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } } - else if (t.cs() == "multicolumn") { - // extract column count and insert dummy cells + else if (t.cs() == "multicolumn" && grid.handlesMulticolumn()) { + // if the columns are specified numerically, + // extract column count and insert dummy cells, + // otherwise parse it as an user macro MathData count; parse(count, FLAG_ITEM, mode); - int cols = 1; - if (!extractNumber(count, cols)) { - success_ = false; - error("can't extract number of multicolumn cells"); - } - // resize the table if necessary - size_t first = grid.index(cellrow, cellcol); - for (int i = 1; i < cols; ++i) { - if (addCol(grid, cellcol)) { - size_t const idx = grid.index(cellrow, cellcol); - grid.cellinfo(idx).multi_ = - InsetMathGrid::CELL_PART_OF_MULTICOLUMN; + int cols; + if (extractNumber(count, cols)) { + // resize the table if necessary + size_t first = grid.index(cellrow, cellcol); + for (int i = 1; i < cols; ++i) { + if (addCol(grid, cellcol)) { + size_t const idx = grid.index(cellrow, cellcol); + grid.cellinfo(idx).multi_ = + InsetMathGrid::CELL_PART_OF_MULTICOLUMN; + } } - } - - // the first cell is the real thing, not a dummy - cell = &grid.cell(first); - grid.cellinfo(first).multi_ = InsetMathGrid::CELL_BEGIN_OF_MULTICOLUMN; - // read special alignment - MathData align; - parse(align, FLAG_ITEM, mode); - grid.cellinfo(first).align_ = asString(align); - - // parse the remaining contents into the "real" cell - parse(*cell, FLAG_ITEM, mode); + // the first cell is the real thing, not a dummy + cell = &grid.cell(first); + grid.cellinfo(first).multi_ = + InsetMathGrid::CELL_BEGIN_OF_MULTICOLUMN; + // read special alignment + MathData align; + parse(align, FLAG_ITEM, mode); + grid.cellinfo(first).align_ = asString(align); + // parse the remaining contents into the "real" cell + parse(*cell, FLAG_ITEM, mode); + } else { + MathAtom at = MathAtom(new MathMacro(buf, t.cs())); + cell->push_back(at); + cell->push_back(MathAtom(new InsetMathBrace(count))); + } } else if (t.cs() == "limits" || t.cs() == "nolimits") { diff --git a/status.22x b/status.22x index b93ba9369e..d7a5bb9136 100644 --- a/status.22x +++ b/status.22x @@ -160,7 +160,7 @@ What's new - Do not convert "--" to "\twohyphens" in formula macros. -- Fix bug in the reversion of colored boxes with special frame settings. +- Fix bugs in the reversion of colored boxes with special frame settings. * USER INTERFACE @@ -219,6 +219,8 @@ What's new - Fix display and output of math macros with optional arguments appearing in the optional argument of another macro. +- Handle the command \multicolumn correctly in math macros (bug 10466). + - Do not prematurely cut selected text when inserting a Hyperref (bug 10306). - Consider the argument of the hyperref-insert function even if there is a -- 2.39.5