summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
b67c859)
+2006-02-05 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * LyX.py: new member is_default_layout()
+ * LyX.py: new member default_layout
+ * parser_tools.py (get_layout): new, extract layout name from line
+ * lyx_1_1_5.py, lyx_1_1_6.py, lyx_1_2.py, lyx_1_4.py: Replace all
+ occurences of the "Standard" layout with file.default_layout (bug 2026)
+
2006-02-02 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* lyx_1_4.py (remove_branches): new, remove branch insets
2006-02-02 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* lyx_1_4.py (remove_branches): new, remove branch insets
self.backend = "latex"
self.textclass = "article"
self.backend = "latex"
self.textclass = "article"
+ # This is a hack: We use '' since we don't know the default
+ # layout of the text class. LyX will parse it as default layout.
+ # FIXME: Read the layout file and use the real default layout
+ self.default_layout = ''
self.header = []
self.preamble = []
self.body = []
self.header = []
self.preamble = []
self.body = []
self.header[i] = '\\%s %s' % (param, str(value))
self.header[i] = '\\%s %s' % (param, str(value))
+ def is_default_layout(self, layout):
+ " Check whether a layout is the default layout of this class."
+ # FIXME: Check against the real text class default layout
+ if layout == 'Standard' or layout == self.default_layout:
+ return 1
+ return 0
+
+
def convert(self):
"Convert from current (self.format) to self.end_format."
mode, convertion_chain = self.chain()
def convert(self):
"Convert from current (self.format) to self.end_format."
mode, convertion_chain = self.chain()
-from parser_tools import find_token, find_token_backwards, find_re
+from parser_tools import find_token, find_token_backwards, find_re, get_layout
-layout_exp = re.compile(r"\\layout (\S*)")
math_env = ["\\[","\\begin{eqnarray*}","\\begin{eqnarray}","\\begin{equation}"]
def replace_protected_separator(file):
math_env = ["\\[","\\begin{eqnarray*}","\\begin{eqnarray}","\\begin{equation}"]
def replace_protected_separator(file):
break
j = find_token_backwards(lines, "\\layout", i)
#if j == -1: print error
break
j = find_token_backwards(lines, "\\layout", i)
#if j == -1: print error
- layout_m = layout_exp.match(lines[j])
- if layout_m:
- layout = layout_m.group(1)
- else:
- layout = "Standard"
+ layout = get_layout(lines[j], file.default_layout)
if layout == "LyX-Code":
result = ""
if layout == "LyX-Code":
result = ""
while (lines[0] == ""):
del lines[0]
if lines[0][:7] != "\\layout":
while (lines[0] == ""):
del lines[0]
if lines[0][:7] != "\\layout":
- lines[:0] = ["\\layout Standard"]
+ lines[:0] = ['\\layout %s' % file.default_layout, '']
def remove_space_in_units(file):
def remove_space_in_units(file):
tmp.append('<Cell multicolumn="%s" alignment="%s" valignment="0" topline="%s" bottomline="%s" leftline="%d" rightline="%d" rotate="%s" usebox="%s" width=%s special=%s>' % (cell_info[m][0],cell_info[m][1],cell_info[m][2],cell_info[m][3],leftline,rightline,cell_info[m][5],cell_info[m][6],cell_info[m][7],cell_info[m][8]))
tmp.append('\\begin_inset Text')
tmp.append('')
tmp.append('<Cell multicolumn="%s" alignment="%s" valignment="0" topline="%s" bottomline="%s" leftline="%d" rightline="%d" rotate="%s" usebox="%s" width=%s special=%s>' % (cell_info[m][0],cell_info[m][1],cell_info[m][2],cell_info[m][3],leftline,rightline,cell_info[m][5],cell_info[m][6],cell_info[m][7],cell_info[m][8]))
tmp.append('\\begin_inset Text')
tmp.append('')
- tmp.append('\\layout Standard')
+ tmp.append('\\layout %s' % file.default_layout)
tmp.append('')
if cell_info[m][0] != '2':
tmp.append('')
if cell_info[m][0] != '2':
from parser_tools import find_token, find_token_backwards, get_next_paragraph,\
find_tokens, find_end_of_inset, find_re, \
is_nonempty_line, get_paragraph, find_nonempty_line, \
from parser_tools import find_token, find_token_backwards, get_next_paragraph,\
find_tokens, find_end_of_inset, find_re, \
is_nonempty_line, get_paragraph, find_nonempty_line, \
- get_value, get_tabular_lines, check_token
+ get_value, get_tabular_lines, check_token, get_layout
floats = {
"footnote": ["\\begin_inset Foot",
floats = {
"footnote": ["\\begin_inset Foot",
if hfill:
start = ["","\hfill",""]+start
else:
if hfill:
start = ["","\hfill",""]+start
else:
- start = ["\\layout Standard"] + start
+ start = ['\\layout %s' % file.default_layout,''] + start
j0 = find_token_backwards(lines,"\\layout", i-1)
j = get_next_paragraph(lines, i, file.format + 1)
j0 = find_token_backwards(lines,"\\layout", i-1)
j = get_next_paragraph(lines, i, file.format + 1)
move_rexp = re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun|end_deeper)")
ert_rexp = re.compile(r"\\begin_inset|\\hfill|.*\\SpecialChar")
spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)")
move_rexp = re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun|end_deeper)")
ert_rexp = re.compile(r"\\begin_inset|\\hfill|.*\\SpecialChar")
spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)")
-ert_begin = ["\\begin_inset ERT",
- "status Collapsed",
- "",
- "\\layout Standard"]
+ ert_begin = ["\\begin_inset ERT",
+ "status Collapsed",
+ "",
+ '\\layout %s' % file.default_layout,
+ ""]
lines = file.body
i = 0
while 1:
lines = file.body
i = 0
while 1:
new = []
new2 = []
if check_token(lines[i], "\\layout LaTeX"):
new = []
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!
+ new = ['\layout %s' % file.default_layout, "", ""]
-def is_ert_paragraph(lines, i):
- if not check_token(lines[i], "\\layout Standard"):
+def is_ert_paragraph(file, i):
+ lines = file.body
+ if not check_token(lines[i], "\\layout"):
+ return 0
+ if not file.is_default_layout(get_layout(lines[i], file.default_layout)):
return 0
i = find_nonempty_line(lines, i+1)
return 0
i = find_nonempty_line(lines, i+1)
j = get_paragraph(lines, i, file.format + 1)
count = 0
text = []
j = get_paragraph(lines, i, file.format + 1)
count = 0
text = []
- while is_ert_paragraph(lines, j):
+ while is_ert_paragraph(file, j):
count = count+1
i2 = find_token(lines, "\\layout", j+1)
count = count+1
i2 = find_token(lines, "\\layout", j+1)
note_lines = [txt]+note_lines
for line in note_lines:
note_lines = [txt]+note_lines
for line in note_lines:
- new = new + ["\layout Standard", ""]
+ new = new + ['\layout %s' % file.default_layout, ""]
tmp = string.split(line, '\\')
new = new + [tmp[0]]
for x in tmp[1:]:
tmp = string.split(line, '\\')
new = new + [tmp[0]]
for x in tmp[1:]:
import os.path
from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
get_paragraph, get_value, del_token, is_nonempty_line,\
import os.path
from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
get_paragraph, get_value, del_token, is_nonempty_line,\
- find_tokens, find_end_of, find_token2, find_re
+ find_tokens, find_end_of, find_token2, find_re,\
+ get_layout
from sys import stdin
from string import replace, split, find, strip, join
from sys import stdin
from string import replace, split, find, strip, join
file.body[i+1:i+1] = ''
if space == "\\space":
space = "\\ "
file.body[i+1:i+1] = ''
if space == "\\space":
space = "\\ "
- i = insert_ert(file.body, i+1, 'Collapsed', space, file.format - 1)
+ i = insert_ert(file.body, i+1, 'Collapsed', space, file.format - 1, file.default_layout)
##
# \InsetSpace \, -> \InsetSpace \thinspace{}
##
# \InsetSpace \, -> \InsetSpace \thinspace{}
break
eqref = lyx_support_escape(regexp.sub("", file.body[i]))
file.body[i:i+1] = ["\\begin_inset ERT", "status Collapsed", "",
break
eqref = lyx_support_escape(regexp.sub("", file.body[i]))
file.body[i:i+1] = ["\\begin_inset ERT", "status Collapsed", "",
- "\\layout Standard", "", "\\backslash ",
+ '\\layout %s' % file.default_layout, "", "\\backslash ",
"eqref" + eqref]
i = i + 7
"eqref" + eqref]
i = i + 7
- file.body[i:i+1] = ["\\layout Standard","","",
+ file.body[i:i+1] = ['\\layout %s' % file.default_layout,"","",
"\\begin_inset Comment",
"collapsed true","",
"\\begin_inset Comment",
"collapsed true","",
+ '\\layout %s' % file.default_layout]
file.body[i:i] = ["\\end_inset"]
i = i + 1
break
file.body[i:i] = ["\\end_inset"]
i = i + 1
break
- file.body[i:i+1] = ["\\layout Standard"]
+ file.body[i:i+1] = ['\\layout %s' % file.default_layout]
i = find_token(file.body, "\\begin_layout", i)
if i == -1:
return
i = find_token(file.body, "\\begin_layout", i)
if i == -1:
return
- layout = split(file.body[i])[1]
+ layout = get_layout(file.body[i], file.default_layout)
i = i + 1
# Merge all paragraph parameters into a single line
i = i + 1
# Merge all paragraph parameters into a single line
# We want to avoid new paragraphs if possible becauase we want to
# inherit font sizes.
nonstandard = 0
# We want to avoid new paragraphs if possible becauase we want to
# inherit font sizes.
nonstandard = 0
- if (layout != "Standard" or find(file.body[i],"\\align") != -1 or
+ if (not file.is_default_layout(layout) or
+ find(file.body[i],"\\align") != -1 or
find(file.body[i],"\\labelwidthstring") != -1 or
find(file.body[i],"\\noindent") != -1):
nonstandard = 1
find(file.body[i],"\\labelwidthstring") != -1 or
find(file.body[i],"\\noindent") != -1):
nonstandard = 1
paragraph_above = list()
if nonstandard:
# We need to create an extra paragraph for nonstandard environments
paragraph_above = list()
if nonstandard:
# We need to create an extra paragraph for nonstandard environments
- paragraph_above = ['\\begin_layout Standard', '']
+ paragraph_above = ['\\begin_layout %s' % file.default_layout, '']
if pb_top != -1:
paragraph_above.extend(['\\newpage ',''])
if pb_top != -1:
paragraph_above.extend(['\\newpage ',''])
# We can't use the vspace inset because it does not know \parskip.
paragraph_above.extend(['\\lyxline ', '', ''])
insert_ert(paragraph_above, len(paragraph_above) - 1, 'Collapsed',
# We can't use the vspace inset because it does not know \parskip.
paragraph_above.extend(['\\lyxline ', '', ''])
insert_ert(paragraph_above, len(paragraph_above) - 1, 'Collapsed',
- '\\vspace{-1\\parskip}\n', file.format + 1)
+ '\\vspace{-1\\parskip}\n', file.format + 1, file.default_layout)
paragraph_above.extend([''])
if nonstandard:
paragraph_above.extend([''])
if nonstandard:
paragraph_below = list()
if nonstandard:
# We need to create an extra paragraph for nonstandard environments
paragraph_below = list()
if nonstandard:
# We need to create an extra paragraph for nonstandard environments
- paragraph_below = ['', '\\begin_layout Standard', '']
+ paragraph_below = ['', '\\begin_layout %s' % file.default_layout, '']
else:
for a in range(len(font_attributes)):
if find_token(file.body, font_attributes[a], i, k) != -1:
else:
for a in range(len(font_attributes)):
if find_token(file.body, font_attributes[a], i, k) != -1:
# -------------------------------------------------------------------------------------------
# Convert backslashes and '\n' into valid ERT code, append the converted
# text to body[i] and return the (maybe incremented) line index i
# -------------------------------------------------------------------------------------------
# Convert backslashes and '\n' into valid ERT code, append the converted
# text to body[i] and return the (maybe incremented) line index i
-def convert_ertbackslash(body, i, ert, format):
+def convert_ertbackslash(body, i, ert, format, default_layout):
for c in ert:
if c == '\\':
body[i] = body[i] + '\\backslash '
for c in ert:
if c == '\\':
body[i] = body[i] + '\\backslash '
body[i+1:i+1] = ['\\newline ', '']
i = i + 2
else:
body[i+1:i+1] = ['\\newline ', '']
i = i + 2
else:
- body[i+1:i+1] = ['\\end_layout', '', '\\begin_layout Standard', '']
+ body[i+1:i+1] = ['\\end_layout', '', '\\begin_layout %s' % default_layout, '']
i = i + 4
else:
body[i] = body[i] + c
i = i + 4
else:
body[i] = body[i] + c
# The others are converted in the next loop runs (if they exist)
if insets[0] == "vspace":
file.body[i:i+1] = ['\\begin_inset ERT', 'status Collapsed', '',
# The others are converted in the next loop runs (if they exist)
if insets[0] == "vspace":
file.body[i:i+1] = ['\\begin_inset ERT', 'status Collapsed', '',
- '\\layout Standard', '', '\\backslash ']
+ '\\layout %s' % file.default_layout, '', '\\backslash ']
i = i + 6
if spaceamount[0][-1] == '*':
spaceamount[0] = spaceamount[0][:-1]
i = i + 6
if spaceamount[0][-1] == '*':
spaceamount[0] = spaceamount[0][:-1]
file.body.insert(i, 'vspace*{')
else:
file.body.insert(i, 'vspace{')
file.body.insert(i, 'vspace*{')
else:
file.body.insert(i, 'vspace{')
- i = convert_ertbackslash(file.body, i, spaceamount[0], file.format - 1)
+ i = convert_ertbackslash(file.body, i, spaceamount[0], file.format - 1, file.default_layout)
file.body[i] = file.body[i] + '}'
i = i + 1
elif insets[0] == "lyxline":
file.body[i] = file.body[i] + '}'
i = i + 1
elif insets[0] == "lyxline":
latexsize = '\\normalsize'
i = insert_ert(file.body, i, 'Collapsed',
'\\lyxline{%s}' % latexsize,
latexsize = '\\normalsize'
i = insert_ert(file.body, i, 'Collapsed',
'\\lyxline{%s}' % latexsize,
+ file.format - 1, file.default_layout)
# We use \providecommand so that we don't get an error if native
# lyxlines are used (LyX writes first its own preamble and then
# the user specified one)
# We use \providecommand so that we don't get an error if native
# lyxlines are used (LyX writes first its own preamble and then
# the user specified one)
elif insets[0] == "newpage":
file.body[i] = ''
i = insert_ert(file.body, i, 'Collapsed', '\\newpage{}',
elif insets[0] == "newpage":
file.body[i] = ''
i = insert_ert(file.body, i, 'Collapsed', '\\newpage{}',
+ file.format - 1, file.default_layout)
# Convert a LyX length into a LaTeX length
# Convert a LyX length into a LaTeX length
# Convert a LyX length into valid ERT code and append it to body[i]
# Return the (maybe incremented) line index i
# Convert a LyX length into valid ERT code and append it to body[i]
# Return the (maybe incremented) line index i
-def convert_ertlen(body, i, len, special, format):
+def convert_ertlen(body, i, len, special, format, default_layout):
# Convert backslashes and insert the converted length into body
# Convert backslashes and insert the converted length into body
- return convert_ertbackslash(body, i, convert_len(len, special), format)
+ return convert_ertbackslash(body, i, convert_len(len, special), format, default_layout)
# Return the value of len without the unit in numerical form
# Return the value of len without the unit in numerical form
# Convert text to ERT and insert it at body[i]
# Return the index of the line after the inserted ERT
# Convert text to ERT and insert it at body[i]
# Return the index of the line after the inserted ERT
-def insert_ert(body, i, status, text, format):
+def insert_ert(body, i, status, text, format, default_layout):
body[i:i] = ['\\begin_inset ERT', 'status ' + status, '']
i = i + 3
if format <= 224:
body[i:i] = ['\\begin_inset ERT', 'status ' + status, '']
i = i + 3
if format <= 224:
- body[i:i] = ['\\layout Standard', '']
+ body[i:i] = ['\\layout %s' % default_layout, '']
- body[i:i] = ['\\begin_layout Standard', '']
+ body[i:i] = ['\\begin_layout %s' % default_layout, '']
i = i + 1 # i points now to the just created empty line
i = i + 1 # i points now to the just created empty line
- i = convert_ertbackslash(body, i, text, format) + 1
+ i = convert_ertbackslash(body, i, text, format, default_layout) + 1
if format > 224:
body[i:i] = ['\\end_layout']
i = i + 1
if format > 224:
body[i:i] = ['\\end_layout']
i = i + 1
ert = ert + '\\let\\endminipage\\endlyxtolyxminipage%\n'
old_i = i
ert = ert + '\\let\\endminipage\\endlyxtolyxminipage%\n'
old_i = i
- i = insert_ert(file.body, i, 'Collapsed', ert, file.format - 1)
+ i = insert_ert(file.body, i, 'Collapsed', ert, file.format - 1, file.default_layout)
j = j + i - old_i - 1
file.body[i:i] = ['\\begin_inset Minipage',
j = j + i - old_i - 1
file.body[i:i] = ['\\begin_inset Minipage',
# Restore the original minipage environment since we may have
# minipages inside this box.
# Start a new paragraph because the following may be nonstandard
# Restore the original minipage environment since we may have
# minipages inside this box.
# Start a new paragraph because the following may be nonstandard
- file.body[i:i] = ['\\layout Standard', '', '']
+ file.body[i:i] = ['\\layout %s' % file.default_layout, '', '']
i = i + 2
j = j + 3
ert = '\\let\\minipage\\lyxtolyxrealminipage%\n'
ert = ert + '\\let\\endminipage\\lyxtolyxrealendminipage%'
old_i = i
i = i + 2
j = j + 3
ert = '\\let\\minipage\\lyxtolyxrealminipage%\n'
ert = ert + '\\let\\endminipage\\lyxtolyxrealendminipage%'
old_i = i
- i = insert_ert(file.body, i, 'Collapsed', ert, file.format - 1)
+ i = insert_ert(file.body, i, 'Collapsed', ert, file.format - 1, file.default_layout)
j = j + i - old_i - 1
# Redefine the minipage end before the inset end.
# Start a new paragraph because the previous may be nonstandard
j = j + i - old_i - 1
# Redefine the minipage end before the inset end.
# Start a new paragraph because the previous may be nonstandard
- file.body[j:j] = ['\\layout Standard', '', '']
+ file.body[j:j] = ['\\layout %s' % file.default_layout, '', '']
j = j + 2
ert = '\\let\\endminipage\\endlyxtolyxminipage'
j = j + 2
ert = '\\let\\endminipage\\endlyxtolyxminipage'
- j = insert_ert(file.body, j, 'Collapsed', ert, file.format - 1)
+ j = insert_ert(file.body, j, 'Collapsed', ert, file.format - 1, file.default_layout)
j = j + 1
file.body.insert(j, '')
j = j + 1
j = j + 1
file.body.insert(j, '')
j = j + 1
ert = '}%\n'
else:
ert = '\\end{lyxtolyxrealminipage}%\n'
ert = '}%\n'
else:
ert = '\\end{lyxtolyxrealminipage}%\n'
- j = insert_ert(file.body, j, 'Collapsed', ert, file.format - 1)
+ j = insert_ert(file.body, j, 'Collapsed', ert, file.format - 1, file.default_layout)
# We don't need to restore the original minipage after the inset
# end because the scope of the redefinition is the original box.
# We don't need to restore the original minipage after the inset
# end because the scope of the redefinition is the original box.
"\\begin_inset CharStyle Firstname",
"status inlined",
"",
"\\begin_inset CharStyle Firstname",
"status inlined",
"",
- "\\begin_layout Standard",
+ '\\begin_layout %s' % file.default_layout,
"",
"%s" % firstname,
"\end_layout",
"",
"%s" % firstname,
"\end_layout",
"\\begin_inset CharStyle Surname",
"status inlined",
"",
"\\begin_inset CharStyle Surname",
"status inlined",
"",
- "\\begin_layout Standard",
+ '\\begin_layout %s' % file.default_layout,
"",
"%s" % surname,
"\\end_layout",
"",
"%s" % surname,
"\\end_layout",
k = find_token(file.body, "\\begin_layout", k, j)
if k == -1:
break
k = find_token(file.body, "\\begin_layout", k, j)
if k == -1:
break
- file.body[k] = "\\begin_layout Standard"
+ file.body[k] = '\\begin_layout %s' % file.default_layout
k = k + 1
# remove all paragraph parameters and font settings
k = k + 1
# remove all paragraph parameters and font settings
k = i
first_pagraph = 1
while 1:
k = i
first_pagraph = 1
while 1:
- k = find_token(file.body, "\\begin_layout Standard", k, j)
+ k = find_token(file.body, "\\begin_layout", k, j)
if k == -1:
break
if first_pagraph:
first_pagraph = 0
k = k + 1
continue
if k == -1:
break
if first_pagraph:
first_pagraph = 0
k = k + 1
continue
- file.body[k:k] = ["\\begin_layout Standard", "",
+ file.body[k:k] = ['\\begin_layout %s' % file.default_layout, "",
"\\end_layout", ""]
k = k + 5
j = j + 4
"\\end_layout", ""]
k = k + 5
j = j + 4
k = find_token(file.body, "\\newline", k, j)
if k == -1:
break
k = find_token(file.body, "\\newline", k, j)
if k == -1:
break
- file.body[k:k+1] = ["\\end_layout", "", "\\begin_layout Standard"]
+ file.body[k:k+1] = ["\\end_layout", "", '\\begin_layout %s' % file.default_layout]
+ # We need an empty line if file.default_layout == ''
+ if file.body[k-1] != '':
+ file.body.insert(k-1, '')
+ k = k + 1
+ j = j + 1
l = l + 1
if strip(file.body[l]) and split(file.body[l])[0] == "\\newline":
file.body[k:l+1] = ["\\end_layout", "",
l = l + 1
if strip(file.body[l]) and split(file.body[l])[0] == "\\newline":
file.body[k:l+1] = ["\\end_layout", "",
- "\\begin_layout Standard"]
+ '\\begin_layout %s' % file.default_layout]
j = j - l + k + 2
k = k + 3
j = j - l + k + 2
k = k + 3
+ # We need an empty line if file.default_layout == ''
+ if file.body[l+1] != '':
+ file.body.insert(l+1, '')
+ k = k + 1
+ j = j + 1
else:
k = k + 1
i = i + 1
else:
k = k + 1
i = i + 1
+def get_layout(line, default_layout):
+ tokens = string.split(line)
+ if len(tokens) > 1:
+ return tokens[1]
+ return default_layout
+
+
def del_token(lines, token, i, j):
k = find_token2(lines, token, i, j)
if k == -1:
def del_token(lines, token, i, j):
k = find_token2(lines, token, i, j)
if k == -1: