diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 6c807ec87b..8f6d7fc535 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1764,10 +1764,11 @@ bool BufferParams::setBaseClass(string const & classname) LayoutFileList & bcl = LayoutFileList::get(); if (!bcl.haveClass(classname)) { docstring s = - bformat(_("The document class %1$s could not be found. " - "A default textclass with default layouts will be used. " - "LyX might not be able to produce output unless a correct " - "textclass is selected from the document settings dialog."), + bformat(_("The layout file:\n" + "%1$s\n" + "could not be found. A default textclass with default\n" + "layouts will be used. LyX will not be able to produce\n" + "correct output."), from_utf8(classname)); frontend::Alert::error(_("Document class not found"), s); bcl.addEmptyClass(classname); @@ -1776,10 +1777,14 @@ bool BufferParams::setBaseClass(string const & classname) bool const success = bcl[classname].load(); if (!success) { docstring s = - bformat(_("The document class %1$s could not be loaded."), + bformat(_("Due to some error in it, the layout file:\n" + "%1$s\n" + "could not be loaded. A default textclass with default\n" + "layouts will be used. LyX will not be able to produce\n" + "correct output."), from_utf8(classname)); frontend::Alert::error(_("Could not load class"), s); - return false; + bcl.addEmptyClass(classname); } pimpl_->baseClass_ = classname; diff --git a/src/LayoutFile.cpp b/src/LayoutFile.cpp index ee53e1f165..b4387deee5 100644 --- a/src/LayoutFile.cpp +++ b/src/LayoutFile.cpp @@ -204,21 +204,13 @@ void LayoutFileList::reset(LayoutFileIndex const & classname) { } -LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass) -{ - if (haveClass(textclass)) - return textclass; +namespace { - FileName const tempLayout = FileName::tempName(); - ofstream ofs(tempLayout.toFilesystemEncoding().c_str()); - ofs << "# This layout is automatically generated\n" - "# \\DeclareLaTeXClass{" << textclass << "}\n\n" - "Format 7\n" - "Input stdclass.inc\n\n" - "Columns 1\n" - "Sides 1\n" - "SecNumDepth 2\n" - "TocDepth 2\n" +string layoutpost = + "Columns 1\n" + "Sides 1\n" + "SecNumDepth 2\n" + "TocDepth 2\n" "DefaultStyle Standard\n\n" "Style Standard\n" " Category MainText\n" @@ -231,6 +223,20 @@ LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass) " AlignPossible Block, Left, Right, Center\n" " LabelType No_Label\n" "End\n"; + +} + +LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass) +{ + FileName const tempLayout = FileName::tempName(); + ofstream ofs(tempLayout.toFilesystemEncoding().c_str()); + // This writes a very basic class, but it also attempts to include + // stdclass.inc. That would give us something moderately usable. + ofs << "# This layout is automatically generated\n" + "# \\DeclareLaTeXClass{" << textclass << "}\n\n" + "Format 26\n" + "Input stdclass.inc\n\n" + << layoutpost; ofs.close(); // We do not know if a LaTeX class is available for this document, but setting @@ -238,11 +244,24 @@ LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass) // tex class. LayoutFile * tc = new LayoutFile(textclass, textclass, "Unknown text class " + textclass, textclass + ".cls", true); + if (!tc->load(tempLayout.absFilename())) { - // The only way this happens is because the hardcoded layout file above - // is wrong. - LASSERT(false, /**/); + // The only way this happens is because the hardcoded layout file + // aboveis wrong or stdclass.inc cannot be found. So try again + // without stdclass.inc. + ofstream ofs2(tempLayout.toFilesystemEncoding().c_str()); + ofs2 << "# This layout is automatically generated\n" + "# \\DeclareLaTeXClass{" << textclass << "}\n\n" + "Format 26\n" + "Input stdclass.inc\n\n" + << layoutpost; + ofs2.close(); + if (!tc->load(tempLayout.absFilename())) { + // This can only happen if the hardcoded file above is wrong. + LASSERT(false, /* */); + } } + classmap_[textclass] = tc; return textclass; } diff --git a/src/LayoutFile.h b/src/LayoutFile.h index 55807e9077..f50f6ea451 100644 --- a/src/LayoutFile.h +++ b/src/LayoutFile.h @@ -115,7 +115,9 @@ public: /// Clears the textclass so as to force it to be reloaded void reset(LayoutFileIndex const & tc); - /// add a default textclass with all standard layouts. + /// Add a default textclass with all standard layouts. + /// Note that this will over-write any information we may have + /// gotten from textclass.lst about this class. LayoutFileIndex addEmptyClass(std::string const & textclass); /// add a textclass from user local directory.