Handle LaTeX layout, and collapse consecutive ERT insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4851 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2002-08-02 20:34:20 +00:00
parent 7d2326f31f
commit 1bd999fa65
3 changed files with 59 additions and 11 deletions

View File

@ -1,3 +1,7 @@
2002-08-02 Dekel Tsur <dekelts@tau.ac.il>
* lyx2lyx/lyxconvert_218.py: Convert ERT and figinsets.
2002-07-30 André Pönitz <poenitz@gmx.net> 2002-07-30 André Pönitz <poenitz@gmx.net>
* configure.m4: * configure.m4:

View File

@ -155,24 +155,20 @@ def remove_oldminipage(lines):
i = i+1 i = i+1
def is_empty(lines): def is_empty(lines):
for line in lines: return filter(is_nonempty_line, lines) == []
line = line[:-1]
if line != " "*len(line):
return 0
return 1
font_rexp = re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun)") font_rexp = re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun)")
ert_rexp = re.compile(r"\\begin_inset|.*\\SpecialChar") ert_rexp = re.compile(r"\\begin_inset|.*\\SpecialChar")
spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)") spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)")
ert_begin = ["\\begin_inset ERT",
def remove_oldert(lines):
ert_begin = ["\\begin_inset ERT",
"status Collapsed", "status Collapsed",
"", "",
"\\layout Standard"] "\\layout Standard"]
def remove_oldert(lines):
i = 0 i = 0
while 1: while 1:
i = find_token(lines, "\\latex latex", i) i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i)
if i == -1: if i == -1:
break break
j = find_tokens(lines, ["\\latex default", "\\layout", "\\end_float"], j = find_tokens(lines, ["\\latex default", "\\layout", "\\end_float"],
@ -186,6 +182,10 @@ def remove_oldert(lines):
# We need to remove insets, special chars & font commands from ERT text # We need to remove insets, special chars & font commands from ERT text
new = [] new = []
new2 = [] new2 = []
if check_token(lines[i], "\\layout LaTeX"):
new = ["\layout Standard", "", ""]
# We have a problem with classes in which Standard is not the default layout!
k = i+1 k = i+1
while 1: while 1:
k2 = find_re(lines, ert_rexp, k, j) k2 = find_re(lines, ert_rexp, k, j)
@ -229,6 +229,37 @@ def remove_oldert(lines):
lines[i:j+1] = new lines[i:j+1] = new
i = i+1 i = i+1
def is_ert_paragraph(lines, i):
i = find_nonempty_line(lines, i+1)
if not check_token(lines[i], "\\begin_inset ERT"):
return 0
j = find_token(lines, "\\end_inset", i)
k = find_nonempty_line(lines, j+1)
return check_token(lines[k], "\\layout")
def combine_ert(lines):
i = 0
while 1:
i = find_token(lines, "\\begin_inset ERT", i)
if i == -1:
break
j = find_token_backwards(lines,"\\layout", i-1)
count = 0
text = []
while is_ert_paragraph(lines, 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:
lines[i+1:k] = text
i = i+1
oldunits = ["pt", "cm", "in", "text%", "col%"] oldunits = ["pt", "cm", "in", "text%", "col%"]
@ -316,6 +347,7 @@ def convert(header, body):
change_preamble(header) change_preamble(header)
remove_oldert(body) remove_oldert(body)
combine_ert(body)
remove_oldminipage(body) remove_oldminipage(body)
remove_oldfloat(body, language) remove_oldfloat(body, language)
remove_figinset(body) remove_figinset(body)

View File

@ -65,6 +65,18 @@ def get_value(lines, token, start, end = 0):
return "" return ""
return string.split(lines[i])[1] return string.split(lines[i])[1]
def is_nonempty_line(line):
line = line[:-1]
return line != " "*len(line)
def find_nonempty_line(lines, start, end = 0):
if end == 0:
end = len(lines)
for i in xrange(start, end):
if is_nonempty_line(lines[i]):
return i
return -1
def set_format(lines, number): def set_format(lines, number):
i = find_token(lines, "\\lyxformat", 0) i = find_token(lines, "\\lyxformat", 0)
lines[i] = "\\lyxformat %s" % number lines[i] = "\\lyxformat %s" % number