]> git.lyx.org Git - features.git/commitdiff
allow 'renewcommand' and 'def' for math macros
authorAndré Pönitz <poenitz@gmx.net>
Fri, 4 Jul 2003 15:55:18 +0000 (15:55 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 4 Jul 2003 15:55:18 +0000 (15:55 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7241 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/formulamacro.C
src/mathed/formulamacro.h
src/mathed/math_macrotemplate.C
src/mathed/math_macrotemplate.h
src/mathed/math_parser.C

index 1ad521a45eee05030e08c48d50e197fc0ce9ec2e..aed61cef26bf68abd0f5b5d151d8cc6f320e855c 100644 (file)
@@ -957,8 +957,10 @@ void mathDispatch(FuncRequest const & cmd)
                        else {
                                string s = cmd.argument;
                                string const s1 = token(s, ' ', 1);
-                               int const na = s1.empty() ? 0 : atoi(s1);
-                               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
+                               int const nargs = s1.empty() ? 0 : atoi(s1);
+                               string const s2 = token(s, ' ', 2);
+                               string const type = s2.empty() ? "newcommand" : s2;
+                               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
                        }
                        break;
 
index da8943bacf13f298adc8d319b81fd0868df95099..390643dcf8055ee40598ef67cb3a06048dca0c1b 100644 (file)
@@ -50,10 +50,11 @@ InsetFormulaMacro::InsetFormulaMacro()
 }
 
 
-InsetFormulaMacro::InsetFormulaMacro(string const & name, int nargs)
+InsetFormulaMacro::InsetFormulaMacro
+       (string const & name, int nargs, string const & type)
 {
        setInsetName(name);
-       MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs)));
+       MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
 }
 
 
index 41fd9bbf6edecacf44f1588fd9a06b00425bdae3..1e4ce5d9231ac94eb448e368fef8749dd918151c 100644 (file)
@@ -29,7 +29,7 @@ public:
        ///
        InsetFormulaMacro();
        /// construct a macro hull from its name and the number of arguments
-       explicit InsetFormulaMacro(string const & name, int nargs);
+       explicit InsetFormulaMacro(string const & name, int nargs, string const & t);
        /// constructs a mocro from its LaTeX definition
        explicit InsetFormulaMacro(string const & s);
        ///
index 3f03eeeb8a3b1265b0d7f49fcb62728ef5aaac70..f200c46cd5a6478b4850803a5d518743529790a0 100644 (file)
@@ -7,13 +7,13 @@
 
 
 MathMacroTemplate::MathMacroTemplate()
-       : MathNestInset(2), numargs_(0), name_()
+       : MathNestInset(2), numargs_(0), name_(), type_("newcommand")
 {}
 
 
 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs,
-               MathArray const & ar1, MathArray const & ar2)
-       : MathNestInset(2), numargs_(numargs), name_(nm)
+               string const & type, MathArray const & ar1, MathArray const & ar2)
+       : MathNestInset(2), numargs_(numargs), name_(nm), type_(type)
 {
        if (numargs_ > 9)
                lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
@@ -86,21 +86,26 @@ void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-
 void MathMacroTemplate::write(WriteStream & os) const
 {
-       if (os.latex()) {
-               os << "\n\\newcommand{\\" << name_.c_str() << '}';
-               if (numargs_ > 0)
-                       os << '[' << numargs_ << ']';
-               os << '{' << cell(0) << "}\n";
+       if (type_ == "def") {
+               os << "\n\\def\\" << name_.c_str();
+               for (int i = 1; i <= numargs_; ++i) 
+                       os << '#' << i;
        } else {
-               // writing .lyx
-               os << "\n\\newcommand{\\" << name_.c_str() << '}';
+               // newcommand or renewcommand
+               os << "\n\\" << type_.c_str() << "{\\" << name_.c_str() << '}';
                if (numargs_ > 0)
                        os << '[' << numargs_ << ']';
-               os << '{' << cell(0) << '}';
-               // write special .tex export only if necessary
+       }
+
+       os << '{' << cell(0) << "}";
+
+       if (os.latex()) {
+               // writing .tex. done.
+               os << "\n";
+       } else {
+               // writing .lyx, write special .tex export only if necessary
                if (!cell(1).empty())
                        os << "\n{" << cell(1) << '}';
        }
index 405eeb331172e24ade293c1d44c44dfd69455dc3..8807cfe859b78cd1b4b4011df02c307669816f23 100644 (file)
@@ -20,7 +20,7 @@ public:
        ///
        MathMacroTemplate();
        ///
-       MathMacroTemplate(string const & name, int nargs,
+       MathMacroTemplate(string const & name, int nargs, string const & type,
                MathArray const & = MathArray(), MathArray const & = MathArray());
        ///
        explicit MathMacroTemplate(std::istream & is);
@@ -47,6 +47,8 @@ private:
        int numargs_;
        ///
        string name_;
+       /// newcommand or renewcommand or def
+       string type_;
 };
 
 #endif
index 06713ed70f6966b4ad05ab6ffa931727d77bbb78..cc098d3ec68fd190a1fc7e124ebd60452e4e099f 100644 (file)
@@ -792,7 +792,11 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                cell->back().nucleus()->lock(true);
                }
 
-               else if (t.cs() == "def" || t.cs() == "newcommand") {
+               else if (t.cs() == "def" ||
+                       t.cs() == "newcommand" ||
+                       t.cs() == "renewcommand")
+               {
+                       string const type = t.cs();
                        string name;
                        int nargs = 0;
                        if (t.cs() == "def") {
@@ -808,7 +812,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                nargs /= 2;
                                //lyxerr << "read \\def parameter list '" << pars << "'\n";
 
-                       } else { // t.cs() == "newcommand"
+                       } else { // t.cs() == "newcommand" || t.cs() == "renewcommand"
 
                                if (getToken().cat() != catBegin) {
                                        error("'{' in \\newcommand expected (1) \n");
@@ -845,7 +849,8 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        if (nextToken().cat() == catBegin)
                                parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
 
-                       cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
+                       cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, type,
+                               ar1, ar2)));
                }
 
                else if (t.cs() == "(") {