commit 24f66f5ae047c180e30a26eeca3a0d6a756d5f44
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat Jun 14 11:41:02 2025 +0200

    Handle commas in labels and references
    
    Replace all commas in labels/refs by dots.
    
    Commas are spacial characters (delimiters in ref lists) and hence
    not allowed in label names (this already applies to LyX 2.4 with
    refstyle, but the bug got unnoticed).
---
 lib/lyx2lyx/lyx_2_5.py | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index 1bec68e123..e06378f59e 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -2680,6 +2680,32 @@ def revert_zref(document):
         )
 
 
+def convert_reflists(document):
+    "Remove commas from labels and references to work with lists"
+
+    i = 0
+    regexp = re.compile(r"(name|reference) \".*\,.*\"")
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset", i)
+        if i == -1:
+            break
+        if document.body[i] != "\\begin_inset CommandInset label" \
+        and document.body[i] != "\\begin_inset CommandInset ref":
+            i += 1
+            continue
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Can't find end of reference inset at line %d!!" 
% (i))
+            i += 1
+            continue
+
+        k = find_re(document.body, regexp, i, j)
+        if k != -1:
+            # replace comma by dot
+            document.body[k] = document.body[k].replace(",", ".")
+        i += 1
+
+
 def revert_reflists(document):
     "Reverts crossref lists and ranges to ERT"
 
@@ -3177,7 +3203,7 @@ convert = [
     [634, []],
     [635, [convert_crossref_package]],
     [636, []],
-    [637, []],
+    [637, [convert_reflists]],
     [638, []],
     [639, [convert_theorem_local_def]],
     [640, []]
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to