commit 4a7a19352cabb401052ca9467cf849da78f82f1a
Author: Enrico Forestieri <[email protected]>
Date:   Wed Jul 13 19:11:03 2022 +0200

    Fix bug #12561
    
    In mathed it is assumed that a labeled line is also implicitly numbered.
    However, latex allows to label an equation without numbering it.
    The label is then assigned the value of a nearby numbered one.
    This commit drops the above mathed assumption in order to allow to import
    valid latex code with a labeled but not numbered equation line.
    
    The screen representation omits the line number and encloses the label
    in square brackets for further differentiation. However, it is still not
    possible to label an equation without numbering it using the GUI.
---
 src/mathed/InsetMathHull.cpp |   23 +++++++++++------------
 src/mathed/MathParser.cpp    |    1 -
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index de01bad..689950d 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -520,9 +520,9 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & 
dim) const
                int extra_offset = 0;
                for (row_type row = 0; row < nrows(); ++row) {
                        rowinfo(row).offset[mi.base.bv] += extra_offset;
-                       if (!numbered(row))
-                               continue;
                        docstring const nl = nicelabel(row);
+                       if (nl.empty())
+                               continue;
                        Dimension dimnl;
                        mathed_string_dim(mi.base.font, nl, dimnl);
                        int const ind = indent(*mi.base.bv);
@@ -925,10 +925,6 @@ void InsetMathHull::label(row_type row, docstring const & 
label)
 void InsetMathHull::numbered(row_type row, Numbered num)
 {
        numbered_[row] = num;
-       if (!numbered(row) && label_[row]) {
-               delete label_[row];
-               label_[row] = 0;
-       }
 }
 
 
@@ -1377,8 +1373,11 @@ void InsetMathHull::delCol(col_type col)
 
 docstring InsetMathHull::nicelabel(row_type row) const
 {
-       if (!numbered(row))
-               return docstring();
+       if (!numbered(row)) {
+               if (!label_[row])
+                       return docstring();
+               return '[' + label_[row]->screenLabel() + ']';
+       }
        docstring const & val = numbers_[row];
        if (!label_[row])
                return '(' + val + ')';
@@ -1686,7 +1685,7 @@ docstring InsetMathHull::eolString(row_type row, bool 
fragile, bool latex,
 {
        docstring res;
        if (numberedType()) {
-               if (label_[row] && numbered(row)) {
+               if (label_[row]) {
                        docstring const name =
                                latex ? escape(label_[row]->getParam("name"))
                                      : label_[row]->getParam("name");
@@ -1908,7 +1907,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest 
& cmd)
                        // if there is an argument, find the corresponding 
label, else
                        // check whether there is at least one label.
                        for (row = 0; row != nrows(); ++row)
-                               if (numbered(row) && label_[row]
+                               if (label_[row]
                                          && (cmd.argument().empty() || 
label(row) == cmd.argument()))
                                        break;
                }
@@ -2111,12 +2110,12 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest 
const & cmd,
                        // if there is no argument and we're inside math, we 
retrieve
                        // the row number from the cursor position.
                        row_type row = (type_ == hullMultline) ? nrows() - 1 : 
cur.row();
-                       enabled = numberedType() && label_[row] && 
numbered(row);
+                       enabled = numberedType() && label_[row];
                } else {
                        // if there is an argument, find the corresponding 
label, else
                        // check whether there is at least one label.
                        for (row_type row = 0; row != nrows(); ++row) {
-                               if (numbered(row) && label_[row] &&
+                               if (label_[row] &&
                                        (cmd.argument().empty() || label(row) 
== cmd.argument())) {
                                                enabled = true;
                                                break;
diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index 0ba3375..1958900 100644
--- a/src/mathed/MathParser.cpp
+++ b/src/mathed/MathParser.cpp
@@ -1794,7 +1794,6 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        asArray(label, ar);
                        if (grid.asHullInset()) {
                                grid.asHullInset()->label(cellrow, label);
-                               grid.asHullInset()->numbered(cellrow, true);
                        } else {
                                cell->push_back(createInsetMath(t.cs(), buf));
                                cell->push_back(MathAtom(new 
InsetMathBrace(ar)));
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to