X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_2_4.py;h=8436d9a84c1e57e3d5de5814b4c4a94f68101405;hb=69ed8cb89abd291b19ca2a3423d1f368a0d67f71;hp=90ce08eca3935a9a256b3932a4f0772ad36ba77c;hpb=0b7305024a33e6616ef3ae73a0df63c5a62e3d10;p=lyx.git diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 90ce08eca3..8436d9a84c 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -642,7 +642,7 @@ def revert_lscape(document): while True: i = find_token(document.body, "\\begin_inset Flex Landscape", i+1) if i == -1: - return + break j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed LyX document: Can't find end of Landscape inset") @@ -657,6 +657,7 @@ def revert_lscape(document): document.body[i : i + 4] = put_cmd_in_ert("\\begin{landscape}") add_to_preamble(document, ["\\usepackage{pdflscape}"]) + document.del_module("landscape") def convert_fontenc(document): @@ -2021,7 +2022,7 @@ def revert_linggloss(document): beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i) endInset = find_end_of_inset(document.body, i) - endPlain = find_token_backwards(document.body, "\\end_layout", endInset) + endPlain = find_end_of_layout(document.body, beginPlain) precontent = put_cmd_in_ert(cmd) if len(optargcontent) > 0: precontent += put_cmd_in_ert("[") + optargcontent + put_cmd_in_ert("]") @@ -3389,7 +3390,196 @@ def revert_pagesizenames(document): if val in newnames: newval = val + "paper" document.header[i] = "\\papersize " + newval - + + +def revert_theendnotes(document): + " Reverts native support of \\theendnotes to TeX-code " + + if not "endnotes" in document.get_module_list() and not "foottoend" in document.get_module_list(): + return + + i = 0 + while True: + i = find_token(document.body, "\\begin_inset FloatList endnote", i + 1) + if i == -1: + return + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of FloatList inset") + continue + + document.body[i : j + 1] = put_cmd_in_ert("\\theendnotes") + + +def revert_enotez(document): + " Reverts native support of enotez package to TeX-code " + + if not "enotez" in document.get_module_list() and not "foottoenotez" in document.get_module_list(): + return + + use = False + if find_token(document.body, "\\begin_inset Flex Endnote", 0) != -1: + use = True + + revert_flex_inset(document.body, "Endnote", "\\endnote") + + i = 0 + while True: + i = find_token(document.body, "\\begin_inset FloatList endnote", i + 1) + if i == -1: + break + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of FloatList inset") + continue + + use = True + document.body[i : j + 1] = put_cmd_in_ert("\\printendnotes") + + if use: + add_to_preamble(document, ["\\usepackage{enotez}"]) + document.del_module("enotez") + document.del_module("foottoenotez") + + +def revert_memoir_endnotes(document): + " Reverts native support of memoir endnotes to TeX-code " + + if document.textclass != "memoir": + return + + encommand = "\\pagenote" + modules = document.get_module_list() + if "enotez" in modules or "foottoenotez" in modules or "endnotes" in modules or "foottoend" in modules: + encommand = "\\endnote" + + revert_flex_inset(document.body, "Endnote", encommand) + + i = 0 + while True: + i = find_token(document.body, "\\begin_inset FloatList pagenote", i + 1) + if i == -1: + break + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of FloatList inset") + continue + + if document.body[i] == "\\begin_inset FloatList pagenote*": + document.body[i : j + 1] = put_cmd_in_ert("\\printpagenotes*") + else: + document.body[i : j + 1] = put_cmd_in_ert("\\printpagenotes") + add_to_preamble(document, ["\\makepagenote"]) + + +def revert_totalheight(document): + " Reverts graphics height parameter from totalheight to height " + + i = 0 + while (True): + i = find_token(document.body, "\\begin_inset Graphics", i) + if i == -1: + break + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Can't find end of graphics inset at line %d!!" %(i)) + i += 1 + continue + + rx = re.compile(r'\s*special\s*(\S+)$') + k = find_re(document.body, rx, i, j) + special = "" + oldheight = "" + if k != -1: + m = rx.match(document.body[k]) + if m: + special = m.group(1) + mspecial = special.split(',') + for spc in mspecial: + if spc[:7] == "height=": + oldheight = spc.split('=')[1] + mspecial.remove(spc) + break + if len(mspecial) > 0: + special = ",".join(mspecial) + else: + special = "" + + rx = re.compile(r'(\s*height\s*)(\S+)$') + kk = find_re(document.body, rx, i, j) + if kk != -1: + m = rx.match(document.body[kk]) + val = "" + if m: + val = m.group(2) + if k != -1: + if special != "": + val = val + "," + special + document.body[k] = "\tspecial " + "totalheight=" + val + else: + document.body.insert(kk, "\tspecial totalheight=" + val) + if oldheight != "": + document.body[kk] = m.group(1) + oldheight + else: + del document.body[kk] + elif oldheight != "": + document.body.insert(k, "\theight " + oldheight) + i = j + 1 + + +def convert_totalheight(document): + " Converts graphics height parameter from totalheight to height " + + i = 0 + while (True): + i = find_token(document.body, "\\begin_inset Graphics", i) + if i == -1: + break + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Can't find end of graphics inset at line %d!!" %(i)) + i += 1 + continue + + rx = re.compile(r'\s*special\s*(\S+)$') + k = find_re(document.body, rx, i, j) + special = "" + newheight = "" + if k != -1: + m = rx.match(document.body[k]) + if m: + special = m.group(1) + mspecial = special.split(',') + for spc in mspecial: + if spc[:12] == "totalheight=": + newheight = spc.split('=')[1] + mspecial.remove(spc) + break + if len(mspecial) > 0: + special = ",".join(mspecial) + else: + special = "" + + rx = re.compile(r'(\s*height\s*)(\S+)$') + kk = find_re(document.body, rx, i, j) + if kk != -1: + m = rx.match(document.body[kk]) + val = "" + if m: + val = m.group(2) + if k != -1: + if special != "": + val = val + "," + special + document.body[k] = "\tspecial " + "height=" + val + else: + document.body.insert(kk + 1, "\tspecial height=" + val) + if newheight != "": + document.body[kk] = m.group(1) + newheight + else: + del document.body[kk] + elif newheight != "": + document.body.insert(k, "\theight " + newheight) + i = j + 1 ## # Conversion hub @@ -3439,10 +3629,14 @@ convert = [ [584, []], [585, [convert_pagesizes]], [586, []], - [587, [convert_pagesizenames]] + [587, [convert_pagesizenames]], + [588, []], + [589, [convert_totalheight]] ] -revert = [[586, [revert_pagesizenames]], +revert = [[588, [revert_totalheight]], + [587, [revert_memoir_endnotes,revert_enotez,revert_theendnotes]], + [586, [revert_pagesizenames]], [585, [revert_dupqualicites]], [584, [revert_pagesizes,revert_komafontsizes]], [583, [revert_vcsinfo_rev_abbrev]],