lyx2lyx/lyx_2_0.py: fix box reversion and conversion routines

This commit is contained in:
Uwe Stöhr 2017-04-17 22:13:46 +02:00
parent 113c9a2f7f
commit fc2db913e0

View File

@ -1503,7 +1503,7 @@ def revert_argument(document):
def revert_makebox(document): def revert_makebox(document):
" Convert \\makebox to TeX code " " Convert \\makebox to TeX code "
i = 0 i = 0
while 1: while True:
i = find_token(document.body, '\\begin_inset Box', i) i = find_token(document.body, '\\begin_inset Box', i)
if i == -1: if i == -1:
break break
@ -1517,17 +1517,16 @@ def revert_makebox(document):
document.warning("Malformed LyX document: Can't find layout in box.") document.warning("Malformed LyX document: Can't find layout in box.")
i = z i = z
continue continue
# by looking before the layout we make sure we're actually finding j = find_token(document.body, 'use_makebox', i)
# an option, not text. if j == -1 or j != i +6:
j = find_token(document.body, 'use_makebox', i, blay) document.warning("Malformed LyX document: Can't find use_makebox statement in box.")
if j == -1: i = z
i = z continue
continue # delete use_makebox
if not check_token(document.body[i], "\\begin_inset Box Frameless") \ if not check_token(document.body[i], "\\begin_inset Box Frameless") \
or get_value(document.body, 'use_makebox', j) != 1: or get_value(document.body, 'use_makebox', j) != 1:
del document.body[j] del document.body[j]
i = z i += 1
continue continue
bend = find_end_of_layout(document.body, blay) bend = find_end_of_layout(document.body, blay)
if bend == -1 or bend > z: if bend == -1 or bend > z:
@ -1550,30 +1549,18 @@ def revert_makebox(document):
def convert_use_makebox(document): def convert_use_makebox(document):
" Adds use_makebox option for boxes " " Adds use_makebox option for boxes "
i = 0 i = 0
while 1: while True:
i = find_token(document.body, '\\begin_inset Box', i) i = find_token(document.body, '\\begin_inset Box', i)
if i == -1: if i == -1:
return return
# all of this is to make sure we actually find the use_parbox k = find_token(document.body, 'use_parbox', i)
# that is an option for this box, not some text elsewhere. if k == -1 or k != i + 5:
z = find_end_of_inset(document.body, i) document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
if z == -1:
document.warning("Can't find end of box inset!!")
i += 1 i += 1
continue continue
blay = find_token(document.body, "\\begin_layout", i, z) if k == i + 5:
if blay == -1: document.body.insert(k + 1, "use_makebox 0")
document.warning("Can't find layout in box inset!!") i += 1
i = z
continue
# so now we are looking for use_parbox before the box's layout
k = find_token(document.body, 'use_parbox', i, blay)
if k == -1:
document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
i = z
continue
document.body.insert(k + 1, "use_makebox 0")
i = blay + 1 # not z + 1 (box insets may be nested)
def revert_IEEEtran(document): def revert_IEEEtran(document):