2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
#include "math_hullinset.h"
|
2001-12-11 15:04:02 +00:00
|
|
|
#include "math_mathmlstream.h"
|
|
|
|
#include "math_streamstr.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "debug.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2002-05-02 07:30:49 +00:00
|
|
|
#include "textpainter.h"
|
|
|
|
#include "Lsstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2001-12-11 15:04:02 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
|
|
|
|
#include <vector>
|
2001-02-14 15:00:50 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::max;
|
2001-12-05 08:04:20 +00:00
|
|
|
using std::endl;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
namespace {
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
int getCols(MathInsetTypes type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
return 3;
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
return 2;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
|
|
|
// returns position of first relation operator in the array
|
|
|
|
// used for "intelligent splitting"
|
2002-01-08 13:31:14 +00:00
|
|
|
MathArray::size_type firstRelOp(MathArray const & ar)
|
2001-10-18 13:21:21 +00:00
|
|
|
{
|
|
|
|
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
|
|
|
|
if ((*it)->isRelOp())
|
|
|
|
return it - ar.begin();
|
|
|
|
return ar.size();
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
char const * star(bool numbered)
|
|
|
|
{
|
|
|
|
return numbered ? "" : "*";
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
MathInsetTypes typecode(string const & s)
|
|
|
|
{
|
|
|
|
if (s == "equation") return LM_OT_EQUATION;
|
|
|
|
if (s == "display") return LM_OT_EQUATION;
|
|
|
|
if (s == "eqnarray") return LM_OT_EQNARRAY;
|
|
|
|
if (s == "align") return LM_OT_ALIGN;
|
|
|
|
if (s == "alignat") return LM_OT_ALIGNAT;
|
|
|
|
if (s == "xalignat") return LM_OT_XALIGNAT;
|
|
|
|
if (s == "xxalignat") return LM_OT_XXALIGNAT;
|
|
|
|
if (s == "multline") return LM_OT_MULTLINE;
|
|
|
|
if (s == "gather") return LM_OT_GATHER;
|
|
|
|
return LM_OT_SIMPLE;
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
string normalName(MathInsetTypes t)
|
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
case LM_OT_EQUATION: return "equation";
|
|
|
|
case LM_OT_EQNARRAY: return "eqnarray";
|
|
|
|
case LM_OT_ALIGN: return "align";
|
|
|
|
case LM_OT_ALIGNAT: return "alignat";
|
|
|
|
case LM_OT_XALIGNAT: return "xalignat";
|
|
|
|
case LM_OT_XXALIGNAT: return "xxalignat";
|
|
|
|
case LM_OT_MULTLINE: return "multline";
|
|
|
|
case LM_OT_GATHER: return "gather";
|
|
|
|
case LM_OT_SIMPLE: return "simple";
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "unknown";
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-10-18 13:21:21 +00:00
|
|
|
|
|
|
|
} // end anon namespace
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
MathHullInset::MathHullInset()
|
2001-09-04 08:48:23 +00:00
|
|
|
: MathGridInset(1, 1), objtype_(LM_OT_SIMPLE), nonum_(1), label_(1)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
|
|
|
setDefaults();
|
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
MathHullInset::MathHullInset(MathInsetTypes t)
|
2001-08-08 17:26:30 +00:00
|
|
|
: MathGridInset(getCols(t), 1), objtype_(t), nonum_(1), label_(1)
|
2002-02-14 13:25:26 +00:00
|
|
|
{
|
|
|
|
setDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathHullInset::MathHullInset(MathInsetTypes t, MathGridInset const & grid)
|
|
|
|
: MathGridInset(grid), objtype_(t), nonum_(1), label_(1)
|
2001-08-02 09:59:09 +00:00
|
|
|
{
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-08-02 09:59:09 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
MathHullInset::MathHullInset(MathInsetTypes t, col_type cols)
|
2001-09-04 08:48:23 +00:00
|
|
|
: MathGridInset(cols, 1), objtype_(t), nonum_(1), label_(1)
|
|
|
|
{
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-09-04 08:48:23 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
MathInset * MathHullInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-11-08 12:30:26 +00:00
|
|
|
return new MathHullInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
char MathHullInset::defaultColAlign(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
|
|
|
switch (getType()) {
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
return "rl"[col & 1];
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
return "rcl"[col];
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return 'c';
|
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
int MathHullInset::defaultColSpace(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
|
|
|
switch (getType()) {
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
return 0;
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
return (col & 1) ? 20 : 0;
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
return (col & 1) ? 40 : 0;
|
|
|
|
default:;
|
|
|
|
}
|
2001-11-28 13:09:40 +00:00
|
|
|
return 0;
|
2001-09-04 13:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::metrics(MathMetricsInfo const & mi) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
mi_ = mi;
|
|
|
|
mi_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
// let the cells adjust themselves
|
2001-10-22 15:37:49 +00:00
|
|
|
MathGridInset::metrics(mi_);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (display()) {
|
|
|
|
ascent_ += 12;
|
|
|
|
descent_ += 12;
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-03-06 17:44:53 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (numberedType()) {
|
2002-03-19 16:55:58 +00:00
|
|
|
whichFont(mi_.font, LM_TC_BF, mi_);
|
2001-06-25 00:06:33 +00:00
|
|
|
int l = 0;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2002-03-19 16:55:58 +00:00
|
|
|
l = max(l, mathed_string_width(mi_.font, nicelabel(row)));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (l)
|
|
|
|
width_ += 30 + l;
|
2001-02-16 09:25:43 +00:00
|
|
|
}
|
2001-09-03 11:38:04 +00:00
|
|
|
|
|
|
|
// make it at least as high as the current font
|
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
2002-03-19 16:55:58 +00:00
|
|
|
math_font_max_dim(mi_.font, asc, des);
|
2002-02-16 15:59:55 +00:00
|
|
|
ascent_ = max(ascent_, asc);
|
|
|
|
descent_ = max(descent_, des);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::draw(Painter & pain, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
MathGridInset::draw(pain, x, y);
|
|
|
|
|
|
|
|
if (numberedType()) {
|
2001-10-19 17:46:13 +00:00
|
|
|
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-10-19 17:46:13 +00:00
|
|
|
int const yy = y + rowinfo_[row].offset_;
|
2002-03-19 16:55:58 +00:00
|
|
|
drawStr(pain, mi_.font, xx, yy, nicelabel(row));
|
2001-07-20 14:54:13 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-02 07:30:49 +00:00
|
|
|
|
|
|
|
void MathHullInset::metricsT(TextMetricsInfo const &) const
|
2002-03-18 11:45:53 +00:00
|
|
|
{
|
2002-05-02 07:30:49 +00:00
|
|
|
#if 0
|
|
|
|
if (display()) {
|
|
|
|
MathGridInset::metricsT(mi);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
WriteStream wi(os, false, true);
|
|
|
|
write(wi);
|
|
|
|
width_ = os.str().size();
|
|
|
|
ascent_ = 1;
|
|
|
|
descent_ = 0;
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
void MathHullInset::drawT(TextPainter & pain, int x, int y) const
|
2002-03-18 11:45:53 +00:00
|
|
|
{
|
2002-05-02 07:30:49 +00:00
|
|
|
#if 0
|
|
|
|
if (display()) {
|
|
|
|
MathGridInset::drawT(pain, x, y);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
WriteStream wi(os, false, true);
|
|
|
|
write(wi);
|
|
|
|
pain.draw(x, y, os.str().c_str());
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
string MathHullInset::label(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-12-11 15:04:02 +00:00
|
|
|
row_type n = nrows();
|
|
|
|
lyx::Assert(row < n);
|
2001-06-25 00:06:33 +00:00
|
|
|
return label_[row];
|
|
|
|
}
|
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::label(row_type row, string const & label)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
label_[row] = label;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::numbered(row_type row, bool num)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
nonum_[row] = !num;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
bool MathHullInset::numbered(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return !nonum_[row];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
bool MathHullInset::ams() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return true;
|
2002-01-08 11:39:24 +00:00
|
|
|
/*
|
2002-03-21 17:42:56 +00:00
|
|
|
return
|
2001-11-05 17:08:45 +00:00
|
|
|
objtype_ == LM_OT_ALIGN ||
|
|
|
|
objtype_ == LM_OT_MULTLINE ||
|
|
|
|
objtype_ == LM_OT_GATHER ||
|
|
|
|
objtype_ == LM_OT_ALIGNAT ||
|
|
|
|
objtype_ == LM_OT_XALIGNAT ||
|
|
|
|
objtype_ == LM_OT_XXALIGNAT;
|
2002-01-08 11:39:24 +00:00
|
|
|
*/
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
bool MathHullInset::display() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
return getType() != LM_OT_SIMPLE;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
vector<string> const MathHullInset::getLabelList() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
vector<string> res;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!label_[row].empty() && nonum_[row] != 1)
|
|
|
|
res.push_back(label_[row]);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
bool MathHullInset::numberedType() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-04 14:56:30 +00:00
|
|
|
if (getType() == LM_OT_SIMPLE || getType() == LM_OT_XXALIGNAT)
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!nonum_[row])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::validate(LaTeXFeatures & features) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-11-19 15:34:11 +00:00
|
|
|
if (ams())
|
2002-01-10 10:05:45 +00:00
|
|
|
features.require("amsmath");
|
2001-11-19 15:34:11 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
// Validation is necessary only if not using AMS math.
|
2001-07-26 06:56:43 +00:00
|
|
|
// To be safe, we will always run mathedvalidate.
|
2001-06-25 00:06:33 +00:00
|
|
|
//if (features.amsstyle)
|
|
|
|
// return;
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("boldsymbol");
|
2001-07-13 14:54:56 +00:00
|
|
|
//features.binom = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
MathNestInset::validate(features);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-19 19:06:05 +00:00
|
|
|
void MathHullInset::header_write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_SIMPLE:
|
2001-07-27 09:55:44 +00:00
|
|
|
os << '$';
|
|
|
|
if (cell(0).empty())
|
|
|
|
os << ' ';
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
if (n)
|
2002-03-21 17:42:56 +00:00
|
|
|
os << "\\begin{equation" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2002-03-21 17:42:56 +00:00
|
|
|
os << "\\[\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
os << "\\begin{eqnarray" << star(n) << "}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\\begin{align" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGNAT:
|
2001-11-20 14:59:39 +00:00
|
|
|
os << "\\begin{alignat" << star(n) << "}"
|
|
|
|
<< "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_XALIGNAT:
|
2001-11-20 14:59:39 +00:00
|
|
|
os << "\\begin{xalignat" << star(n) << "}"
|
|
|
|
<< "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
|
|
case LM_OT_XXALIGNAT:
|
2002-03-21 17:42:56 +00:00
|
|
|
os << "\\begin{xxalignat}"
|
2001-11-20 14:59:39 +00:00
|
|
|
<< "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
break;
|
|
|
|
|
2001-09-04 14:56:30 +00:00
|
|
|
case LM_OT_MULTLINE:
|
|
|
|
os << "\\begin{multline}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_GATHER:
|
|
|
|
os << "\\begin{gather}\n";
|
|
|
|
break;
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
default:
|
|
|
|
os << "\\begin{unknown" << star(n) << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-19 19:06:05 +00:00
|
|
|
void MathHullInset::footer_write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_SIMPLE:
|
2001-07-27 09:55:44 +00:00
|
|
|
os << '$';
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
if (n)
|
2002-03-21 17:42:56 +00:00
|
|
|
os << "\\end{equation" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2002-03-21 17:42:56 +00:00
|
|
|
os << "\\]\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{eqnarray" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{align" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGNAT:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{alignat" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_XALIGNAT:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{xalignat" << star(n) << "}\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_XXALIGNAT:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{xxalignat}\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
break;
|
|
|
|
|
2001-09-04 14:56:30 +00:00
|
|
|
case LM_OT_MULTLINE:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{multline}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_GATHER:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{gather}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
default:
|
|
|
|
os << "\\end{unknown" << star(n) << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
void MathHullInset::addRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
nonum_.insert(nonum_.begin() + row + 1, !numberedType());
|
|
|
|
label_.insert(label_.begin() + row + 1, string());
|
|
|
|
MathGridInset::addRow(row);
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::appendRow()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
nonum_.push_back(!numberedType());
|
|
|
|
label_.push_back(string());
|
|
|
|
MathGridInset::appendRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
void MathHullInset::delRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
MathGridInset::delRow(row);
|
|
|
|
nonum_.erase(nonum_.begin() + row);
|
|
|
|
label_.erase(label_.begin() + row);
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::addCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_EQUATION:
|
|
|
|
mutate(LM_OT_EQNARRAY);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
mutate(LM_OT_ALIGN);
|
|
|
|
addCol(col);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-04 13:32:06 +00:00
|
|
|
mutate(LM_OT_ALIGNAT);
|
|
|
|
addCol(col);
|
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::addCol(col);
|
2001-09-04 13:32:06 +00:00
|
|
|
MathGridInset::addCol(col + 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::delCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
MathGridInset::delCol(col + 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::delCol(col);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
string MathHullInset::nicelabel(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (nonum_[row])
|
|
|
|
return string();
|
|
|
|
if (label_[row].empty())
|
|
|
|
return string("(#)");
|
|
|
|
return "(" + label_[row] + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::mutate(string const & newtype)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (newtype == "dump") {
|
|
|
|
dump();
|
|
|
|
return;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-07-26 06:56:43 +00:00
|
|
|
//lyxerr << "mutating from '" << getType() << "' to '" << newtype << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(typecode(newtype));
|
|
|
|
}
|
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::glueall()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
MathArray ar;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-06-25 00:06:33 +00:00
|
|
|
ar.push_back(cell(i));
|
2001-11-08 12:30:26 +00:00
|
|
|
*this = MathHullInset(LM_OT_SIMPLE);
|
2001-06-25 00:06:33 +00:00
|
|
|
cell(0) = ar;
|
|
|
|
}
|
|
|
|
|
2001-08-01 13:28:45 +00:00
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
MathInsetTypes MathHullInset::getType() const
|
2001-08-01 13:28:45 +00:00
|
|
|
{
|
|
|
|
return objtype_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::setType(MathInsetTypes t)
|
2001-08-01 13:28:45 +00:00
|
|
|
{
|
|
|
|
objtype_ = t;
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-08-01 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
void MathHullInset::mutate(MathInsetTypes newtype)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
//lyxerr << "mutating from '" << getType() << "' to '" << newtype << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
if (newtype == getType())
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_SIMPLE:
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_EQUATION);
|
2001-07-13 12:43:24 +00:00
|
|
|
numbered(0, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_SIMPLE:
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_SIMPLE);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
case LM_OT_ALIGN:
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT: {
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::addCol(1);
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
|
|
// split it "nicely"
|
2002-03-21 17:42:56 +00:00
|
|
|
pos_type pos = firstRelOp(cell(0));
|
2001-07-09 16:59:57 +00:00
|
|
|
cell(1) = cell(0);
|
|
|
|
cell(0).erase(pos, cell(0).size());
|
|
|
|
cell(1).erase(0, pos);
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_ALIGN);
|
2001-09-04 13:32:06 +00:00
|
|
|
mutate(newtype);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-09 16:59:57 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
case LM_OT_EQNARRAY:
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
MathGridInset::addCol(1);
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
|
|
// split it "nicely" on the firest relop
|
2002-03-21 17:42:56 +00:00
|
|
|
pos_type pos = firstRelOp(cell(0));
|
2001-11-09 10:44:24 +00:00
|
|
|
cell(1) = MathArray(cell(0), pos, cell(0).size());
|
2001-08-07 12:02:21 +00:00
|
|
|
cell(0).erase(pos, cell(0).size());
|
|
|
|
|
|
|
|
if (cell(1).size()) {
|
2001-11-09 10:44:24 +00:00
|
|
|
cell(2) = MathArray(cell(1), 1, cell(1).size());
|
2001-08-07 12:02:21 +00:00
|
|
|
cell(1).erase(1, cell(1).size());
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_EQNARRAY);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_SIMPLE:
|
2001-07-09 10:19:50 +00:00
|
|
|
case LM_OT_EQUATION: {
|
2001-07-09 16:59:57 +00:00
|
|
|
// set correct (no)numbering
|
2001-07-09 10:19:50 +00:00
|
|
|
bool allnonum = true;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-09-26 15:20:45 +00:00
|
|
|
if (!nonum_[row])
|
2001-07-09 10:19:50 +00:00
|
|
|
allnonum = false;
|
|
|
|
}
|
2001-07-09 16:42:22 +00:00
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
// set first non-empty label
|
2001-07-09 16:42:22 +00:00
|
|
|
string label;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-09-26 15:20:45 +00:00
|
|
|
if (!label_[row].empty()) {
|
|
|
|
label = label_[row];
|
2001-07-09 16:42:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
glueall();
|
2001-07-10 10:40:23 +00:00
|
|
|
|
|
|
|
nonum_[0] = allnonum;
|
|
|
|
label_[0] = label;
|
2001-07-06 12:09:32 +00:00
|
|
|
mutate(newtype);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-09 10:19:50 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
2001-07-09 16:59:57 +00:00
|
|
|
default: {
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type c = 3 * row + 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
cell(c).push_back(cell(c + 1));
|
|
|
|
}
|
|
|
|
MathGridInset::delCol(2);
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_ALIGN);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
2001-07-09 16:59:57 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_SIMPLE:
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
MathGridInset::addCol(1);
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_EQNARRAY);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
setType(newtype);
|
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
2001-07-26 06:56:43 +00:00
|
|
|
lyxerr << "mutation from '" << getType()
|
2001-12-05 08:04:20 +00:00
|
|
|
<< "' to '" << newtype << "' not implemented"
|
|
|
|
<< endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-09-04 14:56:30 +00:00
|
|
|
case LM_OT_MULTLINE:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_GATHER:
|
|
|
|
setType(LM_OT_GATHER);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lyxerr << "mutation from '" << getType()
|
2001-12-05 08:04:20 +00:00
|
|
|
<< "' to '" << newtype << "' not implemented"
|
|
|
|
<< endl;
|
2001-09-04 14:56:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_GATHER:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_MULTLINE:
|
|
|
|
setType(LM_OT_MULTLINE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lyxerr << "mutation from '" << getType()
|
2001-12-05 08:04:20 +00:00
|
|
|
<< "' to '" << newtype << "' not implemented"
|
|
|
|
<< endl;
|
2001-09-04 14:56:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
2001-07-26 06:56:43 +00:00
|
|
|
lyxerr << "mutation from '" << getType()
|
2001-12-05 08:04:20 +00:00
|
|
|
<< "' to '" << newtype << "' not implemented"
|
|
|
|
<< endl;
|
|
|
|
break;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathHullInset::write(WriteStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
header_write(os);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
bool n = numberedType();
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2002-03-21 17:42:56 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
2001-12-05 08:04:20 +00:00
|
|
|
os << cell(index(row, col)) << eocString(col);
|
2001-11-08 12:06:56 +00:00
|
|
|
if (n) {
|
|
|
|
if (!label_[row].empty())
|
2001-12-05 08:04:20 +00:00
|
|
|
os << "\\label{" << label_[row] << "}";
|
2001-11-08 12:06:56 +00:00
|
|
|
if (nonum_[row])
|
|
|
|
os << "\\nonumber ";
|
|
|
|
}
|
2001-12-05 08:04:20 +00:00
|
|
|
os << eolString(row);
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
footer_write(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathHullInset::normalize(NormalStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
os << "[formula " << normalName(getType()) << " ";
|
2001-11-09 08:35:57 +00:00
|
|
|
MathGridInset::normalize(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 18:02:20 +00:00
|
|
|
void MathHullInset::mathmlize(MathMLStream & os) const
|
|
|
|
{
|
|
|
|
MathGridInset::mathmlize(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
void MathHullInset::check() const
|
|
|
|
{
|
|
|
|
lyx::Assert(nonum_.size() == nrows());
|
|
|
|
lyx::Assert(label_.size() == nrows());
|
|
|
|
}
|