2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_macro.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include "math_macro.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2001-11-16 08:26:41 +00:00
|
|
|
|
#include "math_extern.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2001-11-16 08:26:41 +00:00
|
|
|
|
#include "debug.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#include "BufferView.h"
|
2001-07-13 14:54:56 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::max;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
using std::endl;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
MathMacro::MathMacro(string const & name)
|
|
|
|
|
: name_(name)
|
2001-07-12 11:55:57 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> MathMacro::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathMacro(*this));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-09 09:19:18 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
string MathMacro::name() const
|
2001-08-08 17:26:30 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
return name_;
|
2001-08-08 17:26:30 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-09 09:19:18 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
void MathMacro::setExpansion(MathArray const & exp, MathArray const & arg) const
|
2001-10-12 16:12:32 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
expanded_ = exp;
|
|
|
|
|
args_ = arg;
|
2001-10-12 16:12:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-03-25 12:11:25 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
LyXFont font = mi.base.font;
|
|
|
|
|
augmentFont(font, "lyxtex");
|
|
|
|
|
mathed_string_dim(font, "\\" + name(), dim);
|
|
|
|
|
dim_ = dim;
|
2002-03-25 12:11:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
void MathMacro::metricsExpanded(MetricsInfo & mi, Dimension & dim) const
|
2001-04-24 16:13:38 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
args_.metrics(mi);
|
|
|
|
|
expanded_.metrics(mi, dim);
|
|
|
|
|
dim.wid -= args_.size() ? args_.width() : 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim_ = dim;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathMacro::draw(PainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
LyXFont font = pi.base.font;
|
|
|
|
|
augmentFont(font, "lyxtex");
|
|
|
|
|
drawStr(pi, font, x, y, "\\" + name());
|
2004-04-07 16:54:15 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2001-04-24 16:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
void MathMacro::drawExpanded(PainterInfo & pi, int x, int y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
expanded_.draw(pi, x, y);
|
|
|
|
|
drawMarkers2(pi, x, y);
|
2001-04-24 16:13:38 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
int MathMacro::widthExpanded() const
|
2001-04-25 15:43:57 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
return expanded_.width();
|
2001-04-25 15:43:57 +00:00
|
|
|
|
}
|
2001-07-13 14:54:56 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
|
void MathMacro::validate(LaTeXFeatures & features) const
|
2001-07-13 14:54:56 +00:00
|
|
|
|
{
|
2002-04-03 10:45:32 +00:00
|
|
|
|
if (name() == "binom" || name() == "mathcircumflex")
|
|
|
|
|
features.require(name());
|
2001-07-13 14:54:56 +00:00
|
|
|
|
}
|
2001-11-16 08:26:41 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathMacro::maple(MapleStream & os) const
|
2001-11-16 08:26:41 +00:00
|
|
|
|
{
|
2001-12-11 11:33:43 +00:00
|
|
|
|
updateExpansion();
|
2003-02-14 14:30:09 +00:00
|
|
|
|
::maple(expanded_, os);
|
2001-11-16 08:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-16 08:29:11 +00:00
|
|
|
|
void MathMacro::mathmlize(MathMLStream & os) const
|
|
|
|
|
{
|
2001-12-11 11:33:43 +00:00
|
|
|
|
updateExpansion();
|
2002-08-02 14:29:42 +00:00
|
|
|
|
::mathmlize(expanded_, os);
|
2001-11-16 08:29:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathMacro::octave(OctaveStream & os) const
|
2001-11-16 08:29:11 +00:00
|
|
|
|
{
|
2001-12-11 11:33:43 +00:00
|
|
|
|
updateExpansion();
|
2003-02-14 14:30:09 +00:00
|
|
|
|
::octave(expanded_, os);
|
2001-11-16 08:26:41 +00:00
|
|
|
|
}
|
2001-12-11 11:33:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::updateExpansion() const
|
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
//expand();
|
|
|
|
|
//expanded_.substitute(*this);
|
2001-12-11 11:33:43 +00:00
|
|
|
|
}
|
2003-01-07 11:24:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::infoize(std::ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "Macro: " << name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::infoize2(std::ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "Macro: " << name();
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
2003-01-07 11:24:43 +00:00
|
|
|
|
}
|