>>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes:
Georg> This is the updated patch with layout2layout support. I needed Georg> to change one other place as well (compile error due to Georg> Martin's recent natbib change). This is finally the working and tested patch. The only thing missing is the documentation (easy) and maybe the update of the layout files (Georg, shall we do it now?) To summarize, the patch replaces things like ProvidesAmsmath 1 by Provides amsmath 1 This means that any feature handled by LaTeXFeature can be overridden (of course, some of them will need some fixing, we'll see). So, what shall I do with it now? JMarc
Index: src/LaTeXFeatures.C =================================================================== --- src/LaTeXFeatures.C (révision 17701) +++ src/LaTeXFeatures.C (copie de travail) @@ -153,6 +153,12 @@ bool LaTeXFeatures::isRequired(string co } +bool LaTeXFeatures::mustProvide(string const & name) const +{ + return isRequired(name) && !params_.getLyXTextClass().provides(name); +} + + bool LaTeXFeatures::isAvailable(string const & name) { if (packages_.empty()) @@ -268,7 +274,7 @@ string const LaTeXFeatures::getPackages( // packages which we just \usepackage{package} // for (int i = 0; i < nb_simplefeatures; ++i) { - if (isRequired(simplefeatures[i])) + if (mustProvide(simplefeatures[i])) packages << "\\usepackage{" << simplefeatures[i] << "}\n"; } @@ -278,8 +284,7 @@ string const LaTeXFeatures::getPackages( // than those above. // - if (isRequired("amsmath") - && !tclass.provides(LyXTextClass::amsmath) + if (mustProvide("amsmath") && params_.use_amsmath != BufferParams::package_off) { packages << "\\usepackage{amsmath}\n"; } @@ -291,12 +296,12 @@ string const LaTeXFeatures::getPackages( // esint is used, since esint redefines all relevant integral // symbols from wasysym and amsmath. // See http://bugzilla.lyx.org/show_bug.cgi?id=1942 - if (isRequired("wasysym") && isRequired("esint") && + if (mustProvide("wasysym") && isRequired("esint") && params_.use_esint != BufferParams::package_off) packages << "\\usepackage{wasysym}\n"; // color.sty - if (isRequired("color")) { + if (mustProvide("color")) { if (params_.graphicsDriver == "default") packages << "\\usepackage{color}\n"; else @@ -307,13 +312,13 @@ string const LaTeXFeatures::getPackages( // makeidx.sty if (isRequired("makeidx")) { - if (!tclass.provides(LyXTextClass::makeidx)) + if (!tclass.provides("makeidx")) packages << "\\usepackage{makeidx}\n"; packages << "\\makeindex\n"; } // graphicx.sty - if (isRequired("graphicx") && params_.graphicsDriver != "none") { + if (mustProvide("graphicx") && params_.graphicsDriver != "none") { if (params_.graphicsDriver == "default") packages << "\\usepackage{graphicx}\n"; else @@ -322,18 +327,14 @@ string const LaTeXFeatures::getPackages( << "]{graphicx}\n"; } // shadecolor for shaded - if (isRequired("framed")) { + if (mustProvide("framed")) { RGBColor c = RGBColor(lcolor.getX11Name(LColor::shadedbg)); packages << "\\definecolor{shadecolor}{rgb}{" << c.r/255 << ',' << c.g/255 << ',' << c.b/255 << "}\n"; } - //if (algorithm) { - // packages << "\\usepackage{algorithm}\n"; - //} - // lyxskak.sty --- newer chess support based on skak.sty - if (isRequired("chess")) { + if (mustProvide("chess")) { packages << "\\usepackage[ps,mover]{lyxskak}\n"; } @@ -362,22 +363,23 @@ string const LaTeXFeatures::getPackages( } // amssymb.sty - if (isRequired("amssymb") || params_.use_amsmath == BufferParams::package_on) + if (mustProvide("amssymb") + || params_.use_amsmath == BufferParams::package_on) packages << "\\usepackage{amssymb}\n"; // esint must be after amsmath and wasysym, since it will redeclare // inconsistent integral symbols - if (isRequired("esint") && params_.use_esint != BufferParams::package_off) + if (mustProvide("esint") + && params_.use_esint != BufferParams::package_off) packages << "\\usepackage{esint}\n"; // url.sty - if (isRequired("url") && ! tclass.provides(LyXTextClass::url)) + if (mustProvide("url")) packages << "\\IfFileExists{url.sty}{\\usepackage{url}}\n" " {\\newcommand{\\url}{\\texttt}}\n"; - // float.sty // natbib.sty - if (isRequired("natbib") && ! tclass.provides(LyXTextClass::natbib)) { + if (mustProvide("natbib")) { packages << "\\usepackage["; if (params_.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL) { packages << "numbers"; @@ -388,20 +390,20 @@ string const LaTeXFeatures::getPackages( } // jurabib -- we need version 0.6 at least. - if (isRequired("jurabib")) { + if (mustProvide("jurabib")) { packages << "\\usepackage{jurabib}[2004/01/25]\n"; } // bibtopic -- the dot provides the aux file naming which // LyX can detect. - if (isRequired("bibtopic")) { + if (mustProvide("bibtopic")) { packages << "\\usepackage[dot]{bibtopic}\n"; } - if (isRequired("xy")) + if (mustProvide("xy")) packages << "\\usepackage[all]{xy}\n"; - if (isRequired("nomencl")) { + if (mustProvide("nomencl")) { packages << "\\usepackage{nomencl}[2005/09/22]\n" << "\\makenomenclature\n"; } @@ -422,55 +424,55 @@ string const LaTeXFeatures::getMacros() macros << *pit << '\n'; } - if (isRequired("LyX")) + if (mustProvide("LyX")) macros << lyx_def << '\n'; - if (isRequired("lyxline")) + if (mustProvide("lyxline")) macros << lyxline_def << '\n'; - if (isRequired("noun")) + if (mustProvide("noun")) macros << noun_def << '\n'; - if (isRequired("lyxarrow")) + if (mustProvide("lyxarrow")) macros << lyxarrow_def << '\n'; // quotes. - if (isRequired("quotesinglbase")) + if (mustProvide("quotesinglbase")) macros << quotesinglbase_def << '\n'; - if (isRequired("quotedblbase")) + if (mustProvide("quotedblbase")) macros << quotedblbase_def << '\n'; - if (isRequired("guilsinglleft")) + if (mustProvide("guilsinglleft")) macros << guilsinglleft_def << '\n'; - if (isRequired("guilsinglright")) + if (mustProvide("guilsinglright")) macros << guilsinglright_def << '\n'; - if (isRequired("guillemotleft")) + if (mustProvide("guillemotleft")) macros << guillemotleft_def << '\n'; - if (isRequired("guillemotright")) + if (mustProvide("guillemotright")) macros << guillemotright_def << '\n'; // Math mode - if (isRequired("boldsymbol") && !isRequired("amsmath")) + if (mustProvide("boldsymbol") && !isRequired("amsmath")) macros << boldsymbol_def << '\n'; - if (isRequired("binom") && !isRequired("amsmath")) + if (mustProvide("binom") && !isRequired("amsmath")) macros << binom_def << '\n'; - if (isRequired("mathcircumflex")) + if (mustProvide("mathcircumflex")) macros << mathcircumflex_def << '\n'; // other - if (isRequired("ParagraphLeftIndent")) + if (mustProvide("ParagraphLeftIndent")) macros << paragraphleftindent_def; - if (isRequired("NeedLyXFootnoteCode")) + if (mustProvide("NeedLyXFootnoteCode")) macros << floatingfootnote_def; // some problems with tex->html converters - if (isRequired("NeedTabularnewline")) + if (mustProvide("NeedTabularnewline")) macros << tabularnewline_def; // greyedout environment (note inset) - if (isRequired("lyxgreyedout")) + if (mustProvide("lyxgreyedout")) macros << lyxgreyedout_def; - if (isRequired("lyxdot")) + if (mustProvide("lyxdot")) macros << lyxdot_def << '\n'; // floats @@ -526,7 +528,7 @@ docstring const LaTeXFeatures::getLyXSGM // Definition of entities used in the document that are LyX related. odocstringstream entities; - if (isRequired("lyxarrow")) { + if (mustProvide("lyxarrow")) { entities << "<!ENTITY lyxarrow \"->\">" << '\n'; } Index: src/LaTeXFeatures.h =================================================================== --- src/LaTeXFeatures.h (révision 17701) +++ src/LaTeXFeatures.h (copie de travail) @@ -73,8 +73,13 @@ public: static void getAvailable(); /// Is the (required) package available? static bool isAvailable(std::string const & name); - /// Is the package required? + /// Has the package been required? bool isRequired(std::string const & name) const; + /* Is it necessary to load the package? This is true is + isRequired is true and the feature is not provided by the + textclass. + */ + bool mustProvide(std::string const & name) const; /// void useFloat(std::string const & name); /// Index: src/buffer.C =================================================================== --- src/buffer.C (révision 17701) +++ src/buffer.C (copie de travail) @@ -1195,7 +1195,7 @@ void Buffer::validate(LaTeXFeatures & fe // AMS Style is at document level if (params().use_amsmath == BufferParams::package_on - || tclass.provides(LyXTextClass::amsmath)) + || tclass.provides("amsmath")) features.require("amsmath"); if (params().use_esint == BufferParams::package_on) features.require("esint"); Index: src/bufferparams.C =================================================================== --- src/bufferparams.C (révision 17701) +++ src/bufferparams.C (copie de travail) @@ -1487,7 +1487,7 @@ biblio::CiteEngine BufferParams::getEngi { // FIXME the class should provide the numerical/ // authoryear choice - if (getLyXTextClass().provides(LyXTextClass::natbib) + if (getLyXTextClass().provides("natbib") && cite_engine_ != biblio::ENGINE_NATBIB_NUMERICAL) return biblio::ENGINE_NATBIB_AUTHORYEAR; return cite_engine_; Index: src/lyxtextclass.C =================================================================== --- src/lyxtextclass.C (révision 17701) +++ src/lyxtextclass.C (copie de travail) @@ -65,7 +65,7 @@ private: }; -int const FORMAT = 3; +int const FORMAT = 4; bool layout2layout(FileName const & filename, FileName const & tempfile) @@ -113,7 +113,6 @@ LyXTextClass::LyXTextClass(string const defaultfont_ = LyXFont(LyXFont::ALL_SANE); opt_fontsize_ = "10|11|12"; opt_pagestyle_ = "empty|plain|headings|fancy"; - provides_ = nothing; titletype_ = TITLE_COMMAND_AFTER; titlename_ = "maketitle"; loaded_ = false; @@ -158,10 +157,7 @@ enum TextClassTags { TC_TOCDEPTH, TC_CLASSOPTIONS, TC_PREAMBLE, - TC_PROVIDESAMSMATH, - TC_PROVIDESNATBIB, - TC_PROVIDESMAKEIDX, - TC_PROVIDESURL, + TC_PROVIDES, TC_LEFTMARGIN, TC_RIGHTMARGIN, TC_FLOAT, @@ -199,10 +195,7 @@ bool LyXTextClass::read(FileName const & { "outputtype", TC_OUTPUTTYPE }, { "pagestyle", TC_PAGESTYLE }, { "preamble", TC_PREAMBLE }, - { "providesamsmath", TC_PROVIDESAMSMATH }, - { "providesmakeidx", TC_PROVIDESMAKEIDX }, - { "providesnatbib", TC_PROVIDESNATBIB }, - { "providesurl", TC_PROVIDESURL }, + { "provides", TC_PROVIDES }, { "rightmargin", TC_RIGHTMARGIN }, { "secnumdepth", TC_SECNUMDEPTH }, { "sides", TC_SIDES }, @@ -383,25 +376,16 @@ bool LyXTextClass::read(FileName const & preamble_ = from_utf8(lexrc.getLongString("EndPreamble")); break; - case TC_PROVIDESAMSMATH: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= amsmath; - break; - - case TC_PROVIDESNATBIB: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= natbib; - break; - - case TC_PROVIDESMAKEIDX: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= makeidx; - break; - - case TC_PROVIDESURL: - if (lexrc.next() && lexrc.getInteger()) - provides_ |= url; + case TC_PROVIDES: { + lexrc.next(); + string const feature = lexrc.getString(); + lexrc.next(); + if (lexrc.getInteger()) + provides_.insert(feature); + else + provides_.erase(feature); break; + } case TC_LEFTMARGIN: // left margin type if (lexrc.next()) @@ -1067,9 +1051,9 @@ OutputType LyXTextClass::outputType() co } -bool LyXTextClass::provides(LyXTextClass::Provides p) const +bool LyXTextClass::provides(string const & p) const { - return provides_ & p; + return provides_.find(p) != provides_.end(); } Index: src/lyxtextclass.h =================================================================== --- src/lyxtextclass.h (révision 17701) +++ src/lyxtextclass.h (copie de travail) @@ -16,7 +16,7 @@ #include <boost/shared_ptr.hpp> #include <vector> - +#include <set> namespace lyx { @@ -126,21 +126,8 @@ public: /// docstring const & preamble() const; - /// Packages that are already loaded by the class - enum Provides { - /// - nothing = 0, - /// - amsmath = 1, - /// - makeidx = 2, - /// - url = 4, - /// - natbib = 8 - }; - /// - bool provides(Provides p) const; + /// is this feature already provided by the class? + bool provides(std::string const & p) const; /// unsigned int columns() const; @@ -209,7 +196,7 @@ private: /// preamble text to support layout styles docstring preamble_; /// latex packages loaded by document class. - Provides provides_; + std::set<std::string> provides_; /// unsigned int columns_; /// @@ -261,14 +248,6 @@ private: }; -/// Merge two different provides flags into one bit field record -inline -void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2) -{ - p1 = static_cast<LyXTextClass::Provides>(p1 | p2); -} - - /// convert page sides option to text 1 or 2 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p); Index: lib/scripts/layout2layout.py =================================================================== --- lib/scripts/layout2layout.py (révision 17701) +++ lib/scripts/layout2layout.py (copie de travail) @@ -79,6 +79,7 @@ def convert(lines): re_CopyStyle = re.compile(r'^(\s*)(CopyStyle)(\s+)(\S+)', re.IGNORECASE) re_NoStyle = re.compile(r'^(\s*)(NoStyle)(\s+)(\S+)', re.IGNORECASE) re_End = re.compile(r'^(\s*)(End)(\s*)$', re.IGNORECASE) + re_Provides = re.compile(r'^(\s*)Provides(\S+)(\s+)(\S+)', re.IGNORECASE) # counters for sectioning styles (hardcoded in 1.3) counters = {"part" : "\\Roman{part}", @@ -133,10 +134,10 @@ def convert(lines): match = re_Format.match(lines[i]) if match: format = int(match.group(4)) - if format == 2: - lines[i] = "Format 3" + if format > 1 and format < 4: + lines[i] = "Format %d" % (format + 1) only_comment = 0 - elif format == 3: + elif format == 4: # nothing to do return format else: @@ -153,6 +154,17 @@ def convert(lines): i = i + 1 continue + if format == 3: + # convert 'providesamsmath x', 'providesmakeidx x', 'providesnatbib x', 'providesurl x' to + # 'provides amsmath x', 'provides makeidx x', 'provides natbib x', 'provides url x' + # x is either 0 or 1 + match = re_Provides.match(lines[i]) + if match: + lines[i] = "%sProvides %s%s%s" % (match.group(1), match.group(2).lower(), + match.group(3), match.group(4)) + i = i + 1 + continue + if format == 2: caption = [] @@ -370,7 +382,7 @@ def main(argv): # Do the real work lines = read(input) format = 1 - while (format < 3): + while (format < 4): format = convert(lines) write(output, lines)