Jürgen Spitzmüller wrote:
rgheck wrote:
I think they'll still work. At least, I tried to make them check for
"\begin_layout Plain", which ought to be OK, (Maybe they could check for
"PlainLayout" and "Plain Layout"?) But anyway, I agree with you: There
should have been lyx2lyx that went with this change. Pavel didn't do it,
I expect, because he was thinking that "PlainLayout" was just a UI
string, whereas it was (and is) a layout identifier. I suppose we could
add it, but it'd be a bit after the fact.

Did you do a file format change when introducing PlainLayout in the first place?

No, in part because it isn't a format change. Older versions of LyX will read these files just fine, i.e., they won't throw parser errors. It's just that but they won't recognize Plain\s?Layout, so they'll convert it to whatever they regard as default. Which is what we want them to do, and is really the best we can do. (See below.)

That said, I did consider a dummy format change, but I discarded the idea pretty quickly. You can't do the [[Default]] --> PlainLayout conversion in lyx2lyx, for the simple reason that we don't there know what the default layout is. Yes, it's usually Standard, but the problem PlainLayout was supposed to fix arose in a case where it's precisely not Standard. So we can't do it there. (Not unless we give lyx2lyx a layout file parser. I confess I did not consider writing one.)

My solution was to have LyX itself fix this: If it sees \begin_layout [[default layout name]], then it checks whether Plain Layout is what's needed---i.e., it checks useEmptyLayout()---and if so performs the conversion. (I seem to remember thinking that we should check this anyway.)

And of course we have the same problem in reversion: We don't know what to revert to (without the layout parser). which is why I'm suggesting that 1.5.x could be made aware of Plain\s?Layout, thus repressing the layout errors. Yes, there will be versions of 1.6.svn that produce layout errors, but such versions of LyX can red the file, and the file they load will actually be correct.

So, that leaves the PlainLayout --> Plain Layout part. If we wanted to do something about this, we could do it at 322, which was committed the same day Pavel made that change. Alternatively or additionally, we could do the attached.

Richard

Index: lyx_1_6.py
===================================================================
--- lyx_1_6.py	(revision 24272)
+++ lyx_1_6.py	(working copy)
@@ -68,6 +68,16 @@
     # No number means 1.0
     return 1.0
 
+# Unfortunately, this doesn't really work, since Standard isn't always default.
+# But it's as good as we can do right now.
+def find_default_layout(doc, start, end):
+    l = find_token(document.body, "\\begin_layout Standard", start, end)
+    if l == -1:
+        l = find_token(document.body, "\\begin_layout PlainLayout", start, end)
+    if l == -1:
+        l = find_token(document.body, "\\begin_layout Plain Layout", start, end)
+    return l
+
 ####################################################################
 
 def get_option(document, m, option, default):
@@ -1276,10 +1286,8 @@
             document.warning("Malformed LyX document: Missing `status' tag in Box inset.")
             return
         status = document.body[k]
-        l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
+        l = find_default_layout(document, i + 1, j)
         if l == -1:
-            l = find_token(document.body, "\\begin_layout Plain", i + 1, j)
-        if l == -1:
             document.warning("Malformed LyX document: Missing `\\begin_layout' in Box inset.")
             return
         m = find_token(document.body, "\\end_layout", i + 1, j)
@@ -1460,10 +1468,8 @@
             i = i + 1
             continue
         if get_value(document.body, 'sideways', i, j) != "false":
-            l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
+            l = find_default_layout(doc, i + 1, j)
             if l == -1:
-                l = find_token(document.body, "\\begin_layout Plain", i + 1, j)
-            if l == -1:
                 document.warning("Malformed LyX document: Missing `\\begin_layout' in Float inset.")
                 return
             document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \
@@ -1508,10 +1514,8 @@
             continue
         if get_value(document.body, 'sideways', i, j) != "false":
             if get_value(document.body, 'wide', i, j) != "false":
-                l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
+                l = find_default_layout(document, i + 1, j)
                 if l == -1:
-                    l = find_token(document.body, "\\begin_layout Plain", i + 1, j)
-                if l == -1:
                     document.warning("Malformed LyX document: Missing `\\begin_layout' in Float inset.")
                     return
                 document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \
@@ -1596,7 +1600,7 @@
                 document.warning("Malformed lyx document: Missing '\\end_inset' (embedded float).")
                 i = i + 1
                 continue
-            m = find_token(document.body, "\\begin_layout Plain Layout", k + 1, l)
+            m = find_default_layout(document.body, k + 1, l)
             # caption?
             cap = find_token(document.body, '\\begin_inset Caption', k + 1, l)
             caption = ''
@@ -1629,9 +1633,9 @@
                     if optend == -1:
                         document.warning("Malformed lyx document: Missing '\\end_inset' (OptArg).")
                         return
-                    optc = find_token(document.body, "\\begin_layout Plain Layout", opt, optend)
+                    optc = find_default_layout(document.body, opt, optend)
                     if optc == -1:
-                        document.warning("Malformed LyX document: Missing `\\begin_layout Plain Layout' in Float inset.")
+                        document.warning("Malformed LyX document: Missing `\\begin_layout' in Float inset.")
                         return
                     optcend = find_end_of(document.body, optc, "\\begin_layout", "\\end_layout")
                     for line in document.body[optc:optcend]:

Reply via email to