From b0c60993301bca5d65696c4f5a77f6c267e8861e Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Tue, 7 Oct 2008 15:45:08 +0000 Subject: [PATCH] Fix bug 5330, round 1. 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 | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index f42a508a6c..583771a86a 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -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 -- 2.39.2