]> git.lyx.org Git - features.git/commitdiff
Fix bug 5330, round 1.
authorRichard Heck <rgheck@comcast.net>
Tue, 7 Oct 2008 15:45:08 +0000 (15:45 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 7 Oct 2008 15:45:08 +0000 (15:45 +0000)
The bug is that older layout files with lines like:
Input amsmaths.inc
fail in 1.6, since that file no longer exists. This commit adds some
layout2layout that will scan for such includes and add lines like
UseModule theorems-ams
corresponding to the input lines. The downside to this commit is that
UseModule only becomes available on 25 July 2008, whereas the files
were removed in January.

My intention is to try to deal with these intermediate cases as well.
But I'm not sure that will ultimately work very well, so this will do
until I can figure that out.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26800 a592a061-630c-0410-9148-cb99ea01b6c8

lib/scripts/layout2layout.py

index f42a508a6c9c5cc31065c80e274dc212e290122e..583771a86a9b8386668f4b47d714b33353c12711 100644 (file)
@@ -86,12 +86,18 @@ def concatenate_label(old, new):
     else:
         return '"' + old + new + '"'
 
+# appends a string to a list unless it's already there
+def addstring(s, l):
+    if l.count(s) > 0:
+        return
+    l.append(s)
+
 
 def convert(lines):
     " Convert to new format."
     re_Comment = re.compile(r'^(\s*)#')
-    re_Counter = re.compile(r'\s*Counter\s*')
-    re_Name = re.compile(r'\s*Name\s+(\S+)\s*')
+    re_Counter = re.compile(r'\s*Counter\s*', re.IGNORECASE)
+    re_Name = re.compile(r'\s*Name\s+(\S+)\s*', re.IGNORECASE)
     re_Empty = re.compile(r'^(\s*)$')
     re_Format = re.compile(r'^(\s*)(Format)(\s+)(\S+)', re.IGNORECASE)
     re_Preamble = re.compile(r'^(\s*)Preamble', re.IGNORECASE)
@@ -107,6 +113,9 @@ def convert(lines):
     re_End = re.compile(r'^(\s*)(End)(\s*)$', re.IGNORECASE)
     re_Provides = re.compile(r'^(\s*)Provides(\S+)(\s+)(\S+)', re.IGNORECASE)
     re_CharStyle = re.compile(r'^(\s*)CharStyle(\s+)(\S+)$', re.IGNORECASE)
+    re_AMSMaths = re.compile(r'^\s*Input amsmaths.inc\s*')
+    re_AMSMathsPlain = re.compile(r'^\s*Input amsmaths-plain.inc\s*')
+    re_AMSMathsSeq = re.compile(r'^\s*Input amsmaths-seq.inc\s*')
 
     # counters for sectioning styles (hardcoded in 1.3)
     counters = {"part"          : "\\Roman{part}",
@@ -149,6 +158,9 @@ def convert(lines):
     style = ""
     maxcounter = 0
     format = 1
+    formatline = 0
+    usemodules = []
+
     while i < len(lines):
         # Skip comments and empty lines
         if re_Comment.match(lines[i]) or re_Empty.match(lines[i]):
@@ -159,6 +171,7 @@ def convert(lines):
         if (only_comment):
             match = re_Format.match(lines[i])
             if match:
+                formatline = i
                 format = int(match.group(4))
                 if format > 1 and format < currentFormat:
                     lines[i] = "Format %d" % (format + 1)
@@ -201,8 +214,32 @@ def convert(lines):
             i += 1
             continue
 
+        if format == 8:
+            # We want to scan for ams-type includes and, if we find them,
+            # add corresponding UseModule tags to the layout.
+            match = re_AMSMaths.match(lines[i])
+            if match:
+                addstring("theorems-ams", usemodules)
+                addstring("theorems-ams-extended", usemodules)
+                addstring("theorems-sec", usemodules)
+                lines.pop(i)
+                continue
+            match = re_AMSMathsPlain.match(lines[i])
+            if match:
+                addstring("theorems-starred", usemodules)
+                lines.pop(i)
+                continue
+            match = re_AMSMathsSeq.match(lines[i])
+            if match:
+                addstring("theorems-ams", usemodules)
+                addstring("theorems-ams-extended", usemodules)
+                lines.pop(i)
+                continue
+            i += 1
+            continue
+
         # These just involved new features, not any changes to old ones
-        if format >= 5 and format <= 8:
+        if format >= 5 and format <= 7:
           i += 1
           continue
 
@@ -429,6 +466,12 @@ def convert(lines):
 
         i += 1
 
+    if usemodules:
+        i = formatline + 1
+        for mod in usemodules:
+            lines.insert(i, "UseModule " + mod)
+            i += 1
+
     return format + 1