commit 782a1e42ed8091f837bb7895d4a6eb609738857b
Author: Juergen Spitzmueller <[email protected]>
Date:   Wed Sep 30 10:03:56 2026 +0200

    When checking for existing labels from LaTeX (log), consider that they 
might have escaped characters
    
    (cherry picked from commit 0f9f9be72d2001a1aca0bbc03d210d37a2a1100d)
---
 src/Buffer.cpp | 9 +++++----
 src/Buffer.h   | 9 +++++++--
 src/LaTeX.cpp  | 4 ++--
 status.25x     | 3 +++
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index fee0acde02..743deb6da7 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4210,19 +4210,20 @@ void Buffer::setInsetLabel(docstring const & label, 
InsetLabel const * il,
 
 
 InsetLabel const * Buffer::insetLabel(docstring const & label,
-                                     bool const active) const
+                                     bool const active, bool const escaped) 
const
 {
        for (auto const & rc : masterBuffer()->d->label_cache_) {
-               if (rc.label == label && (rc.active || !active))
+               docstring const lab = escaped ? escape(rc.label) : rc.label;
+               if (lab == label && (rc.active || !active))
                        return rc.inset;
        }
        return nullptr;
 }
 
 
-bool Buffer::activeLabel(docstring const & label) const
+bool Buffer::activeLabel(docstring const & label, bool const escaped) const
 {
-       return insetLabel(label, true) != nullptr;
+       return insetLabel(label, true, escaped) != nullptr;
 }
 
 
diff --git a/src/Buffer.h b/src/Buffer.h
index 897e673421..94b1fb4d41 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -756,11 +756,16 @@ public:
        /// \return the InsetLabel associated with this \p label string
        /// If \p active is true we only return active labels
        /// (see @ref activeLabel)
+       /// With \p escaped = true the \p label string is
+       /// escaped via support::escape()
        InsetLabel const * insetLabel(docstring const & label,
-                                     bool const active = false) const;
+                                     bool const active = false,
+                                     bool const escaped = false) const;
        /// \return true if this \param label is an active label.
        /// Inactive labels are currently deleted labels (in ct mode)
-       bool activeLabel(docstring const & label) const;
+       /// With \p escaped = true the \p label string is
+       /// escaped via support::escape()
+       bool activeLabel(docstring const & label, bool const escaped = false) 
const;
 
        /// return a list of all used branches (also in children)
        void getUsedBranches(std::list<docstring> &, bool const from_master = 
false) const;
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index abe2995b96..12f2f88f06 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -1170,7 +1170,7 @@ int LaTeX::scanLogFile(TeXErrors & terr)
                                if (regex_match(ml_token, sub, undef_ref)) {
                                        string const ref = sub.str(1);
                                        Buffer const * buf = 
theBufferList().getBufferFromTmp(file.absFileName());
-                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref))) {
+                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref), true)) {
                                                
terr.insertRef(getLineNumber(ml_token), from_ascii("Reference undefined"),
                                                        from_utf8(ml_token), 
child_name);
                                                retval |= UNDEF_UNKNOWN_REF;
@@ -1184,7 +1184,7 @@ int LaTeX::scanLogFile(TeXErrors & terr)
                                if (regex_match(token, sub, undef_ref)) {
                                        string const ref = sub.str(1);
                                        Buffer const * buf = 
theBufferList().getBufferFromTmp(file.absFileName());
-                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref))) {
+                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref), true)) {
                                                
terr.insertRef(getLineNumber(token), from_ascii("Reference undefined"),
                                                        from_utf8(token), 
child_name);
                                                retval |= UNDEF_UNKNOWN_REF;
diff --git a/status.25x b/status.25x
index c84bf071a7..8535814c3c 100644
--- a/status.25x
+++ b/status.25x
@@ -51,6 +51,9 @@ What's new
 - Calibrate the catcode mismatch check introduced in LyX 2.5.3 which
   produced false positives with grouped catcode changes.
 
+- Consider escaped characters when checking for existing labels while doing
+  LaTeX output.
+
 
 * USER INTERFACE
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to