+ if re_LangPreamble.match(lines[i]):
+ i += 1
+ while i < len(lines) and not re_EndLangPreamble.match(lines[i]):
+ i += 1
+ continue
+ if re_BabelPreamble.match(lines[i]):
+ i += 1
+ while i < len(lines) and not re_EndBabelPreamble.match(lines[i]):
+ i += 1
+ continue
+
+ if format == 34:
+ match = re_InsetLayout2.match(lines[i])
+ if not match:
+ match = re_QInsetLayout2.match(lines[i])
+ if not match:
+ match = re_CopyStyle2.match(lines[i])
+ if not match:
+ i += 1
+ continue
+ style = match.group(2)
+
+ if flexstyles.count(style):
+ lines[i] = match.group(1) + "\"Flex:" + style + "\""
+ i += 1
+ continue
+
+ name = match.group(1)
+ names = name.split(":", 1)
+ if len(names) > 1 and names[0] == "Flex":
+ i += 1
+ continue
+
+ isflex = False
+ for j in range(i + 1, len(lines)):
+ if re_IsFlex.match(lines[j]):
+ isflex = True
+ break
+ if re_End.match(lines[j]):
+ break
+
+ if isflex:
+ flexstyles.append(name)
+ lines[i] = "InsetLayout \"Flex:" + name + "\""
+
+ i += 1
+ continue
+
+ if format == 33:
+ m = re_Fill.match(lines[i])
+ if m:
+ lines[i] = ""
+ i += 1
+ continue
+
+ if format == 32:
+ match = re_NeedsFloatPkg.match(lines[i])
+ if match:
+ space = match.group(1)
+ val = match.group(2)
+ lines[i] = space + "UsesFloatPkg " + val
+ newval = 'true'
+ if val == '1' or val.lower() == 'true':
+ newval = 'false'
+ lines.insert(i, space + "IsPredefined " + newval)
+ i += 1
+ i += 1
+ continue
+
+ # Only new features
+ if format >= 29 and format <= 31:
+ i += 1
+ continue
+
+ if format == 28:
+ match = re_InsetLayout.match(lines[i])
+ if match:
+ lines[i] = "InsetLayout Flex:" + match.group(1)
+ else:
+ match = re_QInsetLayout.match(lines[i])
+ if match:
+ lines[i] = "InsetLayout \"Flex:" + match.group(1) + "\""
+ else:
+ match = re_InsetLayout_CopyStyle.match(lines[i])
+ if match:
+ lines[i] = "\tCopyStyle Flex:" + match.group(1)
+ else:
+ match = re_QInsetLayout_CopyStyle.match(lines[i])
+ if match:
+ lines[i] = "\tCopyStyle \"Flex:" + match.group(1) + "\""
+ i += 1
+ continue
+
+ # Only new features
+ if format >= 24 and format <= 27:
+ i += 1
+ continue
+
+ if format == 23:
+ match = re_Float.match(lines[i])
+ i += 1
+ if not match:
+ continue
+ # we need to do two things:
+ # (i) Convert Builtin to NeedsFloatPkg
+ # (ii) Write ListCommand lines for the builtin floats table and figure
+ builtin = False
+ cmd = ""
+ while True and i < len(lines):
+ m1 = re_End.match(lines[i])
+ if m1:
+ if builtin and cmd:
+ line = " ListCommand " + cmd
+ lines.insert(i, line)
+ i += 1
+ break
+ m2 = re_Builtin.match(lines[i])
+ if m2:
+ builtin = True
+ ws1 = m2.group(1)
+ arg = m2.group(2)
+ newarg = ""
+ if re_True.match(arg):
+ newarg = "false"
+ else:
+ newarg = "true"
+ lines[i] = ws1 + "NeedsFloatPkg " + newarg
+ m3 = re_Type.match(lines[i])
+ if m3:
+ fltype = m3.group(1)
+ fltype = fltype.lower()
+ if fltype == "table":
+ cmd = "listoftables"
+ elif fltype == "figure":
+ cmd = "listoffigures"
+ # else unknown, which is why we're doing this
+ i += 1
+ continue
+
+ # This just involved new features, not any changes to old ones
+ if format >= 14 and format <= 22:
+ i += 1
+ continue
+
+ # Rename I18NPreamble to BabelPreamble
+ if format == 13:
+ match = re_I18nPreamble.match(lines[i])
+ if match:
+ lines[i] = match.group(1) + "BabelPreamble"
+ i += 1
+ match = re_EndI18nPreamble.match(lines[i])
+ while i < len(lines) and not match:
+ i += 1
+ match = re_EndI18nPreamble.match(lines[i])
+ lines[i] = match.group(1) + "EndBabelPreamble"
+ i += 1
+ continue
+
+ # These just involved new features, not any changes to old ones
+ if format == 11 or format == 12:
+ i += 1
+ continue
+
+ if format == 10:
+ match = re_UseMod.match(lines[i])
+ if match:
+ module = match.group(1)
+ lines[i] = "DefaultModule " + module
+ i += 1
+ continue
+
+ if format == 9:
+ match = re_Counter.match(lines[i])
+ if match:
+ counterline = i
+ i += 1
+ while i < len(lines):
+ namem = re_Name.match(lines[i])
+ if namem:
+ name = namem.group(1)
+ lines.pop(i)
+ lines[counterline] = "Counter %s" % name
+ # we don't need to increment i
+ continue
+ endem = re_End.match(lines[i])
+ if endem:
+ i += 1
+ break
+ i += 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