On 04/11/2014 01:51 PM, Vincent van Ravesteijn wrote:
Op 11 apr. 2014 19:46 schreef "Richard Heck" <[email protected]
<mailto:[email protected]>>:
>
> On 04/11/2014 01:04 PM, Vincent van Ravesteijn wrote:
>>>
>>> def revert_verbatim(document):
>>> " Revert verbatim einvironments completely to TeX-code. "
>>> i = 0
>>
>> [..]
>>
>>> while 1:
>>> i = find_token(document.body, "\\begin_layout Verbatim", i)
>>> if i == -1:
>>> return
>>> j = find_end_of_layout(document.body, i)
>>> if j == -1:
>>> document.warning("Malformed LyX document: Can't find
end of Verbatim layout")
>>> i += 1
>>> continue
>>> # delete all line breaks insets (there are no other insets)
>>> l = i
>>> while 1:
>>> n = find_token(document.body, "\\begin_inset Newline
newline", l)
>>> if n == -1:
>>> n = find_token(document.body, "\\begin_inset
Newline linebreak", l)
>>> if n == -1:
>>> break
>>> m = find_end_of_inset(document.body, n)
>>> del(document.body[m:m+1])
>>> document.body[n:n+1] = ['\end_layout', '',
'\\begin_layout Plain Layout']
>>> l += 1
>>> j += 1
>>
>> Did we just replace _all_ Newline insets in the whole document ?
>
>
> But there are none of those in this case. Still, it's a bug.
>
What do you mean? There are newlines at least somewhere in a footnote.
You'll find them if you search for "usepackage".
Sorry, my mistake. Anyway, I have a fix:
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index 2ec955d..c7768b1 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -741,10 +741,11 @@ def revert_verbatim(document):
'\\end_layout', '', '\\end_inset',
'', '', '\\end_layout']
subst_begin = ['\\begin_layout Standard', '\\noindent',
- '\\begin_inset ERT', 'status collapsed', '',
+ '\\begin_inset ERT', 'status open', '',
'\\begin_layout Plain Layout', '', '', '\\backslash',
'begin{verbatim}',
'\\end_layout', '', '\\begin_layout Plain Layout', '']
+
while 1:
i = find_token(document.body, "\\begin_layout Verbatim", i)
if i == -1:
@@ -757,16 +758,17 @@ def revert_verbatim(document):
# delete all line breaks insets (there are no other insets)
l = i
while 1:
- n = find_token(document.body, "\\begin_inset Newline
newline", l)
+ n = find_token(document.body, "\\begin_inset Newline
newline", l, j
if n == -1:
- n = find_token(document.body, "\\begin_inset Newline
linebreak"
+ n = find_token(document.body, "\\begin_inset Newline
linebreak"
if n == -1:
break
m = find_end_of_inset(document.body, n)
del(document.body[m:m+1])
document.body[n:n+1] = ['\end_layout', '', '\\begin_layout
Plain La
l += 1
- j += 1
+ # we deleted a line, so the end of the inset moved forward.
+ j -= 1
# consecutive verbatim environments need to be connected
k = find_token(document.body, "\\begin_layout Verbatim", j)
if k == j + 2 and consecutive == False:
OK to commit?
Richard