From 34001ec175b10b2b75ca91ccf0a28ffc4419f55e Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Sat, 1 Jul 2006 19:16:09 +0000 Subject: [PATCH] Remove all tabs in lib/lyx2lyx/*.py, corresponding to the added -tt option git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14285 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx_1_1_6fix3.py | 2 +- lib/lyx2lyx/lyx_1_2.py | 666 +++++++++++++++++------------------ lib/lyx2lyx/lyx_1_3.py | 92 ++--- lib/lyx2lyx/lyx_1_4.py | 198 +++++------ lib/lyx2lyx/parser_tools.py | 110 +++--- lib/lyx2lyx/profiling.py | 4 +- 6 files changed, 536 insertions(+), 536 deletions(-) diff --git a/lib/lyx2lyx/lyx_1_1_6fix3.py b/lib/lyx2lyx/lyx_1_1_6fix3.py index bc5f9e6c01..f7656d796a 100644 --- a/lib/lyx2lyx/lyx_1_1_6fix3.py +++ b/lib/lyx2lyx/lyx_1_1_6fix3.py @@ -55,7 +55,7 @@ def update_tabular(file): break new_table = table_update(lines[i:j]) - lines[i:j] = new_table + lines[i:j] = new_table i = i + len(new_table) diff --git a/lib/lyx2lyx/lyx_1_2.py b/lib/lyx2lyx/lyx_1_2.py index 46b7797a8b..3ac5d9cfb9 100644 --- a/lib/lyx2lyx/lyx_1_2.py +++ b/lib/lyx2lyx/lyx_1_2.py @@ -27,45 +27,45 @@ from parser_tools import find_token, find_token_backwards, get_next_paragraph,\ floats = { "footnote": ["\\begin_inset Foot", - "collapsed true"], + "collapsed true"], "margin": ["\\begin_inset Marginal", - "collapsed true"], + "collapsed true"], "fig": ["\\begin_inset Float figure", - "wide false", - "collapsed false"], + "wide false", + "collapsed false"], "tab": ["\\begin_inset Float table", - "wide false", - "collapsed false"], + "wide false", + "collapsed false"], "alg": ["\\begin_inset Float algorithm", - "wide false", - "collapsed false"], + "wide false", + "collapsed false"], "wide-fig": ["\\begin_inset Float figure", - "wide true", - "collapsed false"], + "wide true", + "collapsed false"], "wide-tab": ["\\begin_inset Float table", - "wide true", - "collapsed false"] + "wide true", + "collapsed false"] } font_tokens = ["\\family", "\\series", "\\shape", "\\size", "\\emph", - "\\bar", "\\noun", "\\color", "\\lang", "\\latex"] + "\\bar", "\\noun", "\\color", "\\lang", "\\latex"] pextra_type3_rexp = re.compile(r".*\\pextra_type\s+3") pextra_rexp = re.compile(r"\\pextra_type\s+(\S+)"+\ - r"(\s+\\pextra_alignment\s+(\S+))?"+\ - r"(\s+\\pextra_hfill\s+(\S+))?"+\ - r"(\s+\\pextra_start_minipage\s+(\S+))?"+\ - r"(\s+(\\pextra_widthp?)\s+(\S*))?") + r"(\s+\\pextra_alignment\s+(\S+))?"+\ + r"(\s+\\pextra_hfill\s+(\S+))?"+\ + r"(\s+\\pextra_start_minipage\s+(\S+))?"+\ + r"(\s+(\\pextra_widthp?)\s+(\S*))?") def get_width(mo): if mo.group(10): - if mo.group(9) == "\\pextra_widthp": - return mo.group(10)+"col%" - else: - return mo.group(10) + if mo.group(9) == "\\pextra_widthp": + return mo.group(10)+"col%" + else: + return mo.group(10) else: - return "100col%" + return "100col%" # @@ -75,63 +75,63 @@ def remove_oldfloat(file): lines = file.body i = 0 while 1: - i = find_token(lines, "\\begin_float", i) - if i == -1: - break - # There are no nested floats, so finding the end of the float is simple - j = find_token(lines, "\\end_float", i+1) - - floattype = string.split(lines[i])[1] - if not floats.has_key(floattype): - file.warning("Error! Unknown float type " + floattype) - floattype = "fig" - - # skip \end_deeper tokens - i2 = i+1 - while check_token(lines[i2], "\\end_deeper"): - i2 = i2+1 - if i2 > i+1: - j2 = get_next_paragraph(lines, j + 1, file.format + 1) - lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1)) - - new = floats[floattype]+[""] - - # Check if the float is floatingfigure - k = find_re(lines, pextra_type3_rexp, i, j) - if k != -1: - mo = pextra_rexp.search(lines[k]) - width = get_width(mo) - lines[k] = re.sub(pextra_rexp, "", lines[k]) - new = ["\\begin_inset Wrap figure", - 'width "%s"' % width, - "collapsed false", - ""] - - new = new+lines[i2:j]+["\\end_inset ", ""] - - # After a float, all font attributes are reseted. - # We need to output '\foo default' for every attribute foo - # whose value is not default before the float. - # The check here is not accurate, but it doesn't matter - # as extra '\foo default' commands are ignored. - # In fact, it might be safer to output '\foo default' for all - # font attributes. - k = get_paragraph(lines, i, file.format + 1) - flag = 0 - for token in font_tokens: - if find_token(lines, token, k, i) != -1: - if not flag: - # This is not necessary, but we want the output to be - # as similar as posible to the lyx format - flag = 1 - new.append("") - if token == "\\lang": - new.append(token+" "+ file.language) - else: - new.append(token+" default ") - - lines[i:j+1] = new - i = i+1 + i = find_token(lines, "\\begin_float", i) + if i == -1: + break + # There are no nested floats, so finding the end of the float is simple + j = find_token(lines, "\\end_float", i+1) + + floattype = string.split(lines[i])[1] + if not floats.has_key(floattype): + file.warning("Error! Unknown float type " + floattype) + floattype = "fig" + + # skip \end_deeper tokens + i2 = i+1 + while check_token(lines[i2], "\\end_deeper"): + i2 = i2+1 + if i2 > i+1: + j2 = get_next_paragraph(lines, j + 1, file.format + 1) + lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1)) + + new = floats[floattype]+[""] + + # Check if the float is floatingfigure + k = find_re(lines, pextra_type3_rexp, i, j) + if k != -1: + mo = pextra_rexp.search(lines[k]) + width = get_width(mo) + lines[k] = re.sub(pextra_rexp, "", lines[k]) + new = ["\\begin_inset Wrap figure", + 'width "%s"' % width, + "collapsed false", + ""] + + new = new+lines[i2:j]+["\\end_inset ", ""] + + # After a float, all font attributes are reseted. + # We need to output '\foo default' for every attribute foo + # whose value is not default before the float. + # The check here is not accurate, but it doesn't matter + # as extra '\foo default' commands are ignored. + # In fact, it might be safer to output '\foo default' for all + # font attributes. + k = get_paragraph(lines, i, file.format + 1) + flag = 0 + for token in font_tokens: + if find_token(lines, token, k, i) != -1: + if not flag: + # This is not necessary, but we want the output to be + # as similar as posible to the lyx format + flag = 1 + new.append("") + if token == "\\lang": + new.append(token+" "+ file.language) + else: + new.append(token+" default ") + + lines[i:j+1] = new + i = i+1 pextra_type2_rexp = re.compile(r".*\\pextra_type\s+[12]") @@ -143,9 +143,9 @@ def remove_pextra(file): i = 0 flag = 0 while 1: - i = find_re(lines, pextra_type2_rexp, i) - if i == -1: - break + i = find_re(lines, pextra_type2_rexp, i) + if i == -1: + break # Sometimes the \pextra_widthp argument comes in it own # line. If that happens insert it back in this line. @@ -153,7 +153,7 @@ def remove_pextra(file): lines[i] = lines[i] + ' ' + lines[i+1] del lines[i+1] - mo = pextra_rexp.search(lines[i]) + mo = pextra_rexp.search(lines[i]) width = get_width(mo) if mo.group(1) == "1": @@ -163,50 +163,50 @@ def remove_pextra(file): continue # handle \pextra_type 2 (minipage) - position = mo.group(3) - hfill = mo.group(5) - lines[i] = re.sub(pextra_rexp, "", lines[i]) - - start = ["\\begin_inset Minipage", - "position " + position, - "inner_position 0", - 'height "0pt"', - 'width "%s"' % width, - "collapsed false" - ] - if flag: - flag = 0 - if hfill: - start = ["","\hfill",""]+start - else: - start = ['\\layout %s' % file.default_layout,''] + start - - j0 = find_token_backwards(lines,"\\layout", i-1) - j = get_next_paragraph(lines, i, file.format + 1) - - count = 0 - while 1: - # collect more paragraphs to the minipage - count = count+1 - if j == -1 or not check_token(lines[j], "\\layout"): - break - i = find_re(lines, pextra_type2_rexp2, j+1) - if i == -1: - break - mo = pextra_rexp.search(lines[i]) - if not mo: - break - if mo.group(7) == "1": - flag = 1 - break - lines[i] = re.sub(pextra_rexp, "", lines[i]) - j = find_tokens(lines, ["\\layout", "\\end_float"], i+1) - - mid = lines[j0:j] - end = ["\\end_inset "] - - lines[j0:j] = start+mid+end - i = i+1 + position = mo.group(3) + hfill = mo.group(5) + lines[i] = re.sub(pextra_rexp, "", lines[i]) + + start = ["\\begin_inset Minipage", + "position " + position, + "inner_position 0", + 'height "0pt"', + 'width "%s"' % width, + "collapsed false" + ] + if flag: + flag = 0 + if hfill: + start = ["","\hfill",""]+start + else: + start = ['\\layout %s' % file.default_layout,''] + start + + j0 = find_token_backwards(lines,"\\layout", i-1) + j = get_next_paragraph(lines, i, file.format + 1) + + count = 0 + while 1: + # collect more paragraphs to the minipage + count = count+1 + if j == -1 or not check_token(lines[j], "\\layout"): + break + i = find_re(lines, pextra_type2_rexp2, j+1) + if i == -1: + break + mo = pextra_rexp.search(lines[i]) + if not mo: + break + if mo.group(7) == "1": + flag = 1 + break + lines[i] = re.sub(pextra_rexp, "", lines[i]) + j = find_tokens(lines, ["\\layout", "\\end_float"], i+1) + + mid = lines[j0:j] + end = ["\\end_inset "] + + lines[j0:j] = start+mid+end + i = i+1 def is_empty(lines): @@ -227,108 +227,108 @@ def remove_oldert(file): lines = file.body i = 0 while 1: - i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i) - if i == -1: - break - j = i+1 - while 1: + i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i) + if i == -1: + break + j = i+1 + while 1: # \end_inset is for ert inside a tabular cell. The other tokens # are obvious. - j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", "\\the_end"], - j) - if check_token(lines[j], "\\begin_inset"): - j = find_end_of_inset(lines, j)+1 - else: - break - - if check_token(lines[j], "\\layout"): - while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"): - j = j-1 - - # We need to remove insets, special chars & font commands from ERT text - new = [] - new2 = [] - if check_token(lines[i], "\\layout LaTeX"): - new = ['\layout %s' % file.default_layout, "", ""] - - k = i+1 - while 1: - k2 = find_re(lines, ert_rexp, k, j) - inset = hfill = specialchar = 0 - if k2 == -1: - k2 = j - elif check_token(lines[k2], "\\begin_inset"): - inset = 1 + j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", "\\the_end"], + j) + if check_token(lines[j], "\\begin_inset"): + j = find_end_of_inset(lines, j)+1 + else: + break + + if check_token(lines[j], "\\layout"): + while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"): + j = j-1 + + # We need to remove insets, special chars & font commands from ERT text + new = [] + new2 = [] + if check_token(lines[i], "\\layout LaTeX"): + new = ['\layout %s' % file.default_layout, "", ""] + + k = i+1 + while 1: + k2 = find_re(lines, ert_rexp, k, j) + inset = hfill = specialchar = 0 + if k2 == -1: + k2 = j + elif check_token(lines[k2], "\\begin_inset"): + inset = 1 elif check_token(lines[k2], "\\hfill"): hfill = 1 del lines[k2] j = j-1 - else: - specialchar = 1 - mo = spchar_rexp.match(lines[k2]) - lines[k2] = mo.group(1) - specialchar_str = mo.group(2) - k2 = k2+1 - - tmp = [] - for line in lines[k:k2]: + else: + specialchar = 1 + mo = spchar_rexp.match(lines[k2]) + lines[k2] = mo.group(1) + specialchar_str = mo.group(2) + k2 = k2+1 + + tmp = [] + for line in lines[k:k2]: # Move some lines outside the ERT inset: - if move_rexp.match(line): - if new2 == []: - # This is not necessary, but we want the output to be - # as similar as posible to the lyx format - new2 = [""] - new2.append(line) - elif not check_token(line, "\\latex"): - tmp.append(line) - - if is_empty(tmp): - if filter(lambda x:x != "", tmp) != []: - if new == []: - # This is not necessary, but we want the output to be - # as similar as posible to the lyx format - lines[i-1] = lines[i-1]+" " - else: - new = new+[" "] - else: - new = new+ert_begin+tmp+["\\end_inset ", ""] - - if inset: - k3 = find_end_of_inset(lines, k2) - new = new+[""]+lines[k2:k3+1]+[""] # Put an empty line after \end_inset - k = k3+1 - # Skip the empty line after \end_inset - if not is_nonempty_line(lines[k]): - k = k+1 - new.append("") + if move_rexp.match(line): + if new2 == []: + # This is not necessary, but we want the output to be + # as similar as posible to the lyx format + new2 = [""] + new2.append(line) + elif not check_token(line, "\\latex"): + tmp.append(line) + + if is_empty(tmp): + if filter(lambda x:x != "", tmp) != []: + if new == []: + # This is not necessary, but we want the output to be + # as similar as posible to the lyx format + lines[i-1] = lines[i-1]+" " + else: + new = new+[" "] + else: + new = new+ert_begin+tmp+["\\end_inset ", ""] + + if inset: + k3 = find_end_of_inset(lines, k2) + new = new+[""]+lines[k2:k3+1]+[""] # Put an empty line after \end_inset + k = k3+1 + # Skip the empty line after \end_inset + if not is_nonempty_line(lines[k]): + k = k+1 + new.append("") elif hfill: new = new + ["\\hfill", ""] k = k2 - elif specialchar: - if new == []: - # This is not necessary, but we want the output to be - # as similar as posible to the lyx format - lines[i-1] = lines[i-1]+specialchar_str - new = [""] - else: - new = new+[specialchar_str, ""] - k = k2 - else: - break - - new = new+new2 - if not check_token(lines[j], "\\latex "): - new = new+[""]+[lines[j]] - lines[i:j+1] = new - i = i+1 + elif specialchar: + if new == []: + # This is not necessary, but we want the output to be + # as similar as posible to the lyx format + lines[i-1] = lines[i-1]+specialchar_str + new = [""] + else: + new = new+[specialchar_str, ""] + k = k2 + else: + break + + new = new+new2 + if not check_token(lines[j], "\\latex "): + new = new+[""]+[lines[j]] + lines[i:j+1] = new + i = i+1 # Delete remaining "\latex xxx" tokens i = 0 while 1: - i = find_token(lines, "\\latex ", i) - if i == -1: - break - del lines[i] + i = find_token(lines, "\\latex ", i) + if i == -1: + break + del lines[i] # ERT insert are hidden feature of lyx 1.1.6. This might be removed in the future. @@ -336,17 +336,17 @@ def remove_oldertinset(file): lines = file.body i = 0 while 1: - i = find_token(lines, "\\begin_inset ERT", i) - if i == -1: - break - j = find_end_of_inset(lines, i) - k = find_token(lines, "\\layout", i+1) - l = get_paragraph(lines, i, file.format + 1) - if lines[k] == lines[l]: # same layout - k = k+1 - new = lines[k:j] - lines[i:j+1] = new - i = i+1 + i = find_token(lines, "\\begin_inset ERT", i) + if i == -1: + break + j = find_end_of_inset(lines, i) + k = find_token(lines, "\\layout", i+1) + l = get_paragraph(lines, i, file.format + 1) + if lines[k] == lines[l]: # same layout + k = k+1 + new = lines[k:j] + lines[i:j+1] = new + i = i+1 def is_ert_paragraph(file, i): @@ -358,7 +358,7 @@ def is_ert_paragraph(file, i): i = find_nonempty_line(lines, i+1) if not check_token(lines[i], "\\begin_inset ERT"): - return 0 + return 0 j = find_end_of_inset(lines, i) k = find_nonempty_line(lines, j+1) @@ -369,27 +369,27 @@ def combine_ert(file): lines = file.body i = 0 while 1: - i = find_token(lines, "\\begin_inset ERT", i) - if i == -1: - break - j = get_paragraph(lines, i, file.format + 1) - count = 0 - text = [] - while is_ert_paragraph(file, j): - - count = count+1 - i2 = find_token(lines, "\\layout", j+1) - k = find_token(lines, "\\end_inset", i2+1) - text = text+lines[i2:k] - j = find_token(lines, "\\layout", k+1) - if j == -1: - break - - if count >= 2: - j = find_token(lines, "\\layout", i+1) - lines[j:k] = text + i = find_token(lines, "\\begin_inset ERT", i) + if i == -1: + break + j = get_paragraph(lines, i, file.format + 1) + count = 0 + text = [] + while is_ert_paragraph(file, j): + + count = count+1 + i2 = find_token(lines, "\\layout", j+1) + k = find_token(lines, "\\end_inset", i2+1) + text = text+lines[i2:k] + j = find_token(lines, "\\layout", k+1) + if j == -1: + break + + if count >= 2: + j = find_token(lines, "\\layout", i+1) + lines[j:k] = text - i = i+1 + i = i+1 oldunits = ["pt", "cm", "in", "text%", "col%"] @@ -397,83 +397,83 @@ oldunits = ["pt", "cm", "in", "text%", "col%"] def get_length(lines, name, start, end): i = find_token(lines, name, start, end) if i == -1: - return "" + return "" x = string.split(lines[i]) return x[2]+oldunits[int(x[1])] def write_attribute(x, token, value): if value != "": - x.append("\t"+token+" "+value) + x.append("\t"+token+" "+value) def remove_figinset(file): lines = file.body i = 0 while 1: - i = find_token(lines, "\\begin_inset Figure", i) - if i == -1: - break - j = find_end_of_inset(lines, i) - - if ( len(string.split(lines[i])) > 2 ): - lyxwidth = string.split(lines[i])[3]+"pt" - lyxheight = string.split(lines[i])[4]+"pt" - else: - lyxwidth = "" - lyxheight = "" - - filename = get_value(lines, "file", i+1, j) - - width = get_length(lines, "width", i+1, j) - # what does width=5 mean ? - height = get_length(lines, "height", i+1, j) - rotateAngle = get_value(lines, "angle", i+1, j) - if width == "" and height == "": - size_type = "0" - else: - size_type = "1" - - flags = get_value(lines, "flags", i+1, j) - x = int(flags)%4 - if x == 1: - display = "monochrome" - elif x == 2: - display = "gray" - else: - display = "color" - - subcaptionText = "" - subcaptionLine = find_token(lines, "subcaption", i+1, j) - if subcaptionLine != -1: + i = find_token(lines, "\\begin_inset Figure", i) + if i == -1: + break + j = find_end_of_inset(lines, i) + + if ( len(string.split(lines[i])) > 2 ): + lyxwidth = string.split(lines[i])[3]+"pt" + lyxheight = string.split(lines[i])[4]+"pt" + else: + lyxwidth = "" + lyxheight = "" + + filename = get_value(lines, "file", i+1, j) + + width = get_length(lines, "width", i+1, j) + # what does width=5 mean ? + height = get_length(lines, "height", i+1, j) + rotateAngle = get_value(lines, "angle", i+1, j) + if width == "" and height == "": + size_type = "0" + else: + size_type = "1" + + flags = get_value(lines, "flags", i+1, j) + x = int(flags)%4 + if x == 1: + display = "monochrome" + elif x == 2: + display = "gray" + else: + display = "color" + + subcaptionText = "" + subcaptionLine = find_token(lines, "subcaption", i+1, j) + if subcaptionLine != -1: subcaptionText = lines[subcaptionLine][11:] - if subcaptionText != "": - subcaptionText = '"'+subcaptionText+'"' - - k = find_token(lines, "subfigure", i+1,j) - if k == -1: - subcaption = 0 - else: - subcaption = 1 - - new = ["\\begin_inset Graphics FormatVersion 1"] - write_attribute(new, "filename", filename) - write_attribute(new, "display", display) - if subcaption: - new.append("\tsubcaption") - write_attribute(new, "subcaptionText", subcaptionText) - write_attribute(new, "size_type", size_type) - write_attribute(new, "width", width) - write_attribute(new, "height", height) - if rotateAngle != "": - new.append("\trotate") - write_attribute(new, "rotateAngle", rotateAngle) - write_attribute(new, "rotateOrigin", "leftBaseline") - write_attribute(new, "lyxsize_type", "1") - write_attribute(new, "lyxwidth", lyxwidth) - write_attribute(new, "lyxheight", lyxheight) - new = new + ["\\end_inset"] - lines[i:j+1] = new + if subcaptionText != "": + subcaptionText = '"'+subcaptionText+'"' + + k = find_token(lines, "subfigure", i+1,j) + if k == -1: + subcaption = 0 + else: + subcaption = 1 + + new = ["\\begin_inset Graphics FormatVersion 1"] + write_attribute(new, "filename", filename) + write_attribute(new, "display", display) + if subcaption: + new.append("\tsubcaption") + write_attribute(new, "subcaptionText", subcaptionText) + write_attribute(new, "size_type", size_type) + write_attribute(new, "width", width) + write_attribute(new, "height", height) + if rotateAngle != "": + new.append("\trotate") + write_attribute(new, "rotateAngle", rotateAngle) + write_attribute(new, "rotateOrigin", "leftBaseline") + write_attribute(new, "lyxsize_type", "1") + write_attribute(new, "lyxwidth", lyxwidth) + write_attribute(new, "lyxheight", lyxheight) + new = new + ["\\end_inset"] + lines[i:j+1] = new ## @@ -491,16 +491,16 @@ def update_tabular(file): if i == -1: break - for k in get_tabular_lines(lines, i): - if check_token(lines[k], " 0 - value = find_token(pos, value, 0) - if value != -1: - params[key] = value - elif key == 'inner_pos': - # convert inner position - value = find_token(inner_pos, value, 0) - if value != -1: - params[key] = value - else: - params[key] = value - j = del_token(file.body, key, i, j) - i = i + 1 - - # Convert to minipage or ERT? - # Note that the inner_position and height parameters of a minipage - # inset are ignored and not accessible for the user, although they - # are present in the file format and correctly read in and written. - # Therefore we convert to ERT if they do not have their LaTeX - # defaults. These are: - # - the value of "position" for "inner_pos" - # - "\totalheight" for "height" - if (params['use_parbox'] != '0' or - params['has_inner_box'] != '1' or - params['special'] != 'none' or - params['height_special'] != 'totalheight' or - len2value(params['height']) != 1.0): + 'special':'none', 'height':'1in', + 'height_special':'totalheight', 'collapsed':'false'} + for key in params.keys(): + value = replace(get_value(file.body, key, i, j), '"', '') + if value != "": + if key == 'position': + # convert new to old position: 'position "t"' -> 0 + value = find_token(pos, value, 0) + if value != -1: + params[key] = value + elif key == 'inner_pos': + # convert inner position + value = find_token(inner_pos, value, 0) + if value != -1: + params[key] = value + else: + params[key] = value + j = del_token(file.body, key, i, j) + i = i + 1 + + # Convert to minipage or ERT? + # Note that the inner_position and height parameters of a minipage + # inset are ignored and not accessible for the user, although they + # are present in the file format and correctly read in and written. + # Therefore we convert to ERT if they do not have their LaTeX + # defaults. These are: + # - the value of "position" for "inner_pos" + # - "\totalheight" for "height" + if (params['use_parbox'] != '0' or + params['has_inner_box'] != '1' or + params['special'] != 'none' or + params['height_special'] != 'totalheight' or + len2value(params['height']) != 1.0): # Here we know that this box is not supported in file format 224. # Therefore we need to convert it to ERT. We can't simply convert @@ -1635,9 +1635,9 @@ def convert_frameless_box(file): j = j + 2 ert = '\\let\\endminipage\\endlyxtolyxminipage' j = insert_ert(file.body, j, 'Collapsed', ert, file.format - 1, file.default_layout) - j = j + 1 + j = j + 1 file.body.insert(j, '') - j = j + 1 + j = j + 1 # LyX writes '%\n' after each box. Therefore we need to end our # ERT with '%\n', too, since this may swallow a following space. @@ -1650,16 +1650,16 @@ def convert_frameless_box(file): # We don't need to restore the original minipage after the inset # end because the scope of the redefinition is the original box. - else: + else: - # Convert to minipage - file.body[i:i] = ['\\begin_inset Minipage', - 'position %d' % params['position'], - 'inner_position %d' % params['inner_pos'], - 'height "' + params['height'] + '"', - 'width "' + params['width'] + '"', - 'collapsed ' + params['collapsed']] - i = i + 6 + # Convert to minipage + file.body[i:i] = ['\\begin_inset Minipage', + 'position %d' % params['position'], + 'inner_position %d' % params['inner_pos'], + 'height "' + params['height'] + '"', + 'width "' + params['width'] + '"', + 'collapsed ' + params['collapsed']] + i = i + 6 def remove_branches(file): @@ -1805,31 +1805,31 @@ def convert_graphics(file): if i == -1: return - j = find_token_exact(file.body, "filename", i) + j = find_token_exact(file.body, "filename", i) if j == -1: return i = i + 1 - filename = split(file.body[j])[1] - absname = os.path.normpath(os.path.join(file.dir, filename)) - if file.input == stdin and not os.path.isabs(filename): - # We don't know the directory and cannot check the file. - # We could use a heuristic and take the current directory, - # and we could try to find out if filename has an extension, - # but that would be just guesses and could be wrong. - file.warning("""Warning: Can not determine whether file + filename = split(file.body[j])[1] + absname = os.path.normpath(os.path.join(file.dir, filename)) + if file.input == stdin and not os.path.isabs(filename): + # We don't know the directory and cannot check the file. + # We could use a heuristic and take the current directory, + # and we could try to find out if filename has an extension, + # but that would be just guesses and could be wrong. + file.warning("""Warning: Can not determine whether file %s needs an extension when reading from standard input. You may need to correct the file manually or run lyx2lyx again with the .lyx file as commandline argument.""" % filename) - continue - # This needs to be the same algorithm as in pre 233 insetgraphics - if access(absname, F_OK): - continue - if access(absname + ".ps", F_OK): - file.body[j] = replace(file.body[j], filename, filename + ".ps") - continue - if access(absname + ".eps", F_OK): - file.body[j] = replace(file.body[j], filename, filename + ".eps") + continue + # This needs to be the same algorithm as in pre 233 insetgraphics + if access(absname, F_OK): + continue + if access(absname + ".ps", F_OK): + file.body[j] = replace(file.body[j], filename, filename + ".ps") + continue + if access(absname + ".eps", F_OK): + file.body[j] = replace(file.body[j], filename, filename + ".eps") ## @@ -2419,12 +2419,12 @@ convert = [[222, [insert_tracking_changes, add_end_header, convert_amsmath]], [241, [convert_ert_paragraphs]], [242, [convert_french]], [243, [remove_paperpackage]], - [244, [rename_spaces]], - [245, [remove_quotestimes, convert_sgml_paragraphs]]] + [244, [rename_spaces]], + [245, [remove_quotestimes, convert_sgml_paragraphs]]] revert = [[244, []], - [243, [revert_space_names]], - [242, []], + [243, [revert_space_names]], + [242, []], [241, []], [240, [revert_ert_paragraphs]], [239, [revert_output_changes]], diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index a4af43fec5..c204cd73a3 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -21,7 +21,7 @@ import re def check_token(line, token): if line[:len(token)] == token: - return 1 + return 1 return 0 @@ -29,17 +29,17 @@ def check_token(line, token): # we can ignore this def find_token(lines, token, start, end = 0): if end == 0: - end = len(lines) + end = len(lines) m = len(token) for i in xrange(start, end): - if lines[i][:m] == token: - return i + if lines[i][:m] == token: + return i return -1 def find_token_exact(lines, token, start, end = 0): if end == 0: - end = len(lines) + end = len(lines) for i in xrange(start, end): x = string.split(lines[i]) y = string.split(token) @@ -52,17 +52,17 @@ def find_token_exact(lines, token, start, end = 0): def find_tokens(lines, tokens, start, end = 0): if end == 0: - end = len(lines) + end = len(lines) for i in xrange(start, end): - for token in tokens: - if lines[i][:len(token)] == token: - return i + for token in tokens: + if lines[i][:len(token)] == token: + return i return -1 def find_tokens_exact(lines, tokens, start, end = 0): if end == 0: - end = len(lines) + end = len(lines) for i in xrange(start, end): for token in tokens: x = string.split(lines[i]) @@ -76,35 +76,35 @@ def find_tokens_exact(lines, tokens, start, end = 0): def find_re(lines, rexp, start, end = 0): if end == 0: - end = len(lines) + end = len(lines) for i in xrange(start, end): - if rexp.match(lines[i]): - return i + if rexp.match(lines[i]): + return i return -1 def find_token_backwards(lines, token, start): m = len(token) for i in xrange(start, -1, -1): - line = lines[i] - if line[:m] == token: - return i + line = lines[i] + if line[:m] == token: + return i return -1 def find_tokens_backwards(lines, tokens, start): for i in xrange(start, -1, -1): - line = lines[i] - for token in tokens: - if line[:len(token)] == token: - return i + line = lines[i] + for token in tokens: + if line[:len(token)] == token: + return i return -1 def get_value(lines, token, start, end = 0): i = find_token_exact(lines, token, start, end) if i == -1: - return "" + return "" if len(string.split(lines[i])) > 1: return string.split(lines[i])[1] else: @@ -121,10 +121,10 @@ def get_layout(line, default_layout): def del_token(lines, token, i, j): k = find_token_exact(lines, token, i, j) if k == -1: - return j + return j else: - del lines[k] - return j-1 + del lines[k] + return j-1 # Finds the paragraph that contains line i. @@ -134,11 +134,11 @@ def get_paragraph(lines, i, format): else: begin_layout = "\\begin_layout" while i != -1: - i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i) + i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i) if i == -1: return -1 - if check_token(lines[i], begin_layout): - return i - i = find_beginning_of_inset(lines, i) + if check_token(lines[i], begin_layout): + return i + i = find_beginning_of_inset(lines, i) return -1 @@ -151,10 +151,10 @@ def get_next_paragraph(lines, i, format): else: tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_body", "\\end_document"] while i != -1: - i = find_tokens(lines, tokens, i) - if not check_token(lines[i], "\\begin_inset"): - return i - i = find_end_of_inset(lines, i) + i = find_tokens(lines, tokens, i) + if not check_token(lines[i], "\\begin_inset"): + return i + i = find_end_of_inset(lines, i) return -1 @@ -162,13 +162,13 @@ def find_end_of(lines, i, start_token, end_token): count = 1 n = len(lines) while i < n: - i = find_tokens(lines, [end_token, start_token], i+1) - if check_token(lines[i], start_token): - count = count+1 - else: - count = count-1 - if count == 0: - return i + i = find_tokens(lines, [end_token, start_token], i+1) + if check_token(lines[i], start_token): + count = count+1 + else: + count = count-1 + if count == 0: + return i return -1 @@ -176,13 +176,13 @@ def find_end_of(lines, i, start_token, end_token): def find_beginning_of(lines, i, start_token, end_token): count = 1 while i > 0: - i = find_tokens_backwards(lines, [start_token, end_token], i-1) - if check_token(lines[i], end_token): - count = count+1 - else: - count = count-1 - if count == 0: - return i + i = find_tokens_backwards(lines, [start_token, end_token], i-1) + if check_token(lines[i], end_token): + count = count+1 + else: + count = count-1 + if count == 0: + return i return -1 @@ -205,14 +205,14 @@ def get_tabular_lines(lines, i): i = i+1 j = find_end_of_tabular(lines, i) if j == -1: - return [] + return [] while i <= j: - if check_token(lines[i], "\\begin_inset"): - i = find_end_of_inset(lines, i)+1 - else: - result.append(i) - i = i+1 + if check_token(lines[i], "\\begin_inset"): + i = find_end_of_inset(lines, i)+1 + else: + result.append(i) + i = i+1 return result @@ -222,8 +222,8 @@ def is_nonempty_line(line): def find_nonempty_line(lines, start, end = 0): if end == 0: - end = len(lines) + end = len(lines) for i in xrange(start, end): - if is_nonempty_line(lines[i]): - return i + if is_nonempty_line(lines[i]): + return i return -1 diff --git a/lib/lyx2lyx/profiling.py b/lib/lyx2lyx/profiling.py index 01dcbc403d..c3d3d5fe70 100755 --- a/lib/lyx2lyx/profiling.py +++ b/lib/lyx2lyx/profiling.py @@ -29,10 +29,10 @@ import os """ This program profiles lyx2lyx. Usage: - ./profiling.py option_to_lyx2lyx + ./profiling.py option_to_lyx2lyx Example: - ./profiling.py -ou.lyx ../doc/UserGuide.lyx + ./profiling.py -ou.lyx ../doc/UserGuide.lyx """ def main(argv): -- 2.39.2