]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathMacroTemplate.cpp
* src/frontends/GuiDocument.{cpp,h}:
[lyx.git] / src / mathed / MathMacroTemplate.cpp
index c892d346733bf0740eb3b7bd7e9e6f1c05ae0ff9..b7ecb9bbc535511fec76a8662dddf88af316d60b 100644 (file)
@@ -13,6 +13,7 @@
 #include "MathMacroTemplate.h"
 
 #include "DocIterator.h"
+#include "LaTeXFeatures.h"
 #include "InsetMathBrace.h"
 #include "InsetMathChar.h"
 #include "InsetMathSqrt.h"
@@ -136,8 +137,6 @@ void InsetLabelBox::metrics(MetricsInfo & mi, Dimension & dim) const
                if (!parent_.premetrics())
                        dim.des += maxasc + maxdes + 1;
        }
-
-       setDimCache(mi, dim);
 }
 
 
@@ -220,7 +219,6 @@ void DisplayLabelBox::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.wid = 0;
                dim.asc = 0;
                dim.des = 0;
-               setDimCache(mi, dim);
        }
 }
 
@@ -395,7 +393,11 @@ MathMacroTemplate::MathMacroTemplate(docstring const & str)
 
 Inset * MathMacroTemplate::clone() const
 {
-       return new MathMacroTemplate(*this);
+       MathMacroTemplate * inset = new MathMacroTemplate(*this);
+       // the parent pointers of the proxy insets above will point to
+       // to the old template. Hence, the look must be updated.
+       inset->updateLook();
+       return inset;
 }
 
 
@@ -970,40 +972,26 @@ void MathMacroTemplate::write(WriteStream & os) const
 
 void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
 {
-       if (type_ == MacroTypeDef) {
-               os << "\\def\\" << name().c_str();
-               for (int i = 1; i <= numargs_; ++i)
-                       os << '#' << i;
-       } else {
-               // newcommand or renewcommand
+       // newcommand or renewcommand
+       if (os.latex() && optionals_ > 1)
+               os << "\\newlyxcommand";
+       else {
                if (redefinition_ && !overwriteRedefinition)
                        os << "\\renewcommand";
                else
                        os << "\\newcommand";
-               os << "{\\" << name().c_str() << '}';
-               if (numargs_ > 0)
-                       os << '[' << numargs_ << ']';
-
-               // optional values
-               if (os.latex()) {
-                       // in latex only one optional possible, simulate the others
-                       if (optionals_ >= 1) {
-                               docstring optValue = asString(cell(optIdx(0)));
-                               if (optValue.find(']') != docstring::npos)
-                                       os << "[{" << cell(optIdx(0)) << "}]";
-                               else
-                                       os << "[" << cell(optIdx(0)) << "]";
-                       }
-               } else {
-                       // in lyx we handle all optionals as real optionals
-                       for (int i = 0; i < optionals_; ++i) {
-                               docstring optValue = asString(cell(optIdx(i)));
-                               if (optValue.find(']') != docstring::npos)
-                                       os << "[{" << cell(optIdx(i)) << "}]";
-                               else
-                                       os << "[" << cell(optIdx(i)) << "]";
-                       }
-               }
+       }
+       os << "{\\" << name().c_str() << '}';
+       if (numargs_ > 0)
+               os << '[' << numargs_ << ']';
+
+       // optional values
+       for (int i = 0; i < optionals_; ++i) {
+               docstring optValue = asString(cell(optIdx(i)));
+               if (optValue.find(']') != docstring::npos)
+                       os << "[{" << cell(optIdx(i)) << "}]";
+               else
+                       os << "[" << cell(optIdx(i)) << "]";
        }
 
        os << "{" << cell(defIdx()) << "}";
@@ -1085,6 +1073,13 @@ bool MathMacroTemplate::fixNameAndCheckIfValid()
        return data.size() > 0;
 }
 
+       
+void MathMacroTemplate::validate(LaTeXFeatures & features) const
+{
+       if (optionals_ > 1) {
+               features.require("newlyxcommand");
+       }
+}
 
 void MathMacroTemplate::getDefaults(vector<docstring> & defaults) const
 {