diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 109b0b0830..58745669a8 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1056,15 +1056,14 @@ def revert_percent_hspace_lengths(document): document.warning("Malformed lyx document: Missing '\\length' in Space inset.") i = j continue - protected = (document.body[i].find("\\hspace*{}") != -1) + protected = "" + if document.body[i].find("\\hspace*{}") != -1: + protected = "*" # ...and if it used a percent length percent, length = latex_length(length) # revert the HSpace inset to ERT if percent == "True": - if protected: - subst = put_cmd_in_ert("\\hspace*{" + length + "}") - else: - subst = put_cmd_in_ert("\\hspace{" + length + "}") + subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}") document.body[i:j + 1] = subst # if we did a substitution, this will still be ok i = j @@ -1077,23 +1076,28 @@ def revert_hspace_glue_lengths(document): i = find_token(document.body, "\\begin_inset space \\hspace", i) if i == -1: break - protected = (document.body[i].find("\\hspace*{}") != -1) - length = get_value(document.body, '\\length', i + 1) + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Can't find end of inset at line " + str(i)) + i += 1 + continue + length = get_value(document.body, '\\length', i + 1, j) if length == '': document.warning("Malformed lyx document: Missing '\\length' in Space inset.") - return + i = j + continue + protected = "" + if document.body[i].find("\\hspace*{}") != -1: + protected = "*" # only revert if the length contains a plus or minus at pos != 0 - glue = re.compile(r'.+[\+-]') - if glue.search(length): + if length.find('-',1) != -1 or length.find('+',1) != -1: # handle percent lengths length = latex_length(length)[1] # revert the HSpace inset to ERT - if protected: - subst = [old_put_cmd_in_ert("\\hspace*{" + length + "}")] - else: - subst = [old_put_cmd_in_ert("\\hspace{" + length + "}")] - document.body[i:i + 3] = subst - i = i + 2 + subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}") + document.body[i:j+1] = subst + i = j + def convert_author_id(document): " Add the author_id to the \\author definition and make sure 0 is not used"