- backport fix for bug #10466

Handle the command \multicolumn correctly in math macros
This commit is contained in:
Uwe Stöhr 2017-04-18 23:53:27 +02:00
parent fc2db913e0
commit 0271602b8d
10 changed files with 47 additions and 33 deletions

View File

@ -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;
///

View File

@ -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;
///

View File

@ -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;
};

View File

@ -221,6 +221,8 @@ public:
virtual int vlinesep() const;
///
virtual int border() const;
///
virtual bool handlesMulticolumn() const { return false; }
///
void write(WriteStream & os) const;

View File

@ -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"

View File

@ -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;

View File

@ -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")

View File

@ -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;

View File

@ -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);
} else {
MathAtom at = MathAtom(new MathMacro(buf, t.cs()));
cell->push_back(at);
cell->push_back(MathAtom(new InsetMathBrace(count)));
}
// 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 if (t.cs() == "limits" || t.cs() == "nolimits") {

View File

@ -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