#include "math_symbolinset.h"
-MathExIntInset::MathExIntInset()
- : int_(new MathSymbolInset("int"))
+MathExIntInset::MathExIntInset(string const & name)
+ : symbol_(name)
{}
}
-void MathExIntInset::differential(MathArray const & ar)
+void MathExIntInset::index(MathArray const & ar)
{
- diff_ = ar;
+ index_ = ar;
}
}
-void MathExIntInset::symbol(MathAtom const & at)
+MathAtom & MathExIntInset::scripts()
{
- int_ = at;
+ return scripts_;
+}
+
+
+void MathExIntInset::symbol(string const & symbol)
+{
+ symbol_ = symbol;
}
void MathExIntInset::normalize(NormalStream & os) const
{
- os << "[int ";
+ os << '[' << symbol_.c_str() << ' ';
if (hasScripts())
os << scripts_.nucleus();
else
os << "{}";
- os << ' ' << core_ << ' ' << diff_ << ']';
+ os << ' ' << core_ << ' ' << index_ << ']';
}
void MathExIntInset::maplize(MapleStream & os) const
{
- os << int_.nucleus() << '(';
+ os << symbol_.c_str() << '(';
if (core_.size())
os << core_;
else
os << '1';
- os << ',' << diff_;
+ os << ',' << index_;
if (hasScripts()) {
MathScriptInset * p = scripts_->asScriptInset();
os << '=' << p->down().data_ << ".." << p->up().data_;
void MathExIntInset::mathmlize(MathMLStream & os) const
{
+ MathSymbolInset * sym = new MathSymbolInset(symbol_.c_str());
if (hasScripts())
- scripts_->asScriptInset()->mathmlize(int_.nucleus(), os);
+ scripts_->asScriptInset()->mathmlize(sym, os);
else
- int_->mathmlize(os);
+ sym->mathmlize(os);
+ delete sym;
os << core_ << "<mo> ⁢ </mo>"
<< MTag("mrow") << "<mo> ⅆ </mo>"
- << diff_ << ETag("mrow");
+ << index_ << ETag("mrow");
}
-void MathExIntInset::write(WriteStream & os) const
+void MathExIntInset::write(WriteStream &) const
{
- if (hasScripts())
- os << scripts_.nucleus();
- os << core_ << "d" << diff_;
+ lyxerr << "should not happen\n";
}
class MathExIntInset : public MathInset {
public:
///
- MathExIntInset();
+ explicit MathExIntInset(string const & name_);
///
MathInset * clone() const;
///
- void differential(MathArray const &);
+ void index(MathArray const &);
///
void core(MathArray const &);
///
void scripts(MathAtom const &);
///
- void symbol(MathAtom const &);
+ MathAtom & scripts();
///
- bool hasScripts() const;
+ void symbol(string const &);
///
void metrics(MathMetricsInfo const & st) const;
///
void write(WriteStream & os) const;
private:
///
- MathAtom int_;
+ bool hasScripts() const;
+
+ ///
+ string symbol_;
///
MathAtom scripts_;
///
MathArray core_;
///
- MathArray diff_;
+ MathArray index_;
};
+
#endif
// information" from the unstructered layout-oriented stuff in an
// MathArray.
+#include <algorithm>
#include "math_charinset.h"
#include "math_deliminset.h"
// define a function for tests
typedef bool TestItemFunc(MathInset *);
-// define a function for replacing pa
+// define a function for replacing subexpressions
typedef MathInset * ReplaceArgumentFunc(const MathArray & ar);
+
// search end of nested sequence
MathArray::iterator endNestSearch(
MathArray::iterator it,
continue;
// create a proper inset as replacement
- MathExIntInset * p = new MathExIntInset;
+ MathExIntInset * p = new MathExIntInset("int");
// collect scripts
MathArray::iterator st = it + 1;
}
// use the atom behind the 'd' as differential
- MathArray diff;
+ MathArray ind;
if (jt + 1 != ar.end()) {
- diff.push_back(*(jt + 1));
- ar.erase(it + 1, jt + 2);
- } else {
- ar.erase(it + 1, jt + 1);
+ ind.push_back(*(jt + 1));
+ ++jt;
}
- p->differential(diff);
+ ar.erase(it + 1, jt + 1);
+
+ p->index(ind);
(*it).reset(p);
}
lyxerr << "\nIntegrals to: " << ar << "\n";
}
+//
+// search sums
+//
+
+bool sumSymbolTest(MathInset * p)
+{
+ return p->asSymbolInset() && p->asSymbolInset()->name() == "sum";
+}
+
+
+bool equalSign(MathInset * p)
+{
+ return extractString(p) == "=";
+}
+
+
+bool equalSign1(MathAtom const & at)
+{
+ return equalSign(at.nucleus());
+}
+
+
+
+// replace '\sum' ['_^'] f(x) sequences by a real MathExIntInset
+// assume 'extractDelims' ran before
+void extractSums(MathArray & ar)
+{
+ // we need at least two items...
+ if (ar.size() <= 1)
+ return;
+
+ lyxerr << "\nSums from: " << ar << "\n";
+ for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
+ MathArray::iterator it = ar.begin() + i;
+
+ // is this a sum name?
+ if (!sumSymbolTest(it->nucleus()))
+ continue;
+
+ // create a proper inset as replacement
+ MathExIntInset * p = new MathExIntInset("sum");
+
+ // collect scripts
+ MathArray::iterator st = it + 1;
+ if (st != ar.end() && (*st)->asScriptInset()) {
+ p->scripts(*st);
+ ++st;
+
+ // try to figure out the summation index from the subscript
+ MathScriptInset * script = p->scripts()->asScriptInset();
+ if (script->hasDown()) {
+ MathArray & ar = script->down().data_;
+ MathArray::iterator it =
+ std::find_if(ar.begin(), ar.end(), &equalSign1);
+ if (it != ar.end()) {
+ // we found a '=', use everything in front of that as index,
+ // and everything behind as start value
+ p->index(MathArray(ar.begin(), it));
+ ar.erase(ar.begin(), it + 1);
+ } else {
+ // use everything as summation index
+ p->index(ar);
+ p->scripts().reset(0);
+ }
+ }
+ }
+
+ // use the atom behind the script as core
+ MathArray ind;
+ if (st != ar.end()) {
+ MathArray core;
+ core.push_back(*st);
+ p->core(core);
+ ++st;
+ }
+ ar.erase(it + 1, st);
+ (*it).reset(p);
+ }
+ lyxerr << "\nSums to: " << ar << "\n";
+}
+
+
void extractStructure(MathArray & ar)
{
extractMatrices(ar);
extractDelims(ar);
extractFunctions(ar);
extractIntegrals(ar);
+ extractSums(ar);
extractStrings(ar);
}