]> git.lyx.org Git - features.git/commitdiff
* corrected handling of validation of math macros. The macro instances
authorStefan Schimanski <sts@lyx.org>
Wed, 26 Mar 2008 12:55:36 +0000 (12:55 +0000)
committerStefan Schimanski <sts@lyx.org>
Wed, 26 Mar 2008 12:55:36 +0000 (12:55 +0000)
  will require the needed LaTeXFeatures of their definition and their
  paramenters.
* Require the "xargs" package when there is a macro with optional
  parameters which is prepended to a child document which is rendered alone.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23971 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/mathed/MacroTable.cpp
src/mathed/MacroTable.h
src/mathed/MathMacro.cpp

index d248051ae655defcf591c86dfb70b5153037a440..47220166462c9a25729867baa947dfcb1e509089 100644 (file)
@@ -1103,6 +1103,16 @@ void Buffer::writeLaTeXSource(odocstream & os,
                d->texrow.newline();
        }
        LYXERR(Debug::INFO, "lyx document header finished");
+
+       // Don't move this behind the parent_buffer=0 code below,
+       // because then the macros will not get the right "redefinition"
+       // flag as they don't see the parent macros which are output before.
+       updateMacros();
+       
+       // fold macros if possible, still with parent buffer as the
+       // macros will be put in the prefix anyway.
+       updateMacroInstances();
+       
        // There are a few differences between nice LaTeX and usual files:
        // usual is \batchmode and has a
        // special input@path to allow the including of figures
@@ -1133,6 +1143,11 @@ void Buffer::writeLaTeXSource(odocstream & os,
                        d->texrow.newline();
                }
 
+               // get parent macros (if this buffer has a parent) which will be
+               // written at the document begin further down.
+               MacroSet parentMacros;
+               listParentMacros(parentMacros, features);
+
                // Write the preamble
                runparams.use_babel = params().writeLaTeX(os, features, d->texrow);
 
@@ -1142,29 +1157,23 @@ void Buffer::writeLaTeXSource(odocstream & os,
                // make the body.
                os << "\\begin{document}\n";
                d->texrow.newline();
+               
+               // output the parent macros
+               MacroSet::iterator it = parentMacros.begin();
+               MacroSet::iterator end = parentMacros.end();
+               for (; it != end; ++it)
+                       (*it)->write(os, true); 
        } // output_preamble
 
        d->texrow.start(paragraphs().begin()->id(), 0);
        
        LYXERR(Debug::INFO, "preamble finished, now the body.");
 
-       // Don't move this behind the parent_buffer=0 code below,
-       // because then the macros will not get the right "redefinition"
-       // flag as they don't see the parent macros which are output before.
-       updateMacros();
-
-       // fold macros if possible, still with parent buffer as the
-       // macros will be put in the prefix anyway.
-       updateMacroInstances();
-
        // if we are doing a real file with body, even if this is the
        // child of some other buffer, let's cut the link here.
        // This happens for example if only a child document is printed.
        Buffer const * save_parent = 0;
        if (output_preamble) {
-               // output the macros visible for this buffer
-               writeParentMacros(os);
-
                save_parent = d->parent_buffer;
                d->parent_buffer = 0;
        }
@@ -1173,15 +1182,9 @@ void Buffer::writeLaTeXSource(odocstream & os,
        latexParagraphs(*this, text(), os, d->texrow, runparams);
 
        // Restore the parenthood if needed
-       if (output_preamble) {
+       if (output_preamble)
                d->parent_buffer = save_parent;
 
-               // restore macros with correct parent buffer (especially
-               // important for the redefinition flag which depends on the 
-               // parent)
-               updateMacros();
-       }
-
        // add this just in case after all the paragraphs
        os << endl;
        d->texrow.newline();
@@ -1991,24 +1994,30 @@ void Buffer::listMacroNames(MacroNameSet & macros) const
 }
 
 
-void Buffer::writeParentMacros(odocstream & os) const
+void Buffer::listParentMacros(MacroSet & macros, LaTeXFeatures & features) const
 {
        if (!d->parent_buffer)
                return;
-
-       // collect macro names
+       
        MacroNameSet names;
        d->parent_buffer->listMacroNames(names);
-
-       // resolve and output them
+       
+       // resolve macros
        MacroNameSet::iterator it = names.begin();
        MacroNameSet::iterator end = names.end();
        for (; it != end; ++it) {
                // defined?
                MacroData const * data = 
                d->parent_buffer->getMacro(*it, *this, false);
-               if (data)
-                       data->write(os, true);  
+               if (data) {
+                       macros.insert(data);
+                       
+                       // we cannot access the original MathMacroTemplate anymore
+                       // here to calls validate method. So we do its work here manually.
+                       // FIXME: somehow make the template accessible here.
+                       if (data->optionals() > 0)
+                               features.require("xargs");
+               }
        }
 }
 
index eb9b581bf71f0b37273c5a0faafd99a547e3063b..68f80cc82eea33a491394aada325fec6e39692fa 100644 (file)
@@ -43,6 +43,7 @@ class LaTeXFeatures;
 class Language;
 class MacroData;
 class MacroNameSet;
+class MacroSet;
 class OutputParams;
 class Paragraph;
 class ParConstIterator;
@@ -368,12 +369,10 @@ public:
        /// Iterate through the whole buffer and try to resolve macros
        void updateMacroInstances() const;
 
-       /// List macro names of this buffer. the parent and the children
+       /// List macro names of this buffer, the parent and the children
        void listMacroNames(MacroNameSet & macros) const;
-       /// Write out all macros somewhere defined in the parent,
-       /// its parents and its children, which are visible at the beginning 
-       /// of this buffer
-       void writeParentMacros(odocstream & os) const;
+       /// Collect macros of the parent and its children in front of this buffer.
+       void listParentMacros(MacroSet & macros, LaTeXFeatures & features) const;
 
        /// Return macro defined before pos (or in the master buffer)
        MacroData const * getMacro(docstring const & name, DocIterator const & pos, bool global = true) const;
index ad9f43f938a3549113c2eb95864f7bde18207ff6..b4dfb13b15a36b2e51464398021a881723bdfaa4 100644 (file)
@@ -60,7 +60,7 @@ MacroData::MacroData(MathMacroTemplate const & macro)
          redefinition_(false), type_(MacroTypeNewcommand)
 {
        queryData(macro);
-}      
+}
 
 
 void MacroData::expand(vector<MathData> const & args, MathData & to) const
@@ -123,7 +123,8 @@ void MacroData::queryData(MathMacroTemplate const & macro) const
        redefinition_ = macro.redefinition();
        type_ = macro.type();
        optionals_ = macro.numOptionals();
-       macro.getDefaults(defaults_);   
+       
+       macro.getDefaults(defaults_);
 }
 
 
index 281a522f9fab7d4c9f7a05059874c28ed70926df..d1b455b03a390026cb0b741ba4a082e13a9ed6f3 100644 (file)
@@ -34,9 +34,6 @@ enum MacroType {
        MacroTypeNewcommandx,
        MacroTypeDef
 };
-
-///
-class MacroNameSet : public std::set<docstring> {};
        
 ///
 class MacroData {
@@ -138,6 +135,12 @@ private:
        mutable MacroType type_;
 };
 
+
+///
+class MacroNameSet : public std::set<docstring> {};
+///
+class MacroSet : public std::set<MacroData const *> {};
+
        
 /// A lookup table of macro definitions.
 /**
index 8197444dffedb737007d2939a5c9455ca86efdec..d84a64240209b97afdeb431f6d41288cfb49dc42 100644 (file)
@@ -517,6 +517,12 @@ void MathMacro::validate(LaTeXFeatures & features) const
 
        if (name() == "binom" || name() == "mathcircumflex")
                features.require(to_utf8(name()));
+       
+       // validate the cells and the definition
+       if (displayMode() == DISPLAY_NORMAL) {
+               definition_.validate(features);
+               InsetMathNest::validate(features);
+       }
 }