Am Samstag, 4. Februar 2006 11:33 schrieb Lars Gullik Bjønnes:
> This sounds like a hack that will actually be usefull.
> Go ahead with creating the patch.
Here it is (2026-4.diff). I tested it with a lot of files, and the lyx2lyx
conversion works. Yesterday I only tested commandline export, so the bad
news is that LyX 1.4 pops up the error list with
Layout '""' does not exist in textclass 'book'
Trying to use the default instead.
LyX 1.3 only displays the same text on stderr.
That means that we don't gain anything with the patch :-((
I therefore propose again to add the Standard layout programmatically, see
an enhanced version in 2026-5.diff
Jean-Marc, we could of course also combine both patches and use the
<default> layout that you proposed. That would be 2026-6.diff.
Georg
Index: lib/lyx2lyx/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/ChangeLog,v
retrieving revision 1.107
diff -u -p -r1.107 ChangeLog
--- lib/lyx2lyx/ChangeLog 2 Feb 2006 21:30:03 -0000 1.107
+++ lib/lyx2lyx/ChangeLog 4 Feb 2006 14:22:34 -0000
@@ -1,3 +1,10 @@
+2006-02-04 Georg Baum <[EMAIL PROTECTED]>
+
+ * LyX.py: new member is_default_layout()
+ * LyX.py: new member default_layout
+ * 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 <[EMAIL PROTECTED]>
* lyx_1_4.py (remove_branches): new, remove branch insets
Index: lib/lyx2lyx/LyX.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/LyX.py,v
retrieving revision 1.28
diff -u -p -r1.28 LyX.py
--- lib/lyx2lyx/LyX.py 1 Dec 2005 19:00:07 -0000 1.28
+++ lib/lyx2lyx/LyX.py 4 Feb 2006 14:22:35 -0000
@@ -111,6 +111,10 @@ class LyX_Base:
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 = []
@@ -289,6 +293,14 @@ class LyX_Base:
self.warning('Parameter not found in the header: %s' % param, 3)
return
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):
Index: lib/lyx2lyx/lyx_1_1_5.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_1_5.py,v
retrieving revision 1.7
diff -u -p -r1.7 lyx_1_1_5.py
--- lib/lyx2lyx/lyx_1_1_5.py 18 Aug 2005 17:33:26 -0000 1.7
+++ lib/lyx2lyx/lyx_1_1_5.py 4 Feb 2006 14:22:35 -0000
@@ -37,7 +37,7 @@ def replace_protected_separator(file):
if layout_m:
layout = layout_m.group(1)
else:
- layout = "Standard"
+ layout = file.default_layout
if layout == "LyX-Code":
result = ""
@@ -130,7 +130,7 @@ def first_layout(file):
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):
Index: lib/lyx2lyx/lyx_1_1_6.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_1_6.py,v
retrieving revision 1.4
diff -u -p -r1.4 lyx_1_1_6.py
--- lib/lyx2lyx/lyx_1_1_6.py 5 Jan 2005 18:52:59 -0000 1.4
+++ lib/lyx2lyx/lyx_1_1_6.py 4 Feb 2006 14:22:35 -0000
@@ -146,7 +146,7 @@ def update_tabular(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('\\layout Standard')
+ tmp.append('\\layout %s' % file.default_layout)
tmp.append('')
if cell_info[m][0] != '2':
Index: lib/lyx2lyx/lyx_1_2.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_2.py,v
retrieving revision 1.11
diff -u -p -r1.11 lyx_1_2.py
--- lib/lyx2lyx/lyx_1_2.py 20 Sep 2005 12:47:45 -0000 1.11
+++ lib/lyx2lyx/lyx_1_2.py 4 Feb 2006 14:22:35 -0000
@@ -179,7 +179,7 @@ def remove_pextra(file):
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)
@@ -216,13 +216,13 @@ def is_empty(lines):
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"]
def remove_oldert(file):
+ ert_begin = ["\\begin_inset ERT",
+ "status Collapsed",
+ "",
+ '\\layout %s' % file.default_layout]
lines = file.body
i = 0
while 1:
@@ -248,8 +248,7 @@ def remove_oldert(file):
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, "", ""]
k = i+1
while 1:
@@ -349,8 +348,12 @@ def remove_oldertinset(file):
i = i+1
-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
+ tokens = string.split(lines[i])
+ if len(tokens) < 2 or not file.is_default_layout(tokens[1]):
return 0
i = find_nonempty_line(lines, i+1)
@@ -372,7 +375,7 @@ def combine_ert(file):
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)
@@ -721,7 +724,7 @@ def change_infoinset(file):
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:]:
Index: lib/lyx2lyx/lyx_1_4.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_4.py,v
retrieving revision 1.56
diff -u -p -r1.56 lyx_1_4.py
--- lib/lyx2lyx/lyx_1_4.py 2 Feb 2006 21:30:04 -0000 1.56
+++ lib/lyx2lyx/lyx_1_4.py 4 Feb 2006 14:22:35 -0000
@@ -81,7 +81,7 @@ def revert_spaces(file):
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{}
@@ -129,7 +129,7 @@ def revert_eqref(file):
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
@@ -251,10 +251,10 @@ def convert_comment(file):
if i == -1:
return
- file.body[i:i+1] = ["\\layout Standard","","",
+ file.body[i:i+1] = ['\\layout %s' % file.default_layout,"","",
"\\begin_inset Comment",
"collapsed true","",
- "\\layout Standard"]
+ '\\layout %s' % file.default_layout]
i = i + 7
while 1:
@@ -303,7 +303,7 @@ def convert_comment(file):
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 = i + 1
@@ -597,7 +597,8 @@ def convert_breaks(file):
# 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
@@ -640,7 +641,7 @@ def convert_breaks(file):
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 ',''])
@@ -655,7 +656,7 @@ def convert_breaks(file):
# 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:
@@ -692,7 +693,7 @@ def convert_breaks(file):
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:
@@ -993,7 +994,7 @@ def convert_minipage(file):
# -------------------------------------------------------------------------------------------
# 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 '
@@ -1004,7 +1005,7 @@ def convert_ertbackslash(body, i, ert, f
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
@@ -1313,7 +1314,7 @@ def revert_breaks(file):
# 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]
@@ -1345,7 +1346,7 @@ def revert_breaks(file):
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_format)
file.body[i] = file.body[i] + '}'
i = i + 1
elif insets[0] == "lyxline":
@@ -1356,7 +1357,7 @@ def revert_breaks(file):
latexsize = '\\normalsize'
i = insert_ert(file.body, i, 'Collapsed',
'\\lyxline{%s}' % latexsize,
- file.format - 1)
+ 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)
@@ -1368,7 +1369,7 @@ def revert_breaks(file):
elif insets[0] == "newpage":
file.body[i] = ''
i = insert_ert(file.body, i, 'Collapsed', '\\newpage{}',
- file.format - 1)
+ file.format - 1, file.default_layout)
# Convert a LyX length into a LaTeX length
@@ -1392,9 +1393,9 @@ def convert_len(len, special):
# 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_format):
# 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_format)
# Return the value of len without the unit in numerical form
@@ -1408,15 +1409,15 @@ def len2value(len):
# 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] = ['\\layout Standard', '']
+ body[i:i] = ['\\layout %s' % default_layout, '']
else:
- 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 = 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
@@ -1557,7 +1558,7 @@ def convert_frameless_box(file):
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',
@@ -1572,21 +1573,21 @@ def convert_frameless_box(file):
# 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 = 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
- file.body[j:j] = ['\\layout Standard', '', '']
+ file.body[j:j] = ['\\layout %s' % file.default_layout, '', '']
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
@@ -1597,7 +1598,7 @@ def convert_frameless_box(file):
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.
@@ -1841,7 +1842,7 @@ def convert_names(file):
"\\begin_inset CharStyle Firstname",
"status inlined",
"",
- "\\begin_layout Standard",
+ '\\begin_layout %s' % file.default_layout,
"",
"%s" % firstname,
"\end_layout",
@@ -1852,7 +1853,7 @@ def convert_names(file):
"\\begin_inset CharStyle Surname",
"status inlined",
"",
- "\\begin_layout Standard",
+ '\\begin_layout %s' % file.default_layout,
"",
"%s" % surname,
"\\end_layout",
@@ -2179,7 +2180,7 @@ def convert_ert_paragraphs(file):
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
@@ -2196,14 +2197,14 @@ def convert_ert_paragraphs(file):
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
- 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
@@ -2214,7 +2215,7 @@ def convert_ert_paragraphs(file):
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]
k = k + 4
j = j + 3
i = i + 1
@@ -2257,7 +2258,7 @@ def revert_ert_paragraphs(file):
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
else:
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2369
diff -u -p -r1.2369 ChangeLog
--- src/ChangeLog 3 Feb 2006 21:47:24 -0000 1.2369
+++ src/ChangeLog 4 Feb 2006 15:39:54 -0000
@@ -1,3 +1,8 @@
+2006-02-04 Georg Baum <[EMAIL PROTECTED]>
+
+ * lyxtextclass.C (Read): Add Standard layout for lyx2lyx compatibility
+ * lyxlayout.[Ch] (setObsoltetedBy): new, needed for the above
+
2006-02-02 Georg Baum <[EMAIL PROTECTED]>
* exporter.C (Backends): Add "lyx" backend
Index: src/lyxlayout.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.C,v
retrieving revision 1.28
diff -u -p -r1.28 lyxlayout.C
--- src/lyxlayout.C 12 May 2005 10:16:04 -0000 1.28
+++ src/lyxlayout.C 4 Feb 2006 15:39:54 -0000
@@ -812,6 +812,12 @@ string const & LyXLayout::obsoleted_by()
}
+void LyXLayout::setObsoletedBy(string const & obsoleted_by)
+{
+ obsoleted_by_ = obsoleted_by;
+}
+
+
string const & LyXLayout::depends_on() const
{
return depends_on_;
Index: src/lyxlayout.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.h,v
retrieving revision 1.20
diff -u -p -r1.20 lyxlayout.h
--- src/lyxlayout.h 12 May 2005 10:16:04 -0000 1.20
+++ src/lyxlayout.h 4 Feb 2006 15:39:54 -0000
@@ -51,6 +51,8 @@ public:
///
std::string const & obsoleted_by() const;
///
+ void setObsoletedBy(std::string const &);
+ ///
std::string const & depends_on() const;
///
std::string const & latexname() const { return latexname_; }
Index: src/lyxtextclass.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtextclass.C,v
retrieving revision 1.52
diff -u -p -r1.52 lyxtextclass.C
--- src/lyxtextclass.C 2 Nov 2005 20:11:35 -0000 1.52
+++ src/lyxtextclass.C 4 Feb 2006 15:39:54 -0000
@@ -470,6 +470,15 @@ bool LyXTextClass::Read(string const & f
<< "Minimum TocLevel is " << min_toclevel_
<< ", maximum is " << max_toclevel_ <<endl;
+ // lyx2lyx can produce "Standard" layouts when it actually
+ // means the default layout, so we need to add one here.
+ if (!error && !hasLayout("Standard")) {
+ boost::shared_ptr<LyXLayout> lay(new LyXLayout);
+ *lay = *(operator[](defaultlayout_));
+ lay->setName("Standard");
+ lay->setObsoletedBy(defaultlayout_);
+ layoutlist_.push_back(lay);
+ }
} else
lyxerr[Debug::TCLASS] << "Finished reading input file "
<< MakeDisplayPath(filename)
Index: lib/lyx2lyx/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/ChangeLog,v
retrieving revision 1.107
diff -u -p -r1.107 ChangeLog
--- lib/lyx2lyx/ChangeLog 2 Feb 2006 21:30:03 -0000 1.107
+++ lib/lyx2lyx/ChangeLog 4 Feb 2006 15:50:08 -0000
@@ -1,3 +1,10 @@
+2006-02-04 Georg Baum <[EMAIL PROTECTED]>
+
+ * LyX.py: new member is_default_layout()
+ * LyX.py: new member default_layout
+ * 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 <[EMAIL PROTECTED]>
* lyx_1_4.py (remove_branches): new, remove branch insets
Index: lib/lyx2lyx/LyX.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/LyX.py,v
retrieving revision 1.28
diff -u -p -r1.28 LyX.py
--- lib/lyx2lyx/LyX.py 1 Dec 2005 19:00:07 -0000 1.28
+++ lib/lyx2lyx/LyX.py 4 Feb 2006 15:50:08 -0000
@@ -111,6 +111,10 @@ class LyX_Base:
self.backend = "latex"
self.textclass = "article"
+ # This is a hack: We use '<default>' 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 = '<default>'
self.header = []
self.preamble = []
self.body = []
@@ -289,6 +293,14 @@ class LyX_Base:
self.warning('Parameter not found in the header: %s' % param, 3)
return
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):
Index: lib/lyx2lyx/lyx_1_1_5.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_1_5.py,v
retrieving revision 1.7
diff -u -p -r1.7 lyx_1_1_5.py
--- lib/lyx2lyx/lyx_1_1_5.py 18 Aug 2005 17:33:26 -0000 1.7
+++ lib/lyx2lyx/lyx_1_1_5.py 4 Feb 2006 15:50:08 -0000
@@ -37,7 +37,7 @@ def replace_protected_separator(file):
if layout_m:
layout = layout_m.group(1)
else:
- layout = "Standard"
+ layout = file.default_layout
if layout == "LyX-Code":
result = ""
@@ -130,7 +130,7 @@ def first_layout(file):
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):
Index: lib/lyx2lyx/lyx_1_1_6.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_1_6.py,v
retrieving revision 1.4
diff -u -p -r1.4 lyx_1_1_6.py
--- lib/lyx2lyx/lyx_1_1_6.py 5 Jan 2005 18:52:59 -0000 1.4
+++ lib/lyx2lyx/lyx_1_1_6.py 4 Feb 2006 15:50:08 -0000
@@ -146,7 +146,7 @@ def update_tabular(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('\\layout Standard')
+ tmp.append('\\layout %s' % file.default_layout)
tmp.append('')
if cell_info[m][0] != '2':
Index: lib/lyx2lyx/lyx_1_2.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_2.py,v
retrieving revision 1.11
diff -u -p -r1.11 lyx_1_2.py
--- lib/lyx2lyx/lyx_1_2.py 20 Sep 2005 12:47:45 -0000 1.11
+++ lib/lyx2lyx/lyx_1_2.py 4 Feb 2006 15:50:08 -0000
@@ -179,7 +179,7 @@ def remove_pextra(file):
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)
@@ -216,13 +216,13 @@ def is_empty(lines):
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"]
def remove_oldert(file):
+ ert_begin = ["\\begin_inset ERT",
+ "status Collapsed",
+ "",
+ '\\layout %s' % file.default_layout]
lines = file.body
i = 0
while 1:
@@ -248,8 +248,7 @@ def remove_oldert(file):
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, "", ""]
k = i+1
while 1:
@@ -349,8 +348,12 @@ def remove_oldertinset(file):
i = i+1
-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
+ tokens = string.split(lines[i])
+ if len(tokens) < 2 or not file.is_default_layout(tokens[1]):
return 0
i = find_nonempty_line(lines, i+1)
@@ -372,7 +375,7 @@ def combine_ert(file):
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)
@@ -721,7 +724,7 @@ def change_infoinset(file):
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:]:
Index: lib/lyx2lyx/lyx_1_4.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_4.py,v
retrieving revision 1.56
diff -u -p -r1.56 lyx_1_4.py
--- lib/lyx2lyx/lyx_1_4.py 2 Feb 2006 21:30:04 -0000 1.56
+++ lib/lyx2lyx/lyx_1_4.py 4 Feb 2006 15:50:09 -0000
@@ -81,7 +81,7 @@ def revert_spaces(file):
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{}
@@ -129,7 +129,7 @@ def revert_eqref(file):
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
@@ -251,10 +251,10 @@ def convert_comment(file):
if i == -1:
return
- file.body[i:i+1] = ["\\layout Standard","","",
+ file.body[i:i+1] = ['\\layout %s' % file.default_layout,"","",
"\\begin_inset Comment",
"collapsed true","",
- "\\layout Standard"]
+ '\\layout %s' % file.default_layout]
i = i + 7
while 1:
@@ -303,7 +303,7 @@ def convert_comment(file):
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 = i + 1
@@ -597,7 +597,8 @@ def convert_breaks(file):
# 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
@@ -640,7 +641,7 @@ def convert_breaks(file):
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 ',''])
@@ -655,7 +656,7 @@ def convert_breaks(file):
# 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:
@@ -692,7 +693,7 @@ def convert_breaks(file):
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:
@@ -993,7 +994,7 @@ def convert_minipage(file):
# -------------------------------------------------------------------------------------------
# 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 '
@@ -1004,7 +1005,7 @@ def convert_ertbackslash(body, i, ert, f
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
@@ -1313,7 +1314,7 @@ def revert_breaks(file):
# 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]
@@ -1345,7 +1346,7 @@ def revert_breaks(file):
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_format)
file.body[i] = file.body[i] + '}'
i = i + 1
elif insets[0] == "lyxline":
@@ -1356,7 +1357,7 @@ def revert_breaks(file):
latexsize = '\\normalsize'
i = insert_ert(file.body, i, 'Collapsed',
'\\lyxline{%s}' % latexsize,
- file.format - 1)
+ 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)
@@ -1368,7 +1369,7 @@ def revert_breaks(file):
elif insets[0] == "newpage":
file.body[i] = ''
i = insert_ert(file.body, i, 'Collapsed', '\\newpage{}',
- file.format - 1)
+ file.format - 1, file.default_layout)
# Convert a LyX length into a LaTeX length
@@ -1392,9 +1393,9 @@ def convert_len(len, special):
# 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_format):
# 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_format)
# Return the value of len without the unit in numerical form
@@ -1408,15 +1409,15 @@ def len2value(len):
# 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] = ['\\layout Standard', '']
+ body[i:i] = ['\\layout %s' % default_layout, '']
else:
- 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 = 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
@@ -1557,7 +1558,7 @@ def convert_frameless_box(file):
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',
@@ -1572,21 +1573,21 @@ def convert_frameless_box(file):
# 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 = 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
- file.body[j:j] = ['\\layout Standard', '', '']
+ file.body[j:j] = ['\\layout %s' % file.default_layout, '', '']
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
@@ -1597,7 +1598,7 @@ def convert_frameless_box(file):
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.
@@ -1841,7 +1842,7 @@ def convert_names(file):
"\\begin_inset CharStyle Firstname",
"status inlined",
"",
- "\\begin_layout Standard",
+ '\\begin_layout %s' % file.default_layout,
"",
"%s" % firstname,
"\end_layout",
@@ -1852,7 +1853,7 @@ def convert_names(file):
"\\begin_inset CharStyle Surname",
"status inlined",
"",
- "\\begin_layout Standard",
+ '\\begin_layout %s' % file.default_layout,
"",
"%s" % surname,
"\\end_layout",
@@ -2179,7 +2180,7 @@ def convert_ert_paragraphs(file):
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
@@ -2196,14 +2197,14 @@ def convert_ert_paragraphs(file):
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
- 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
@@ -2214,7 +2215,7 @@ def convert_ert_paragraphs(file):
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]
k = k + 4
j = j + 3
i = i + 1
@@ -2257,7 +2258,7 @@ def revert_ert_paragraphs(file):
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
else:
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2369
diff -u -p -r1.2369 ChangeLog
--- src/ChangeLog 3 Feb 2006 21:47:24 -0000 1.2369
+++ src/ChangeLog 4 Feb 2006 15:50:13 -0000
@@ -1,3 +1,8 @@
+2006-02-04 Georg Baum <[EMAIL PROTECTED]>
+
+ * lyxtextclass.C (Read): Add <default> layout for lyx2lyx compatibility
+ * lyxlayout.[Ch] (setObsoletedBy): new, needed for the above
+
2006-02-02 Georg Baum <[EMAIL PROTECTED]>
* exporter.C (Backends): Add "lyx" backend
Index: src/lyxlayout.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.C,v
retrieving revision 1.28
diff -u -p -r1.28 lyxlayout.C
--- src/lyxlayout.C 12 May 2005 10:16:04 -0000 1.28
+++ src/lyxlayout.C 4 Feb 2006 15:50:14 -0000
@@ -812,6 +812,12 @@ string const & LyXLayout::obsoleted_by()
}
+void LyXLayout::setObsoletedBy(string const & obsoleted_by)
+{
+ obsoleted_by_ = obsoleted_by;
+}
+
+
string const & LyXLayout::depends_on() const
{
return depends_on_;
Index: src/lyxlayout.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxlayout.h,v
retrieving revision 1.20
diff -u -p -r1.20 lyxlayout.h
--- src/lyxlayout.h 12 May 2005 10:16:04 -0000 1.20
+++ src/lyxlayout.h 4 Feb 2006 15:50:14 -0000
@@ -51,6 +51,8 @@ public:
///
std::string const & obsoleted_by() const;
///
+ void setObsoletedBy(std::string const &);
+ ///
std::string const & depends_on() const;
///
std::string const & latexname() const { return latexname_; }
Index: src/lyxtextclass.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtextclass.C,v
retrieving revision 1.52
diff -u -p -r1.52 lyxtextclass.C
--- src/lyxtextclass.C 2 Nov 2005 20:11:35 -0000 1.52
+++ src/lyxtextclass.C 4 Feb 2006 15:50:14 -0000
@@ -470,6 +470,15 @@ bool LyXTextClass::Read(string const & f
<< "Minimum TocLevel is " << min_toclevel_
<< ", maximum is " << max_toclevel_ <<endl;
+ // lyx2lyx can produce "<default>" layouts when it actually
+ // means the default layout, so we need to add one here.
+ if (!error && !hasLayout("<default>")) {
+ boost::shared_ptr<LyXLayout> lay(new LyXLayout);
+ *lay = *(operator[](defaultlayout_));
+ lay->setName("<default>");
+ lay->setObsoletedBy(defaultlayout_);
+ layoutlist_.push_back(lay);
+ }
} else
lyxerr[Debug::TCLASS] << "Finished reading input file "
<< MakeDisplayPath(filename)