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;
}
-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)));
}
///
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);
///
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: "
}
-
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) << '}';
}
///
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);
int numargs_;
///
string name_;
+ /// newcommand or renewcommand or def
+ string type_;
};
#endif
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") {
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");
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() == "(") {