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)
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}",
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]):
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)
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
i += 1
+ if usemodules:
+ i = formatline + 1
+ for mod in usemodules:
+ lines.insert(i, "UseModule " + mod)
+ i += 1
+
return format + 1