#
# Change \begin_float .. \end_float into \begin_inset Float .. \end_inset
#
-def remove_oldfloat(lines, opt):
+def remove_oldfloat(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_float", i)
floattype = string.split(lines[i])[1]
if not floats.has_key(floattype):
- opt.warning("Error! Unknown float type " + floattype)
+ file.warning("Error! Unknown float type " + floattype)
floattype = "fig"
# skip \end_deeper tokens
flag = 1
new.append("")
if token == "\\lang":
- new.append(token+" "+ opt.language)
+ new.append(token+" "+ file.language)
else:
new.append(token+" default ")
pextra_type2_rexp = re.compile(r".*\\pextra_type\s+[12]")
pextra_type2_rexp2 = re.compile(r".*(\\layout|\\pextra_type\s+2)")
+pextra_widthp = re.compile(r"\\pextra_widthp")
-def remove_pextra(lines):
+def remove_pextra(file):
+ lines = file.body
i = 0
flag = 0
while 1:
if i == -1:
break
+ # Sometimes the \pextra_widthp argument comes in it own
+ # line. If that happens insert it back in this line.
+ if pextra_widthp.search(lines[i+1]):
+ lines[i] = lines[i] + ' ' + lines[i+1]
+ del lines[i+1]
+
mo = pextra_rexp.search(lines[i])
width = get_width(mo)
"\\layout Standard"]
-def remove_oldert(lines):
+def remove_oldert(file):
+ lines = file.body
i = 0
while 1:
i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i)
# ERT insert are hidden feature of lyx 1.1.6. This might be removed in the future.
-def remove_oldertinset(lines):
+def remove_oldertinset(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_inset ERT", i)
return check_token(lines[k], "\\layout")
-def combine_ert(lines):
+def combine_ert(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_inset ERT", i)
x.append("\t"+token+" "+value)
-def remove_figinset(lines):
+def remove_figinset(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_inset Figure", i)
attr_re = re.compile(r' \w*="(false|0|)"')
line_re = re.compile(r'<(features|column|row|cell)')
-def update_tabular(lines):
+def update_tabular(file):
+ regexp = re.compile(r'^\\begin_inset\s+Tabular')
+ lines = file.body
i = 0
while 1:
- i = find_token(lines, '\\begin_inset Tabular', i)
+ i = find_re(lines, regexp, i)
if i == -1:
break
ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"')
lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")')
def update_longtables(file):
+ regexp = re.compile(r'^\\begin_inset\s+Tabular')
body = file.body
i = 0
while 1:
- i = find_token(body, '\\begin_inset Tabular', i)
+ i = find_re(body, regexp, i)
if i == -1:
break
i = i + 1
i = find_token(body, '<features', i)
if i == -1:
break
-
+
# is this a longtable?
longtable = longtable_re.search(body[i])
# Figure insert are hidden feature of lyx 1.1.6. This might be removed in the future.
-def fix_oldfloatinset(lines):
+def fix_oldfloatinset(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_inset Float ", i)
i = i+1
-def change_listof(lines):
+def change_listof(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_inset LatexCommand \\listof", i)
i = i+1
-def change_infoinset(lines):
+def change_infoinset(file):
+ lines = file.body
i = 0
while 1:
i = find_token(lines, "\\begin_inset Info", i)
i = i+5
-def change_preamble(lines):
+def change_header(file):
+ lines = file.header
i = find_token(lines, "\\use_amsmath", 0)
if i == -1:
return
"\use_numerical_citations 0"]
-def convert(file):
- change_preamble(file.header)
- change_listof(file.body)
- fix_oldfloatinset(file.body)
- update_tabular(file.body)
- update_longtables(file)
- remove_pextra(file.body)
- remove_oldfloat(file.body, file)
- remove_figinset(file.body)
- remove_oldertinset(file.body)
- remove_oldert(file.body)
- combine_ert(file.body)
- change_infoinset(file.body)
- file.format = 220
-
-
-def revert(file):
- file.error("The convertion to an older format (%s) is not implemented." % file.format)
+convert = [[220, [change_header, change_listof, fix_oldfloatinset,
+ update_tabular, update_longtables, remove_pextra,
+ remove_oldfloat, remove_figinset, remove_oldertinset,
+ remove_oldert, combine_ert, change_infoinset]]]
+revert = []
if __name__ == "__main__":