commit 1d08af621d8649c76c5605b563dc02b5d256c82c
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Sat Jul 23 00:56:07 2022 +0200

    Implement on screen numbering for Subequation module
    
    The module subequation allows to number equations in the "Subfigure"
    inset to be numbered (1a), (1b), (1c), etc.
    
    To implement this on screen, we need to redefine temporarily the
    "equation" counter to use this different numbering.
    
    To this end, implement Counters::copy method that can be used to
    backup full counter definitions.
    
    Fixes bug #12567.
---
 src/Counters.cpp         |   10 ++++++++++
 src/Counters.h           |    2 ++
 src/insets/InsetFlex.cpp |   27 ++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/src/Counters.cpp b/src/Counters.cpp
index 519cb27..0133f76 100644
--- a/src/Counters.cpp
+++ b/src/Counters.cpp
@@ -421,6 +421,16 @@ void Counters::reset(docstring const & match)
 }
 
 
+bool Counters::copy(docstring const & cnt, docstring const & newcnt)
+{
+       auto const it = counterList_.find(cnt);
+       if (it == counterList_.end())
+               return false;
+       counterList_[newcnt] = it->second;
+       return true;
+}
+
+
 bool Counters::remove(docstring const & cnt)
 {
        bool retval = counterList_.erase(cnt);
diff --git a/src/Counters.h b/src/Counters.h
index 7a82df4..57fff35 100644
--- a/src/Counters.h
+++ b/src/Counters.h
@@ -162,6 +162,8 @@ public:
        void reset();
        /// Reset counters matched by match string.
        void reset(docstring const & match);
+       /// Copy counter \p cnt to \p newcnt.
+       bool copy(docstring const & cnt, docstring const & newcnt);
        /// Remove counter \p cnt.
        bool remove(docstring const & cnt);
        /** returns the expanded string representation of counter \c
diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp
index e607610..3cf709a 100644
--- a/src/insets/InsetFlex.cpp
+++ b/src/insets/InsetFlex.cpp
@@ -24,6 +24,7 @@
 #include "ParIterator.h"
 #include "TextClass.h"
 
+#include "support/debug.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
@@ -149,11 +150,35 @@ void InsetFlex::updateBuffer(ParIterator const & it, 
UpdateType utype, bool cons
        docstring custom_label = translateIfPossible(il.labelstring());
 
        Counters & cnts = bp.documentClass().counters();
+
+       // Special case for `subequations' module.
+       if (il.latextype() == InsetLaTeXType::ENVIRONMENT &&
+           il.latexname() == "subequations") {
+               docstring equation(from_ascii("equation"));
+               docstring parentequation(from_ascii("parentequation"));
+               if (!deleted)
+                       cnts.step(equation, utype);
+               // save a copy of the equation counter definition
+               cnts.copy(equation, parentequation);
+               // redefine the equation counter definition
+               docstring const eqlabel = deleted ? from_ascii("#")
+                       : cnts.theCounter(equation, 
it->getParLanguage(bp)->code());
+               cnts.newCounter(equation, parentequation,
+                               eqlabel + from_ascii("\\alph{equation}"),
+                               eqlabel + from_ascii("\\alph{equation}"),
+                               cnts.guiName(parentequation));
+               InsetCollapsible::updateBuffer(it, utype, deleted);
+               // reset equation counter as it was.
+               cnts.copy(parentequation, equation);
+               cnts.remove(parentequation);
+               return;
+       }
+
        docstring const & count = il.counter();
        bool const have_counter = cnts.hasCounter(count);
        if (have_counter) {
                Paragraph const & par = it.paragraph();
-               if (!par.isDeleted(it.pos())) {
+               if (!deleted) {
                        cnts.step(count, utype);
                        custom_label += ' ' +
                                cnts.theCounter(count, 
it.paragraph().getParLanguage(bp)->code());
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to