2014-05-24 6:37 GMT+02:00 Scott Kostyshak: > Indeed, examples/beamer.lyx roundtrip is broken for me. After the > roundtrip conversion I get the "Buffer... ended unexpectedly, which > means that it is probably corrupted" error. This was working a day or > two ago. >
Try again. The file should at least open again now (I tried with the complex beamerlyxexample1, which failed for me before). The reason why it does not convert to a file that compiles without LaTeX errors is that the frame arguments in the reverted documents use ERT for the delimiters only (not for the arguments themselves), and we do not support this in conversion (see FIXME in the convert_beamerframeargs routine). I have started to work on this, but it is extremely complex. Attached is a patch that sort of works _except_ for the case where arguments are separated in two different ERTS, that is -- () means: in ERT: (<)arg(>[)arg(]) works now, while (<)arg(>)([)arg(]) does not yet. See attached patch. The crucial missing bit is the ertcontdivline thing, which would need to take the above into account. But I am running out of time. Jürgen > > Scott >
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index a8b14be..3932f15 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -2287,80 +2287,240 @@ def convert_beamerframeargs(document, i, parbeg): if ertend == -1: document.warning("Malformed LyX document: missing ERT \\end_inset") return ertend - ertcont = parbeg + 5 - if document.body[ertcont].startswith("[<"): - # This is a default overlay specification + ertcontfirstline = parbeg + 5 + j = find_end_of_layout(document.body, i) + if j == -1: + document.warning("Malformed LyX document: missing \\end_layout") + return -1 + # Find the last ERT in this paragraph (which might also be the first) + lastertbeg = find_token_backwards(document.body, "\\begin_inset ERT", j) + if lastertbeg == -1: + document.warning("Last ERT not found!") + break + lastertend = find_end_of_inset(document.body, lastertbeg) + if lastertend == -1: + document.warning("End of last ERT not found!") + break + ertend = lastertend + ertcontlastline = lastertend - 3 + if document.body[ertcontfirstline].startswith("[<"): + # This is a default overlay specification (Argument 1) # strip off the [< - document.body[ertcont] = document.body[ertcont][2:] - if document.body[ertcont].endswith(">]"): + document.body[ertcontfirstline] = document.body[ertcontfirstline][3:] + if document.body[ertcontlastline].endswith(">]"): + # We only have Argument 1. This is easy: # strip off the >] - document.body[ertcont] = document.body[ertcont][:-2] - elif document.body[ertcont].endswith("]"): - # divide the args - tok = document.body[ertcont].find('>][') - if tok != -1: - subst = [document.body[ertcont][:tok], - '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', - 'status collapsed', '', '\\begin_layout Plain Layout', - document.body[ertcont][tok + 3:-1]] - document.body[ertcont : ertcont + 1] = subst - ertend += 11 - # Convert to ArgInset - document.body[parbeg] = "\\begin_inset Argument 2" - elif document.body[ertcont].startswith("<"): - # This is an overlay specification - # strip off the < - document.body[ertcont] = document.body[ertcont][1:] - if document.body[ertcont].endswith(">"): - # strip off the > - document.body[ertcont] = document.body[ertcont][:-1] - # Convert to ArgInset - document.body[parbeg] = "\\begin_inset Argument 1" - elif document.body[ertcont].endswith(">]"): + document.body[ertcontlastline] = document.body[ertcontlastline][:-2] + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertend : ertend + 1] = [ + document.body[ertend], '\\end_layout', '', '\\end_inset'] + document.body[parbeg : parbeg + 1] = ['\\begin_inset Argument 1', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', ''] + ertend += 8 + else: + document.body[parbeg] = "\\begin_inset Argument 1" + elif document.body[ertcontlastline].endswith(">"): + # We have Argument 1 + Argument 2 # divide the args - tok = document.body[ertcont].find('>[<') - if tok != -1: - document.body[ertcont : ertcont + 1] = [document.body[ertcont][:tok], - '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2', - 'status collapsed', '', '\\begin_layout Plain Layout', - document.body[ertcont][tok + 3:-2]] - # Convert to ArgInset - document.body[parbeg] = "\\begin_inset Argument 1" - ertend += 11 - elif document.body[ertcont].endswith("]"): + ertcontdivline = ertcontfirstline + tok = document.body[ertcontdivline].find('>]<') + if tok == -1: + regexp = re.compile(r'.*>\]<', re.IGNORECASE) + ertcontdivline = find_re(document.body, regexp, ertcontfirstline, ertcontlastline) + tok = document.body[ertcontdivline].find('>]<') + if tok != -1: + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertcontlastline : ertcontlastline + 1] = [ + document.body[ertcontlastline], '\\end_layout', '', '\\end_inset'] + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', '', 'status open' '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 2:]] + ertend += 17 + else: + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2', + 'status collapsed', '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 2:]] + ertend += 12 + # Convert Argument 1 to ArgInset + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertend : ertend + 1] = [ + document.body[ertend], '\\end_layout', '', '\\end_inset'] + document.body[parbeg : parbeg + 1] = ['\\begin_inset Argument 1', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', ''] + ertend += 8 + else: + document.body[parbeg] = "\\begin_inset Argument 1" + elif document.body[ertcontlastline].endswith("]"): + # We have Argument 1 (maybe + Argument 2) + Argument 3 # divide the args - tok = document.body[ertcont].find('>[<') - if tok != -1: - # divide the args - tokk = document.body[ertcont].find('>][') - if tokk != -1: - document.body[ertcont : ertcont + 1] = [document.body[ertcont][:tok], - '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2', + ertcontdivline = ertcontfirstline + tok = document.body[ertcontdivline].find('>][') + if tok == -1: + regexp = re.compile(r'.*>\]\[', re.IGNORECASE) + ertcontdivline = find_re(document.body, regexp, ertcontfirstline, ertcontlastline) + tok = document.body[ertcontdivline].find('>][') + if tok != -1: + # OK, we only have Argument 1 + Argument 3 + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertcontlastline : ertcontlastline + 1] = [ + document.body[ertcontlastline], '\\end_layout', '', '\\end_inset'] + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', '', 'status open' '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 2:]] + ertend += 17 + else: + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 2:]] + ertend += 12 + else: + # Check if we have Argument 2 + tok = document.body[ertcontdivline].find('>]<') + if tok == -1: + regexp = re.compile(r'.*>\]<', re.IGNORECASE) + ertcontdivline = find_re(document.body, regexp, ertcontfirstline, ertcontlastline) + tok = document.body[ertcontdivline].find('>]<') + if tok != -1: + # This is the division between Argument 1 + Argument 2 + # Check for Argument 3 + ertcontdivlinetwo = ercontdivline + tokk = document.body[ertcontdivlinetwo].find('>[') + if tokk == -1: + regexp = re.compile(r'.*>\[', re.IGNORECASE) + ertcontdivlinetwo = find_re(document.body, regexp, ertcontfirstline, ertcontlastline) + tokk = document.body[ertcontdivlinetwo].find('>]<') + if tokk != -1: + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertcontlastline : ertcontlastline + 1] = [ + document.body[ertcontlastline], '\\end_layout', '', '\\end_inset'] + document.body[ertcontdivlinetwo : ertcontdivlinetwo + 1] = [document.body[ertcontdivlinetwo][:tokk], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', '', 'status open' '', '\\begin_layout Plain Layout', + document.body[ertcontdivlinetwo][tokk + 3:]] + ertend += 17 + else: + document.body[ertcontdivlinetwo : ertcontdivlinetwo + 1] = [document.body[ertcontdivlinetwo][:tokk], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + document.body[ertcontdivlinetwo][tokk + 3:]] + ertend += 12 + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertcontlastline : ertcontlastline + 1] = [ + document.body[ertcontlastline], '\\end_layout', '', '\\end_inset'] + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', '', 'status open' '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 3:]] + ertend += 17 + else: + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2', + 'status collapsed', '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 3:]] + ertend += 12 + # Convert Argument 1 to ArgInset + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertend : ertend + 1] = [ + document.body[ertend], '\\end_layout', '', '\\end_inset'] + document.body[parbeg : parbeg + 1] = ['\\begin_inset Argument 1', 'status collapsed', '', '\\begin_layout Plain Layout', - document.body[ertcont][tok + 3:tokk], - '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + '\\begin_inset ERT', ''] + ertend += 8 + else: + document.body[parbeg] = "\\begin_inset Argument 1" + elif document.body[ertcontfirstline].startswith("<"): + # This is a action specification (Argument 2) + # strip off the < + document.body[ertcontfirstline] = document.body[ertcontfirstline][2:] + if document.body[ertcontlastline].endswith(">"): + # We only have Argument 2. This is easy: + # strip off the > + document.body[ertcontlastline] = document.body[ertcontlastline][:-1] + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertend : ertend + 1] = [ + document.body[ertend], '\\end_layout', '', '\\end_inset'] + document.body[parbeg : parbeg + 1] = ['\\begin_inset Argument 2', 'status collapsed', '', '\\begin_layout Plain Layout', - document.body[ertcont][tokk + 3:-1]] - ertend += 22 + '\\begin_inset ERT', ''] + ertend += 13 else: - tokk = document.body[ertcont].find('>[') - if tokk != -1: - document.body[ertcont : ertcont + 1] = [document.body[ertcont][:tokk], - '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + # Convert to ArgInset + document.body[parbeg] = "\\begin_inset Argument 2" + elif document.body[ertcontlastline].endswith("]"): + # We have Argument 2 + Argument 3 + # divide the args + ertcontdivline = ertcontfirstline + tok = document.body[ertcontdivline].find('>[') + if tok == -1: + regexp = re.compile(r'.*>\[', re.IGNORECASE) + ertcontdivline = find_re(document.body, regexp, ertcontfirstline, ertcontlastline) + tok = document.body[ertcontdivline].find('>[') + if tok != -1: + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertcontlastline : ertcontlastline + 1] = [ + document.body[ertcontlastline], '\\end_layout', '', '\\end_inset'] + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', '', 'status open' '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 2:]] + ertend += 17 + else: + document.body[ertcontdivline : ertcontdivline + 1] = [document.body[ertcontdivline][:tok], + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + document.body[ertcontdivline][tok + 2:]] + ertend += 12 + # Convert Argument 2 to ArgInset + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertend : ertend + 1] = [ + document.body[ertend], '\\end_layout', '', '\\end_inset'] + document.body[parbeg : parbeg + 1] = ['\\begin_inset Argument 2', 'status collapsed', '', '\\begin_layout Plain Layout', - document.body[ertcont][tokk + 2:-1]] - ertend += 11 - # Convert to ArgInset - document.body[parbeg] = "\\begin_inset Argument 1" - elif document.body[ertcont].startswith("["): - # This is an ERT option + '\\begin_inset ERT', ''] + ertend += 8 + else: + document.body[parbeg] = "\\begin_inset Argument 2" + elif document.body[ertcontfirstline].startswith("["): + # We only have Argument 3 # strip off the [ - document.body[ertcont] = document.body[ertcont][1:] - if document.body[ertcont].endswith("]"): + document.body[ertcontfirstline] = document.body[ertcontfirstline][1:] + if document.body[ertcontlastline].endswith("]"): # strip off the ] - document.body[ertcont] = document.body[ertcont][:-1] + document.body[ertcontlastline] = document.body[ertcontlastline][:-1] # Convert to ArgInset - document.body[parbeg] = "\\begin_inset Argument 3" + if ertcontfirstline < ertcontlastline: + # Multiline ERT. Might contain TeX code. Embrace in ERT. + document.body[ertcontlastline : ertcontlastline + 1] = [ + document.body[ertcontlastline], '\\end_layout', '', '\\end_inset'] + document.body[ertcontfirstline : ertcontfirstline + 1] = [ + '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3', + 'status collapsed', '', '\\begin_layout Plain Layout', + '\\begin_inset ERT', '', 'status open' '', '\\begin_layout Plain Layout', + document.body[ertcontfirstline]] + ertend += 16 + else: + document.body[parbeg] = "\\begin_inset Argument 3" parbeg = ertend + 3 continue return ertend