commit ca3004fc6782c5bd4055a13d19dcdd1995e86ee3
Author: Alexander Dunlap <[email protected]>
Date:   Thu Aug 24 21:14:53 2023 -0400

    Assign equation numbers in updateBuffer instead of
    addToToc so that they can be used in updateToc to
    assign label cross-refs
---
 src/insets/InsetLabel.h      |    2 ++
 src/mathed/InsetMathHull.cpp |   33 ++++++++++++++++++++++++++++-----
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h
index 964d8de..91189e5 100644
--- a/src/insets/InsetLabel.h
+++ b/src/insets/InsetLabel.h
@@ -31,6 +31,8 @@ public:
        docstring const & prettyCounter() const { return pretty_counter_; }
        ///
        docstring const & formattedCounter() const { return formatted_counter_; 
}
+        ///
+        void setCounterValue(docstring cv) { counter_value_ = cv; }
        ///
        void setPrettyCounter(docstring pc) { pretty_counter_ = pc; }
         ///
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 0004d1e..d2c2159 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -274,6 +274,32 @@ void InsetMathHull::updateBuffer(ParIterator const & it, 
UpdateType utype, bool
                if (label_[i])
                        label_[i]->updateBuffer(it, utype, deleted);
        }
+        // set up equation numbers
+
+       // compute first and last item
+       row_type first = nrows();
+       for (row_type row = 0; row != nrows(); ++row)
+               if (numbered(row)) {
+                       first = row;
+                       break;
+               }
+       if (first != nrows()) {
+               row_type last = nrows() - 1;
+               for (; last != 0; --last)
+                       if (numbered(last))
+                               break;
+
+               for (row_type row = 0; row != nrows(); ++row) {
+                       if (!numbered(row))
+                               continue;
+                       if (label_[row]) {
+                               label_[row]->setCounterValue(numbers_[row]);
+                               label_[row]->setPrettyCounter("(" + 
numbers_[row] + ")");
+                               label_[row]->setFormattedCounter("(" + 
numbers_[row] + ")");
+                       }
+               }
+       }
+
        // pass down
        InsetMathGrid::updateBuffer(it, utype, deleted);
 }
@@ -304,9 +330,8 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool 
output_active,
                if (numbered(last))
             break;
 
-    TocBuilder & b = backend.builder("equation");
-    // add equation numbers
-       b.pushItem(pit, docstring(), output_active);
+       TocBuilder & b = backend.builder("equation");
+        b.pushItem(pit, docstring(), output_active);
        if (first != last)
                b.argumentItem(bformat(from_ascii("(%1$s-%2$s)"),
                                       numbers_[first], numbers_[last]));
@@ -321,8 +346,6 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool 
output_active,
                if (!numbered(row))
                        continue;
                if (label_[row]) {
-                       label_[row]->setPrettyCounter(_("Equation") + " " + 
numbers_[row]);
-                       label_[row]->setFormattedCounter(_("Equation") + " " + 
numbers_[row]);
                        label_[row]->addToToc(pit, output_active, utype, 
backend);
                }
                docstring label = nicelabel(row);
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to