5 #include "math_macrotemplate.h"
6 #include "math_mathmlstream.h"
7 #include "math_parser.h"
8 #include "frontends/Painter.h"
12 MathMacroTemplate::MathMacroTemplate()
13 : MathNestInset(2), numargs_(0), name_()
17 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs,
18 MathArray const & ar1, MathArray const & ar2)
19 : MathNestInset(2), numargs_(numargs), name_(nm)
22 lyxerr << "MathMacroTemplate::MathMacroTemplate: wrong # of arguments: "
23 << numargs_ << std::endl;
30 MathMacroTemplate::MathMacroTemplate(std::istream & is)
31 : MathNestInset(2), numargs_(0), name_()
34 mathed_parse_cell(ar, is);
35 if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
36 lyxerr << "cannot read macro from '" << ar << "'\n";
39 operator=( *(ar[0]->asMacroTemplate()) );
43 MathInset * MathMacroTemplate::clone() const
45 //lyxerr << "cloning MacroTemplate!\n";
46 return new MathMacroTemplate(*this);
50 int MathMacroTemplate::numargs() const
56 void MathMacroTemplate::numargs(int numargs)
62 string MathMacroTemplate::name() const
68 void MathMacroTemplate::metrics(MathMetricsInfo & mi) const
72 dim_.w = cell(0).width() + cell(1).width() + 10;
73 dim_.a = std::max(cell(0).ascent(), cell(1).ascent()) + 2;
74 dim_.d = std::max(cell(0).descent(), cell(1).descent()) + 2;
78 void MathMacroTemplate::draw(MathPainterInfo & pi, int x, int y) const
80 int const w0 = cell(0).width();
81 int const w1 = cell(1).width();
82 cell(0).draw(pi, x + 2, y + 1);
83 pi.pain.rectangle(x, y - ascent() + 1, w0 + 4, height(),
85 cell(1).draw(pi, x + 8 + w0, y + 1);
86 pi.pain.rectangle(x + w0 + 6 , y - ascent() + 1, w1 + 4,
87 height(), LColor::blue);
92 void MathMacroTemplate::write(WriteStream & os) const
95 os << "\n\\newcommand{\\" << name_.c_str() << '}';
97 os << '[' << numargs_ << ']';
98 os << '{' << cell(0) << "}\n";
101 os << "\n\\newcommand{\\" << name_.c_str() << '}';
103 os << '[' << numargs_ << ']';
104 os << '{' << cell(0) << '}';
105 // write special .tex export only if necessary
106 if (!cell(1).empty())
107 os << "\n{" << cell(1) << '}';