3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "math_macro.h"
15 #include "math_support.h"
16 #include "math_extern.h"
17 #include "math_mathmlstream.h"
22 #include "BufferView.h"
23 #include "LaTeXFeatures.h"
31 MathMacro::MathMacro(string const & name, int numargs)
32 : MathNestInset(numargs), name_(name)
36 auto_ptr<InsetBase> MathMacro::clone() const
38 return auto_ptr<InsetBase>(new MathMacro(*this));
42 string MathMacro::name() const
48 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
50 if (!MacroTable::globalMacros().has(name())) {
51 mathed_string_dim(mi.base.font, "Unknown: " + name(), dim);
52 } else if (editing(mi.base.bv)) {
53 asArray(MacroTable::globalMacros().get(name()).def(), tmpl_);
54 LyXFont font = mi.base.font;
55 augmentFont(font, "lyxtex");
56 tmpl_.metrics(mi, dim);
57 dim.wid += mathed_string_width(font, name()) + 10;
58 int ww = mathed_string_width(font, "#1: ");
59 for (idx_type i = 0; i < nargs(); ++i) {
60 MathArray const & c = cell(i);
62 dim.wid = max(dim.wid, c.width() + ww);
63 dim.des += c.height() + 10;
66 MacroTable::globalMacros().get(name()).expand(cells_, expanded_);
67 expanded_.metrics(mi, dim);
74 void MathMacro::draw(PainterInfo & pi, int x, int y) const
76 if (!MacroTable::globalMacros().has(name())) {
77 drawStrRed(pi, x, y, "Unknown: " + name());
78 } else if (editing(pi.base.bv)) {
79 LyXFont font = pi.base.font;
80 augmentFont(font, "lyxtex");
81 int h = y - dim_.ascent() + 2 + tmpl_.ascent();
82 drawStr(pi, font, x + 3, h, name());
83 int const w = mathed_string_width(font, name());
84 tmpl_.draw(pi, x + w + 12, h);
87 mathed_string_dim(font, "#1: ", ldim);
88 for (idx_type i = 0; i < nargs(); ++i) {
89 MathArray const & c = cell(i);
90 h += max(c.ascent(), ldim.asc) + 5;
91 c.draw(pi, x + ldim.wid, h);
93 str[1] += static_cast<char>(i);
94 drawStr(pi, font, x + 3, h, str);
95 h += max(c.descent(), ldim.des) + 5;
98 expanded_.draw(pi, x, y);
100 drawMarkers2(pi, x, y);
104 void MathMacro::validate(LaTeXFeatures & features) const
106 if (name() == "binom" || name() == "mathcircumflex")
107 features.require(name());
111 void MathMacro::maple(MapleStream & os) const
114 ::maple(expanded_, os);
118 void MathMacro::mathmlize(MathMLStream & os) const
121 ::mathmlize(expanded_, os);
125 void MathMacro::octave(OctaveStream & os) const
128 ::octave(expanded_, os);
132 void MathMacro::updateExpansion() const
134 //expanded_.substitute(*this);
138 void MathMacro::infoize(std::ostream & os) const
140 os << "Macro: " << name();
144 void MathMacro::infoize2(std::ostream & os) const
146 os << "Macro: " << name();