]> git.lyx.org Git - features.git/commitdiff
fixup convert_lineno (#13036)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 26 Jan 2024 09:30:31 +0000 (10:30 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 26 Jan 2024 09:30:31 +0000 (10:30 +0100)
This routine assumed \linenumbers to be preceded by \usepackage{lineno}
and that by a lyx2lyx comment.

Of course, this is not the case if users loaded lineno manually.

lib/lyx2lyx/lyx_2_4.py

index 16d6a99e5697adef35a75b978a7a581de484df03..687c3fbfbd8a3dde97ce04a8eee37bb1e44e18e4 100644 (file)
@@ -1915,13 +1915,14 @@ def convert_lineno(document):
     use_lineno = 0
     options = ""
     i = find_token(document.preamble, "\\linenumbers", 1)
-    if i > -1:
+    if i > 0:
         usepkg = re.match(r"\\usepackage(.*){lineno}", document.preamble[i-1])
         if usepkg:
             use_lineno = 1
             options = usepkg.group(1).strip("[]")
             del(document.preamble[i-1:i+1])
-            del_token(document.preamble, "% Added by lyx2lyx", i-2, i-1)
+            if i > 1:
+                del_token(document.preamble, "% Added by lyx2lyx", i-2, i-1)
 
     k = find_token(document.header, "\\index ")
     if options == "":