2 #include "math_macrotemplate.h"
3 #include "math_mathmlstream.h"
4 #include "math_parser.h"
5 #include "frontends/Painter.h"
9 MathMacroTemplate::MathMacroTemplate()
10 : MathNestInset(2), numargs_(0), name_()
14 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs,
15 MathArray const & ar1, MathArray const & ar2)
16 : MathNestInset(2), numargs_(numargs), name_(nm)
19 lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
20 << numargs_ << std::endl;
27 MathMacroTemplate::MathMacroTemplate(std::istream & is)
28 : MathNestInset(2), numargs_(0), name_()
31 mathed_parse_cell(ar, is);
32 if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
33 lyxerr << "cannot read macro from '" << ar << "'\n";
36 operator=( *(ar[0]->asMacroTemplate()) );
40 MathInset * MathMacroTemplate::clone() const
42 //lyxerr << "cloning MacroTemplate!\n";
43 return new MathMacroTemplate(*this);
47 int MathMacroTemplate::numargs() const
53 void MathMacroTemplate::numargs(int numargs)
59 string MathMacroTemplate::name() const
65 void MathMacroTemplate::metrics(MetricsInfo & mi) const
69 dim_.w = cell(0).width() + cell(1).width() + 10;
70 dim_.a = std::max(cell(0).ascent(), cell(1).ascent()) + 2;
71 dim_.d = std::max(cell(0).descent(), cell(1).descent()) + 2;
75 void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
77 int const w0 = cell(0).width();
78 int const w1 = cell(1).width();
79 cell(0).draw(pi, x + 2, y + 1);
80 pi.pain.rectangle(x, y - ascent() + 1, w0 + 4, height(),
82 cell(1).draw(pi, x + 8 + w0, y + 1);
83 pi.pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4,
84 height(), LColor::mathline);
89 void MathMacroTemplate::write(WriteStream & os) const
92 os << "\n\\newcommand{\\" << name_.c_str() << '}';
94 os << '[' << numargs_ << ']';
95 os << '{' << cell(0) << "}\n";
98 os << "\n\\newcommand{\\" << name_.c_str() << '}';
100 os << '[' << numargs_ << ']';
101 os << '{' << cell(0) << '}';
102 // write special .tex export only if necessary
103 if (!cell(1).empty())
104 os << "\n{" << cell(1) << '}';