2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_scriptinset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "math_scriptinset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
|
|
|
|
#include "math_mathmlstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2001-11-27 13:57:49 +00:00
|
|
|
|
#include "math_symbolinset.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "debug.h"
|
2002-08-28 17:59:32 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
2001-06-25 00:06:33 +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
|
|
|
|
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
MathScriptInset::MathScriptInset()
|
2002-07-30 13:56:02 +00:00
|
|
|
|
: MathNestInset(3), limits_(0)
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
|
|
|
|
script_[0] = false;
|
|
|
|
|
script_[1] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
MathScriptInset::MathScriptInset(bool up)
|
2002-07-30 13:56:02 +00:00
|
|
|
|
: MathNestInset(3), limits_(0)
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
|
|
|
|
script_[0] = !up;
|
|
|
|
|
script_[1] = up;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
|
|
|
|
|
: MathNestInset(3), limits_(0)
|
|
|
|
|
{
|
|
|
|
|
script_[0] = !up;
|
|
|
|
|
script_[1] = up;
|
|
|
|
|
cell(2).push_back(at);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> MathScriptInset::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathScriptInset(*this));
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-24 16:25:06 +00:00
|
|
|
|
MathScriptInset const * MathScriptInset::asScriptInset() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
MathScriptInset * MathScriptInset::asScriptInset()
|
2001-07-26 06:46:50 +00:00
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return this;
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxFirst(LCursor & cur) const
|
2001-07-26 06:46:50 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 2;
|
|
|
|
|
cur.pos() = 0;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxLast(LCursor & cur) const
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 2;
|
|
|
|
|
cur.pos() = nuc().size();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return true;
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathScriptInset::down() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(0);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray & MathScriptInset::down()
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(0);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathScriptInset::up() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(1);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray & MathScriptInset::up()
|
2001-09-11 10:58:17 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(1);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::ensure(bool up)
|
|
|
|
|
{
|
|
|
|
|
script_[up] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & MathScriptInset::nuc() const
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(2);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray & MathScriptInset::nuc()
|
2002-07-30 13:56:02 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cell(2);
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathScriptInset::dy0() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int nd = ndes();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
if (!hasDown())
|
|
|
|
|
return nd;
|
|
|
|
|
int des = down().ascent();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits())
|
2001-10-12 12:02:49 +00:00
|
|
|
|
des += nd + 2;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
else
|
2002-02-16 15:59:55 +00:00
|
|
|
|
des = max(des, nd);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return des;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dy1() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int na = nasc();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
if (!hasUp())
|
|
|
|
|
return na;
|
|
|
|
|
int asc = up().descent();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits())
|
2001-10-12 12:02:49 +00:00
|
|
|
|
asc += na + 2;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
else
|
2002-02-16 15:59:55 +00:00
|
|
|
|
asc = max(asc, na);
|
2002-08-02 14:04:16 +00:00
|
|
|
|
asc = max(asc, 5);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return asc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dx0() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(hasDown());
|
2003-05-27 13:55:03 +00:00
|
|
|
|
return hasLimits() ? (dim_.wid - down().width()) / 2 : nwid();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dx1() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(hasUp());
|
2003-05-27 13:55:03 +00:00
|
|
|
|
return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid();
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::dxx() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2003-05-27 13:55:03 +00:00
|
|
|
|
return hasLimits() ? (dim_.wid - nwid()) / 2 : 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::nwid() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:04:16 +00:00
|
|
|
|
return nuc().size() ? nuc().width() : 2;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::nasc() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:04:16 +00:00
|
|
|
|
return nuc().size() ? nuc().ascent() : 5;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
int MathScriptInset::ndes() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-08-02 14:04:16 +00:00
|
|
|
|
return nuc().size() ? nuc().descent() : 0;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathScriptInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-08-05 16:21:19 +00:00
|
|
|
|
cell(2).metrics(mi);
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ScriptChanger dummy(mi.base);
|
2002-08-05 16:21:19 +00:00
|
|
|
|
cell(0).metrics(mi);
|
|
|
|
|
cell(1).metrics(mi);
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = 0;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasLimits()) {
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = nwid();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp())
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = max(dim_.wid, up().width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown())
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = max(dim_.wid, down().width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (hasUp())
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = max(dim_.wid, up().width());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown())
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = max(dim_.wid, down().width());
|
|
|
|
|
dim_.wid += nwid();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.asc = dy1() + (hasUp() ? up().ascent() : 0);
|
|
|
|
|
dim_.des = dy0() + (hasDown() ? down().descent() : 0);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
metricsMarkers();
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim = dim_;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathScriptInset::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
|
|
|
|
nuc().draw(pi, x + dxx(), y);
|
2002-09-11 08:26:02 +00:00
|
|
|
|
else {
|
|
|
|
|
nuc().setXY(x + dxx(), y);
|
|
|
|
|
if (editing())
|
|
|
|
|
drawStr(pi, pi.base.font, x + dxx(), y, ".");
|
|
|
|
|
}
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ScriptChanger dummy(pi.base);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (hasUp())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
up().draw(pi, x + dx1(), y - dy1());
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (hasDown())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
down().draw(pi, x + dx0(), y + dy0());
|
2003-05-28 13:22:36 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathScriptInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-03-19 16:55:58 +00:00
|
|
|
|
if (hasUp())
|
2003-05-28 13:22:36 +00:00
|
|
|
|
up().metricsT(mi, dim);
|
2002-03-19 16:55:58 +00:00
|
|
|
|
if (hasDown())
|
2003-05-28 13:22:36 +00:00
|
|
|
|
down().metricsT(mi, dim);
|
|
|
|
|
nuc().metricsT(mi, dim);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
|
void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
|
|
|
|
nuc().drawT(pain, x + dxx(), y);
|
2002-03-18 11:45:53 +00:00
|
|
|
|
if (hasUp())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
up().drawT(pain, x + dx1(), y - dy1());
|
2002-03-18 11:45:53 +00:00
|
|
|
|
if (hasDown())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
down().drawT(pain, x + dx0(), y + dy0());
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool MathScriptInset::hasLimits() const
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{
|
2002-07-08 13:03:37 +00:00
|
|
|
|
// obvious cases
|
2001-11-27 13:57:49 +00:00
|
|
|
|
if (limits_ == 1)
|
|
|
|
|
return true;
|
|
|
|
|
if (limits_ == -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
// we can only display limits if the nucleus wants some
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (!nuc().size())
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (!nuc().back()->isScriptable())
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-11-27 13:57:49 +00:00
|
|
|
|
// per default \int has limits beside the \int even in displayed formulas
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().back()->asSymbolInset())
|
|
|
|
|
if (nuc().back()->asSymbolInset()->name().find("int") != string::npos)
|
2001-11-27 13:57:49 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// assume "real" limits for everything else
|
|
|
|
|
return true;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::removeScript(bool up)
|
|
|
|
|
{
|
|
|
|
|
cell(up).clear();
|
|
|
|
|
script_[up] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::has(bool up) const
|
|
|
|
|
{
|
|
|
|
|
return script_[up];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::hasUp() const
|
|
|
|
|
{
|
|
|
|
|
return script_[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathScriptInset::hasDown() const
|
|
|
|
|
{
|
|
|
|
|
return script_[0];
|
2001-07-26 06:46:50 +00:00
|
|
|
|
}
|
2001-10-12 15:38:58 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxRight(LCursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxLeft(LCursor &) const
|
2001-10-12 15:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathScriptInset::idxUpDown(LCursor & cur, bool up, int) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.idx() == 1) {
|
2002-08-09 08:14:18 +00:00
|
|
|
|
// if we are 'up' we can't go further up
|
|
|
|
|
if (up)
|
|
|
|
|
return false;
|
|
|
|
|
// otherwise go to last base position
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 2;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-09 08:14:18 +00:00
|
|
|
|
}
|
2002-07-30 13:56:02 +00:00
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
else if (cur.idx() == 0) {
|
2002-08-09 08:14:18 +00:00
|
|
|
|
// if we are 'down' we can't go further down
|
|
|
|
|
if (!up)
|
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 2;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
|
|
2002-08-09 08:14:18 +00:00
|
|
|
|
else {
|
|
|
|
|
// in nucleus
|
|
|
|
|
// don't go up/down if there is no cell.
|
|
|
|
|
if (!has(up))
|
|
|
|
|
return false;
|
2003-02-10 15:45:56 +00:00
|
|
|
|
// go up/down only if in the last position
|
|
|
|
|
// or in the first position of something with displayed limits
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && hasLimits())) {
|
|
|
|
|
cur.idx() = up;
|
|
|
|
|
cur.pos() = 0;
|
2003-02-10 15:45:56 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2002-08-09 08:14:18 +00:00
|
|
|
|
}
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return true;
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void MathScriptInset::write(WriteStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size()) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-09-30 06:48:53 +00:00
|
|
|
|
//if (nuc().back()->takesLimits()) {
|
2001-11-08 12:06:56 +00:00
|
|
|
|
if (limits_ == -1)
|
|
|
|
|
os << "\\nolimits ";
|
|
|
|
|
if (limits_ == 1)
|
|
|
|
|
os << "\\limits ";
|
2002-09-30 06:48:53 +00:00
|
|
|
|
//}
|
2002-07-30 13:56:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (os.firstitem())
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr[Debug::MATHED] << "suppressing {} when writing"
|
|
|
|
|
<< endl;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
else
|
|
|
|
|
os << "{}";
|
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (hasDown() && down().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "_{" << down() << '}';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (hasUp() && up().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "^{" << up() << '}';
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
|
|
|
|
if (lock_ && !os.latex())
|
|
|
|
|
os << "\\lyxlock ";
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathScriptInset::normalize(NormalStream & os) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
|
bool u = hasUp() && up().size();
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
2002-07-30 17:51:19 +00:00
|
|
|
|
if (u && d)
|
|
|
|
|
os << "[subsup ";
|
|
|
|
|
else if (u)
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << "[sup ";
|
2002-07-30 17:51:19 +00:00
|
|
|
|
else if (d)
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << "[sub ";
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc() << ' ';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
else
|
|
|
|
|
os << "[par]";
|
|
|
|
|
|
2002-07-30 17:51:19 +00:00
|
|
|
|
if (u && d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << ' ' << up() << ']';
|
2002-07-30 17:51:19 +00:00
|
|
|
|
else if (d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << ']';
|
2002-07-30 17:51:19 +00:00
|
|
|
|
else if (u)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << up() << ']';
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathScriptInset::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown() && down().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << '[' << down() << ']';
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp() && up().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "^(" << up() << ')';
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathScriptInset::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
|
bool u = hasUp() && up().size();
|
2002-07-01 11:17:14 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
if (d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "Subscript[" << nuc();
|
2002-07-01 11:17:14 +00:00
|
|
|
|
else
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-01 11:17:14 +00:00
|
|
|
|
if (u)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "^(" << up() << ')';
|
2002-07-01 11:17:14 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-07-01 11:17:14 +00:00
|
|
|
|
if (d)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ',' << down() << ']';
|
2002-07-01 11:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void MathScriptInset::mathmlize( MathMLStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-31 17:26:14 +00:00
|
|
|
|
bool d = hasDown() && down().size();
|
|
|
|
|
bool u = hasUp() && up().size();
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
if (u && d)
|
|
|
|
|
os << MTag("msubsup");
|
|
|
|
|
else if (u)
|
|
|
|
|
os << MTag("msup");
|
|
|
|
|
else if (d)
|
|
|
|
|
os << MTag("msub");
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else
|
|
|
|
|
os << "<mrow/>";
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
if (u && d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << up() << ETag("msubsup");
|
2001-11-08 12:06:56 +00:00
|
|
|
|
else if (u)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << up() << ETag("msup");
|
2001-11-08 12:06:56 +00:00
|
|
|
|
else if (d)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << down() << ETag("msub");
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathScriptInset::octave(OctaveStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (nuc().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << nuc();
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasDown() && down().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << '[' << down() << ']';
|
2002-07-30 13:56:02 +00:00
|
|
|
|
if (hasUp() && up().size())
|
2002-08-02 14:29:42 +00:00
|
|
|
|
os << "^(" << up() << ')';
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2002-07-08 13:03:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::infoize(std::ostream & os) const
|
|
|
|
|
{
|
2002-08-01 11:48:53 +00:00
|
|
|
|
os << "Scripts";
|
2003-01-07 11:24:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathScriptInset::infoize2(std::ostream & os) const
|
|
|
|
|
{
|
2002-07-08 13:03:37 +00:00
|
|
|
|
if (limits_)
|
2002-08-01 11:48:53 +00:00
|
|
|
|
os << (limits_ == 1 ? ", Displayed limits" : ", Inlined limits");
|
2002-07-08 13:03:37 +00:00
|
|
|
|
}
|
2002-08-28 17:59:32 +00:00
|
|
|
|
|
|
|
|
|
|
2002-10-29 08:23:32 +00:00
|
|
|
|
void MathScriptInset::notifyCursorLeaves(idx_type idx)
|
|
|
|
|
{
|
|
|
|
|
MathNestInset::notifyCursorLeaves(idx);
|
|
|
|
|
|
|
|
|
|
// remove empty scripts if possible
|
|
|
|
|
if (idx != 2 && script_[idx] && cell(idx).empty()) {
|
|
|
|
|
cell(idx).clear();
|
|
|
|
|
script_[idx] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2004-01-20 14:25:24 +00:00
|
|
|
|
MathScriptInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
|
2002-08-28 17:59:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (cmd.action == LFUN_MATH_LIMITS) {
|
2002-10-28 10:47:24 +00:00
|
|
|
|
if (!cmd.argument.empty()) {
|
|
|
|
|
if (cmd.argument == "limits")
|
|
|
|
|
limits_ = 1;
|
|
|
|
|
else if (cmd.argument == "nolimits")
|
|
|
|
|
limits_ = -1;
|
|
|
|
|
else
|
|
|
|
|
limits_ = 0;
|
|
|
|
|
} else if (limits_ == 0)
|
2004-01-07 08:36:30 +00:00
|
|
|
|
limits_ = hasLimits() ? -1 : 1;
|
2002-10-28 10:47:24 +00:00
|
|
|
|
else
|
|
|
|
|
limits_ = 0;
|
2003-11-03 19:52:47 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2002-08-28 17:59:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-15 17:34:44 +00:00
|
|
|
|
return MathNestInset::priv_dispatch(bv, cmd);
|
2002-08-28 17:59:32 +00:00
|
|
|
|
}
|