+ if format >= 60 and format <= 62:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 59:
+ match = re_InsetLayout_CaptionLTNN.match(lines[i])
+ if not match:
+ i += 1
+ continue
+ # '^(\s*InsetLayout\s+)(Caption:LongTableNonumber)'
+ lead = match.group(1)
+ lines[i] = lead + "Caption:Unnumbered"
+ i += 1
+ continue
+
+ if format == 58:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 57:
+ match = re_IfStyle.match(lines[i])
+ if not match:
+ i += 1
+ continue
+ # r'^(\s*)IfStyle(\s+\S+)
+ lead = match.group(1)
+ trail = match.group(2)
+ lines[i] = lead + "ModifyStyle" + trail
+ i += 1
+ continue
+
+ if format >= 50 and format <= 56:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 49:
+ separator = []
+
+ # delete separator styles
+ match = re_Style.match(lines[i])
+ if match:
+ style = string.lower(match.group(4))
+ if re_Separator.match(style):
+ del lines[i]
+ while i < len(lines) and not re_End.match(lines[i]):
+ separator.append(lines[i])
+ del lines[i]
+ if i == len(lines):
+ error('Incomplete separator style.')
+ else:
+ del lines[i]
+ continue
+
+ # delete undefinition of separator styles
+ match = re_NoStyle.match(lines[i])
+ if match:
+ style = string.lower(match.group(4))
+ if re_Separator.match(style):
+ del lines[i]
+ continue
+
+ # replace the CopyStyle statement with the definition of the real
+ # style. This may result in duplicate statements, but that is OK
+ # since the second one will overwrite the first one.
+ match = re_CopyStyle.match(lines[i])
+ if match:
+ style = string.lower(match.group(4))
+ if re_Separator.match(style):
+ if len(separator) > 0:
+ lines[i:i+1] = separator
+ else:
+ # FIXME: If this style was redefined in an include file,
+ # we should replace the real style and not this default.
+ lines[i:i+1] = [' Category MainText',
+ ' KeepEmpty 1',
+ ' Margin Dynamic',
+ ' LatexType Paragraph',
+ ' LatexName dummy',
+ ' ParIndent MM',
+ ' Align Block',
+ ' LabelType Static',
+ ' LabelString "--- Separate Environment ---"',
+ ' LabelFont',
+ ' Family Roman',
+ ' Series Medium',
+ ' Size Normal',
+ ' Color Blue',
+ ' EndFont',
+ ' HTMLLabel NONE']
+ i += 1
+ continue
+
+ if format == 48:
+ # The default of ResetsFont in LyX changed from true to false,
+ # because it is now used for all InsetLayouts, not only flex ones.
+ # Therefore we need to set it to true for all flex insets which do
+ # do not already have a ResetsFont.
+ match = re_InsetLayout2.match(lines[i])
+ if not match:
+ i += 1
+ continue
+
+ name = string.lower(match.group(1))
+ if name != "flex" and name != "\"flex\"" and name[0:5] != "flex:" and name [0:6] != "\"flex:":
+ i += 1
+ continue
+
+ resetsfont_found = False
+ inherited = False
+ notdone = True
+ while i < len(lines):
+ match = re_ResetsFont.match(lines[i])
+ if match:
+ resetsfont_found = True
+ else:
+ match = re_CopyStyle.match(lines[i])
+ if match:
+ inherited = True
+ else:
+ match = re_End.match(lines[i])
+ if match:
+ break
+ i += 1
+ if not resetsfont_found and not inherited:
+ lines.insert(i, "\tResetsFont true")
+
+ continue
+
+ if format >= 44 and format <= 47:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 43:
+ match = re_LabelTypeIsCounter.match(lines[i])
+ if match:
+ if inchapter:
+ lines[i] = match.group(1) + "LabelType" + match.group(2) + "Above"
+ else:
+ lines[i] = match.group(1) + "LabelType" + match.group(2) + "Static"
+
+ match = re_TopEnvironment.match(lines[i])
+ if match:
+ lines[i] = match.group(1) + "LabelType" + match.group(2) + "Above"
+
+ match = re_CenteredEnvironment.match(lines[i])
+ if match:
+ lines[i] = match.group(1) + "LabelType" + match.group(2) + "Centered"
+
+ if inchapter:
+ match = re_Style.match(lines[i])
+ if match:
+ inchapter = False
+ else:
+ match = re_ChapterStyle.match(lines[i])
+ if match:
+ inchapter = True
+
+ i += 1
+ continue
+
+ if format == 42:
+ if lines[i] == "InsetLayout Caption":
+ lines[i] = "InsetLayout Caption:Standard"
+ i += 1
+ continue
+
+ if format == 41:
+ # nothing to do.
+ i += 1
+ continue
+
+ if format == 40:
+ # reset counters on Style beginning
+ match = re_Style.match(lines[i])
+ if match:
+ opts = 0
+ reqs = 0
+ i += 1
+ continue
+ match = re_OptArgs.match(lines[i])
+ if match:
+ # Save number of optional arguments
+ space1 = match.group(1)
+ opts = int(match.group(3))
+ # OptionalArgs 0 > ResetArgs 1
+ if opts == 0:
+ lines[i] = space1 + "ResetArgs\t1"
+ i += 1
+ else:
+ del lines[i]
+ continue
+ match = re_ReqArgs.match(lines[i])
+ if match:
+ # Save number of required arguments
+ space1 = match.group(1)
+ reqs = int(match.group(3))
+ del lines[i]
+ continue
+ # Insert the required number of arguments at the end of the style definition
+ match = re_End.match(lines[i])
+ if match:
+ newarg = ['']
+ # First the optionals (this is the required order pre 2.1)
+ if opts > 0:
+ if opts == 1:
+ newarg = [ '%sArgument 1' % (space1),
+ '%s\tLabelString\t\"Optional Layout Argument\"' % (space1),
+ '%sEndArgument' % (space1)]
+ elif opts > 1:
+ actopt = 1
+ while actopt < (opts + 1):
+ newarg += [ '%sArgument %d' % (space1, actopt),
+ '%s\tLabelString\t\"Optional Layout Argument %d\"' % (space1, actopt),
+ '%sEndArgument' % (space1)]
+ actopt += 1
+ # Now the mandatories
+ if reqs > 0:
+ actopt = opts + 1
+ while actopt < (opts + reqs + 1):
+ newarg += [ '%sArgument %d' % (space1, actopt),
+ '%s\tLabelString\t"Required Layout Argument %d"' % (space1, actopt - opts),
+ '%s\tMandatory\t1' % (space1),
+ '%sEndArgument' % (space1)]
+ actopt += 1
+ # Since we replace the "End" line, re-add this line
+ if len(newarg) > 1:
+ newarg += ['End']
+ lines[i:i+1] = newarg
+ i += len(newarg)
+ # Reset the counters
+ opts = 0
+ reqs = 0
+ i += 1
+ continue
+
+ if format == 39:
+ # There is a conversion with format 40, but it is done within the
+ # initial comment block and so is above.
+ i += 1
+ continue
+
+ if format == 37 or format == 38:
+ i += 1
+ continue
+
+ if format == 36:
+ match = re_CiteFormat.match(lines[i]);
+ if match and match.group(4) == "":
+ lines[i] = match.group(0) + " default"
+ i += 1
+ continue
+
+ if format == 35:
+ i += 1
+ continue
+
+ if format == 34:
+ match = re_QInsetLayout2.match(lines[i])
+ if not match:
+ match = re_InsetLayout2.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
+