Hi folks,

I have created a patch that fixes the problem that LyX is incapable of loading documents for which the corresponding TeX class is missing!

Please have a look at the patch. I expect that you are not willing to apply it directly but please don't let us postpone it until 1.4.0. Let's discuss about the open issues if you think there are any (It already hurts me that a patch that is in use for months is not applied to the repository). After all the patch can't be worse than the current solution (conversion to docbook, what a nonsense...) I do my best to fix as many bugs as possible for 1.3.0.

Kind regards, Michael

PS: With this patch we are able to update the example and template files to the current LyX format.
Index: lib/chkconfig.ltx
===================================================================
RCS file: /cvs/lyx/lyx-devel/lib/chkconfig.ltx,v
retrieving revision 1.9
diff -u -r1.9 chkconfig.ltx
--- lib/chkconfig.ltx   2002/03/01 12:39:19     1.9
+++ lib/chkconfig.ltx   2003/01/16 01:38:59
@@ -59,9 +59,9 @@
 %   the variable chk_<name>.  
 %%%
 \newcommand{\prefix}{+} % the character used by grep to filter 'good' output
-\newcommand{\AddLayout}[3][\default]{
+\newcommand{\AddLayout}[4][\default]{
   \def\default{#2}
-  \immediate\write\layouts{"#2"   "#1"   "#3"}}
+  \immediate\write\layouts{"#2"   "#1"   "#3"   "#4"}}
 \newcommand{\AddVariable}[2]{
   \immediate\write\sed{s!@chk_#1@!#2!g}
   \immediate\write\vars{chk_#1='#2'}}
@@ -107,15 +107,17 @@
 }
 \newcommand{\DeclareLaTeXClass}[2][\default]{
   \TestItem[#1]{\layoutname}{document class}{cls}
-           {\AddLayout[\firstelement]{\layoutname}{#2}}{}
+           {\AddLayout[\firstelement]{\layoutname}{#2}{true}}
+           {\AddLayout[\firstelement]{\layoutname}{#2}{false}}
   \expandafter\endinput
 }
 \newcommand{\DeclareLinuxDocClass}[2][\default]{
   \message{^^J\prefix checking for linuxdoc class \layoutname... }
   \@ifundefined{haslinuxdoc}
-    {\message{no^^J}}
+    {\message{no^^J}  
+     \AddLayout[#1]{\layoutname}{#2}{false}}
     {\message{yes^^J}
-     \AddLayout[#1]{\layoutname}{#2}}
+     \AddLayout[#1]{\layoutname}{#2}{true}}
   \expandafter\endinput
 }
 % Only for compatibility. Will be removed later.
@@ -124,9 +126,10 @@
 \newcommand{\DeclareDocBookClass}[2][\default]{
   \message{^^J\prefix checking for docbook\space\space class \layoutname... }
   \@ifundefined{hasdocbook}
-    {\message{no^^J}}
+    {\message{no^^J}
+     \AddLayout[#1]{\layoutname}{#2}{false}}
     {\message{yes^^J}
-     \AddLayout[#1]{\layoutname}{#2}}
+     \AddLayout[#1]{\layoutname}{#2}{true}}
   \expandafter\endinput
 }
 
Index: src/MenuBackend.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/MenuBackend.C,v
retrieving revision 1.62
diff -u -r1.62 MenuBackend.C
--- src/MenuBackend.C   2003/01/08 09:03:31     1.62
+++ src/MenuBackend.C   2003/01/16 01:39:09
@@ -352,7 +352,7 @@
                action = LFUN_PREVIEW;
                break;
        case MenuItem::UpdateFormats:
-               formats = Exporter::GetExportableFormats(buf, false);
+               formats = Exporter::GetExportableFormats(buf, true);
                action = LFUN_UPDATE;
                break;
        default:
Index: src/buffer.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v
retrieving revision 1.396
diff -u -r1.396 buffer.C
--- src/buffer.C        2003/01/13 10:52:17     1.396
+++ src/buffer.C        2003/01/16 01:39:17
@@ -621,13 +621,13 @@
 #if USE_BOOST_FORMAT
                        Alert::alert(_("Textclass error"),
                                boost::io::str(boost::format(_("The document uses an 
unknown textclass \"%1$s\".")) % lex.getString()),
-                               _("LyX will not be able to produce output 
correctly."));
+                               _("-- substituting default."));
 #else
                        Alert::alert(
                                _("Textclass error"),
                                _("The document uses an unknown textclass ")
                                + lex.getString(),
-                               _("LyX will not be able to produce output 
correctly."));
+                               _("-- substituting default."));
 #endif
                        params.textclass = 0;
                }
@@ -649,6 +649,19 @@
                                     _("-- substituting default"));
 #endif
                        params.textclass = 0;
+               }
+               if (!params.getLyXTextClass().isTeXClassAvailable()) {
+#if USE_BOOST_FORMAT
+                       Alert::alert(_("Textclass error"),
+                               boost::io::str(boost::format(_("The document uses a 
+missing TeX class \"%1$s\".")) % lex.getString()),
+                               _("LyX will not be able to produce output."));
+#else
+                       Alert::alert(
+                               _("Textclass error"),
+                               _("The document uses a missing TeX class ")
+                               + lex.getString(),
+                               _("LyX will not be able to produce output."));
+#endif
                }
        } else if (token == "\\options") {
                lex.eatLine();
Index: src/exporter.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/exporter.C,v
retrieving revision 1.25
diff -u -r1.25 exporter.C
--- src/exporter.C      2003/01/06 14:02:21     1.25
+++ src/exporter.C      2003/01/16 01:39:17
@@ -130,9 +130,14 @@
 {
        vector<string> backends = Backends(buffer);
        for (vector<string>::const_iterator it = backends.begin();
-            it != backends.end(); ++it)
+            it != backends.end(); ++it) {
+               if (it == backends.begin() && 
+                    !buffer->params.getLyXTextClass().isTeXClassAvailable())
+                       continue;
+
                if (converters.isReachable(*it, format))
                        return true;
+       }
        return false;
 }
 
@@ -141,12 +146,19 @@
 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
 {
        vector<string> backends = Backends(buffer);
-       vector<Format const *> result =
-               converters.getReachable(backends[0], only_viewable, true);
+       vector<Format const *> result;
+       bool clear = true;
+
+        if (buffer->params.getLyXTextClass().isTeXClassAvailable()) {
+               result = converters.getReachable(backends[0], only_viewable, true);
+                clear = false;
+       }
+
        for (vector<string>::const_iterator it = backends.begin() + 1;
             it != backends.end(); ++it) {
                vector<Format const *>  r =
-                       converters.getReachable(*it, only_viewable, false);
+                       converters.getReachable(*it, only_viewable, clear);
+               clear = false;
                result.insert(result.end(), r.begin(), r.end());
        }
        return result;
Index: src/lyxfunc.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.391
diff -u -r1.391 lyxfunc.C
--- src/lyxfunc.C       2003/01/09 14:31:24     1.391
+++ src/lyxfunc.C       2003/01/16 01:39:22
@@ -327,8 +327,7 @@
                        || lyxrc.print_command == "none";
                break;
        case LFUN_EXPORT:
-               disable = ev.argument == "fax" &&
-                       !Exporter::IsExportable(buf, ev.argument);
+               disable = !Exporter::IsExportable(buf, ev.argument);
                break;
        case LFUN_UNDO:
                disable = buf->undostack.empty();
Index: src/lyxtextclass.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxtextclass.C,v
retrieving revision 1.22
diff -u -r1.22 lyxtextclass.C
--- src/lyxtextclass.C  2002/11/27 10:30:13     1.22
+++ src/lyxtextclass.C  2003/01/16 01:39:23
@@ -49,9 +49,9 @@
 
 
 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
-                          string const & desc)
+                          string const & desc, bool texClassAvail )
        : name_(fn), latexname_(cln), description_(desc),
-         floatlist_(new FloatList), ctrs_(new Counters)
+         floatlist_(new FloatList), ctrs_(new Counters), texClassAvail(texClassAvail)
 {
        outputType_ = LATEX;
        columns_ = 1;
@@ -65,6 +65,11 @@
        opt_pagestyle_ = "empty|plain|headings|fancy";
        provides_ = nothing;
        loaded = false;
+}
+
+
+bool LyXTextClass::isTeXClassAvailable() const {
+       return texClassAvail;
 }
 
 
Index: src/lyxtextclass.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxtextclass.h,v
retrieving revision 1.11
diff -u -r1.11 lyxtextclass.h
--- src/lyxtextclass.h  2002/11/07 19:51:22     1.11
+++ src/lyxtextclass.h  2003/01/16 01:39:24
@@ -39,8 +39,12 @@
        explicit
        LyXTextClass(string const & = string(),
                     string const & = string(),
-                    string const & = string());
+                    string const & = string(),
+                    bool = false );
 
+       /// check whether the TeX class is available
+       bool isTeXClassAvailable() const;
+
        /// paragraph styles begin iterator.
        const_iterator begin() const { return layoutlist_.begin(); }
        /// paragraph styles end iterator
@@ -142,6 +146,8 @@
        ///
        int size() const;
 private:
+       /// Is the TeX class available?
+       bool texClassAvail;
        ///
        bool delete_layout(string const &);
        ///
Index: src/lyxtextclasslist.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxtextclasslist.C,v
retrieving revision 1.9
diff -u -r1.9 lyxtextclasslist.C
--- src/lyxtextclasslist.C      2002/11/27 10:30:13     1.9
+++ src/lyxtextclasslist.C      2003/01/16 01:39:24
@@ -69,7 +69,9 @@
 class less_textclass_desc {
 public:
        int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
-               return tc1.description() < tc2.description();
+               return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
+                      (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
+                       tc1.description() < tc2.description());
        }
 };
 
@@ -130,13 +132,18 @@
                                if (lex.next()) {
                                        string const desc = lex.getString();
                                        lyxerr[Debug::TCLASS] << "Desc: " << desc << 
endl;
-                                       // This code is run when we have
-                                       // fname, clname and desc
-                                       LyXTextClass tmpl(fname, clname, desc);
-                                       if (lyxerr.debugging(Debug::TCLASS)) {
-                                               tmpl.load();
+                                       if (lex.next()) {
+                                               string const avail = lex.getString();
+                                               lyxerr[Debug::TCLASS] << "Available: " 
+<< avail << endl;
+                                               // This code is run when we have
+                                               // fname, clname, desc, and avail
+                                               LyXTextClass tmpl(fname, clname, desc,
+                                                                  avail == "true" ? 
+true : false );
+                                               if (lyxerr.debugging(Debug::TCLASS)) {
+                                                       tmpl.load();
+                                               }
+                                               classlist_.push_back(tmpl);
                                        }
-                                       classlist_.push_back(tmpl);
                                }
                        }
                }
Index: src/frontends/qt2/QDocument.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QDocument.C,v
retrieving revision 1.31
diff -u -r1.31 QDocument.C
--- src/frontends/qt2/QDocument.C       2002/12/17 20:37:10     1.31
+++ src/frontends/qt2/QDocument.C       2003/01/16 01:39:36
@@ -124,7 +124,12 @@
        // layout
        for (LyXTextClassList::const_iterator cit = textclasslist.begin();
             cit != textclasslist.end(); ++cit) {
-               dialog_->layoutModule->classCO->insertItem(toqstr(cit->description()));
+               if (cit->isTeXClassAvailable()) {
+                       
+dialog_->layoutModule->classCO->insertItem(toqstr(cit->description()));
+                } else {
+                       dialog_->layoutModule->classCO->insertItem(toqstr("N/A: " +
+                                                                         
+cit->description()));
+               }
        }
 
        for (int n = 0; tex_fonts[n][0]; ++n) {
Index: src/frontends/xforms/FormDocument.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/FormDocument.C,v
retrieving revision 1.125
diff -u -r1.125 FormDocument.C
--- src/frontends/xforms/FormDocument.C 2002/12/01 21:10:37     1.125
+++ src/frontends/xforms/FormDocument.C 2003/01/16 01:39:39
@@ -134,7 +134,11 @@
        fl_end_form();
        for (LyXTextClassList::const_iterator cit = textclasslist.begin();
             cit != textclasslist.end(); ++cit) {
-               combo_doc_class->addto(cit->description());
+               if (cit->isTeXClassAvailable()) {
+                       combo_doc_class->addto(cit->description());
+               } else {
+                       combo_doc_class->addto("N/A: " + cit->description());
+               }
        }
 
        fl_addto_choice(class_->choice_doc_spacing,


Reply via email to