5 #include "math_macrotemplate.h"
6 #include "math_mathmlstream.h"
7 #include "frontends/Painter.h"
11 MathMacroTemplate::MathMacroTemplate()
12 : MathNestInset(2), numargs_(0), name_()
16 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
17 : MathNestInset(2), numargs_(numargs), name_(nm)
20 lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
21 << numargs_ << std::endl;
25 MathInset * MathMacroTemplate::clone() const
27 //lyxerr << "cloning MacroTemplate!\n";
28 return new MathMacroTemplate(*this);
32 int MathMacroTemplate::numargs() const
38 void MathMacroTemplate::numargs(int numargs)
44 string const & MathMacroTemplate::name() const
50 void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
54 width_ = xcell(0).width() + xcell(1).width() + 10;
55 ascent_ = std::max(xcell(0).ascent(), xcell(1).ascent()) + 2;
56 descent_ = std::max(xcell(0).descent(), xcell(1).descent()) + 2;
60 void MathMacroTemplate::draw(Painter & pain, int x, int y) const
62 int const w0 = xcell(0).width();
63 int const w1 = xcell(1).width();
64 xcell(0).draw(pain, x + 2, y + 1);
65 pain.rectangle(x, y - ascent() + 1, w0 + 4, height(), LColor::blue);
66 xcell(1).draw(pain, x + 8 + w0, y + 1);
67 pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4, height(), LColor::blue);
71 void MathMacroTemplate::write(WriteStream & os) const
74 os << "\n\\newcommand{\\" << name_.c_str() << '}';
76 os << '[' << numargs_ << ']';
77 os << '{' << cell(0) << "}\n";
80 os << "\n\\newcommand{\\" << name_.c_str() << '}';
82 os << '[' << numargs_ << ']';
83 os << '{' << cell(0) << '}';
84 // write special .tex export only if necessary
86 os << "\n{" << cell(1) << '}';