math_kerninset.h \
math_lefteqninset.C \
math_lefteqninset.h \
+ math_limitopinset.C \
+ math_limitopinset.h \
math_macro.C \
math_macro.h \
math_macroarg.C \
+++ /dev/null
-#include "math_exintinset.h"
-#include "math_support.h"
-#include "debug.h"
-#include "math_mathmlstream.h"
-#include "math_symbolinset.h"
-
-
-MathExIntInset::MathExIntInset(MathScriptInset const & scripts,
- MathArray const & core, MathArray const & diff)
- : int_(new MathSymbolInset("int")),
- scripts_(scripts), core_(core), diff_(diff)
-{}
-
-
-MathInset * MathExIntInset::clone() const
-{
- return new MathExIntInset(*this);
-}
-
-
-void MathExIntInset::write(WriteStream & os) const
-{
- scripts_.write(int_.nucleus(), os);
- os << core_ << "d" << diff_;
-}
-
-
-void MathExIntInset::normalize(NormalStream & os) const
-{
- //os << "[int " << scripts_ << ' ' << core_ << ' ' << diff_ << ']'
-}
-
-
-void MathExIntInset::metrics(MathMetricsInfo const &) const
-{
- lyxerr << "should not happen\n";
-}
-
-
-void MathExIntInset::draw(Painter &, int, int) const
-{
- lyxerr << "should not happen\n";
-}
-
-
-void MathExIntInset::maplize(MapleStream & os) const
-{
- //os << name_.c_str() << '(' << cell(0) << ')';
-}
-
-void MathExIntInset::mathmlize(MathMLStream & os) const
-{
- //os << name_.c_str() << '(' << cell(0) << ')';
-}
+++ /dev/null
-// -*- C++ -*-
-#ifndef MATH_EXINTINSET_H
-#define MATH_EXINTINSET_H
-
-// /\int_l^u f(x) dxin one block (as opposed to 'f','(','x',')' or 'f','x')
-// for interfacing external programs
-
-#include "math_scriptinset.h"
-
-class MathExIntInset : public MathInset {
-public:
- ///
- MathExIntInset(MathScriptInset const &, MathArray const &, MathArray const &);
- ///
- MathInset * clone() const;
- ///
- void metrics(MathMetricsInfo const & st) const;
- ///
- void draw(Painter &, int x, int y) const;
- ///
- void write(WriteStream & os) const;
- ///
- void normalize(NormalStream &) const;
- ///
- void maplize(MapleStream &) const;
- ///
- void mathmlize(MathMLStream &) const;
-private:
- ///
- MathAtom int_;
- ///
- MathScriptInset scripts_;
- ///
- MathArray core_;
- ///
- MathArray diff_;
-};
-#endif
#include "math_mathmlstream.h"
#include "math_scriptinset.h"
#include "math_stringinset.h"
+#include "math_symbolinset.h"
#include "debug.h"
MathCharInset const * p = it->nucleus()->asCharInset();
if (p) {
for (MathTextCodes c = p->code(); it != end; ++it) {
- if (!it->nucleus())
- break;
p = it->nucleus()->asCharInset();
if (!p || p->code() != c)
break;
}
-bool needAsterisk(MathAtom const &, MathAtom const &)
-{
- return false;
-}
-
-
-void guessAsterisks(MathArray & dat)
-{
- if (dat.size() <= 1)
- return;
- MathArray ar;
- ar.push_back(*dat.begin());
- MathArray::const_iterator it = dat.begin();
- MathArray::const_iterator jt = it + 1;
- for (; jt != dat.end(); ++it, ++jt) {
- if (needAsterisk(*it, *jt))
- ar.push_back(MathAtom(new MathCharInset('*')));
- ar.push_back(*it);
- }
- ar.push_back(*dat.end());
- ar.swap(dat);
-}
-
-
MathInset * singleItem(MathArray & ar)
{
- lyxerr << "ar.size: " << ar.size() << "\n";
- //lyxerr << "ar.begin: " << ar.begin() << "\n";
- //lyxerr << "ar.nuc: " << ar.begin()->nucleus() << "\n";
- lyxerr << "ar.nuc: " << *ar.begin()->nucleus() << "\n";
return ar.size() == 1 ? ar.begin()->nucleus() : 0;
}
{
lyxerr << "\nMatrices from: " << ar << "\n";
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
- if (!it->nucleus())
- continue;
- MathDelimInset * del = it->nucleus()->asDelimInset();
+ MathDelimInset * del = (*it)->asDelimInset();
if (!del)
continue;
MathInset * arr = singleItem(del->cell(0));
}
-// replace '('...')' sequences by a real MathDelimInset
-void extractDelims(MathArray & ar) {
+// define a function for tests
+typedef bool TestItemFunc(MathInset *);
+
+// define a function for replacing pa
+typedef MathInset * ReplaceArgumentFunc(const MathArray & ar);
+
+// search end of nested sequence
+MathArray::iterator searchNestedEnd(
+ MathArray::iterator it,
+ MathArray::iterator last,
+ TestItemFunc testOpen,
+ TestItemFunc testClose
+)
+{
+ for (int level = 0; it != last; ++it) {
+ if (testOpen(it->nucleus()))
+ ++level;
+ if (testClose(it->nucleus()))
+ --level;
+ if (level == 0)
+ break;
+ }
+ return it;
+}
+
+
+// replace nested sequences by a real Insets
+void replaceNested(
+ MathArray & ar,
+ TestItemFunc testOpen,
+ TestItemFunc testClose,
+ ReplaceArgumentFunc replaceArg
+)
+{
// use indices rather than iterators for the loop because we are going
// to modify the array.
- lyxerr << "\nDelims from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
+ // check whether this is the begin of the sequence
MathArray::iterator it = ar.begin() + i;
- if (extractString(it->nucleus()) != "(")
+ if (!testOpen(it->nucleus()))
continue;
- // search matching closing paranthesis
- int level = 1;
- MathArray::iterator jt = it + 1;
- for (; jt != ar.end(); ++jt) {
- string s = extractString(jt->nucleus());
- if (s == "(")
- ++level;
- if (s == ")")
- --level;
- if (level == 0)
- break;
- }
+ // search end of sequence
+ MathArray::iterator jt = searchNestedEnd(it, ar.end(), testOpen, testClose);
if (jt == ar.end())
continue;
- // create a proper deliminset
- MathAtom at(new MathDelimInset("(", ")"));
- at->cell(0) = MathArray(it + 1, jt);
+ // create a proper inset as replacement
+ MathInset * p = replaceArg(MathArray(it + 1, jt));
// replace the original stuff by the new inset
ar.erase(it + 1, jt + 1);
- *it = at;
- lyxerr << "\nDelims to: " << ar << "\n";
+ (*it).reset(p);
}
}
+bool testParanOpen(MathInset * p)
+{
+ return extractString(p) == "(";
+}
+
+
+bool testParanClose(MathInset * p)
+{
+ return extractString(p) == ")";
+}
+
+
+MathInset * replaceByDelimInset(const MathArray & ar)
+{
+ MathDelimInset * del = new MathDelimInset("(", ")");
+ del->cell(0) = ar;
+ return del;
+}
+
+
+// replace '('...')' sequences by a real MathDelimInset
+void extractDelims(MathArray & ar) {
+ lyxerr << "\nDelims from: " << ar << "\n";
+ replaceNested(ar, testParanOpen, testParanClose, replaceByDelimInset);
+ lyxerr << "\nDelims to: " << ar << "\n";
+}
+
+
// replace 'f' '(...)' and 'f' '^n' '(...)' sequences by a real MathExFuncInset
// assume 'extractDelims' ran before
void extractFunctions(MathArray & ar)
MathArray::iterator it = ar.begin() + i;
// is this a function name?
- if (!it->nucleus())
- continue;
MathFuncInset * func = (*it)->asFuncInset();
if (!func)
continue;
}
+bool testIntSymbol(MathInset * p)
+{
+ return p->asSymbolInset() && p->asSymbolInset()->name() == "int";
+}
+
+
+bool testSmallD(MathInset * p)
+{
+ string s = extractString(p);
+ return s.size() && s[0] == 'd';
+}
+
+
+// replace '\int' ['_^'] x 'd''x'(...)' sequences by a real MathExIntInset
+// assume 'extractDelims' ran before
+void extractIntegrals(MathArray & ar)
+{
+ // we need at least three items...
+ if (ar.size() <= 2)
+ return;
+
+ lyxerr << "\nIntegrals from: " << ar << "\n";
+ for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
+ MathArray::iterator it = ar.begin() + i;
+
+ // is this a integral name?
+ if (!testIntSymbol(it->nucleus()))
+ continue;
+
+ // search 'd'
+ MathArray::iterator jt =
+ searchNestedEnd(it, ar.end(), testIntSymbol, testSmallD);
+
+ // create a proper inset as replacement
+ //MathInset * p = replaceArg(MathArray(it + 1, jt));
+
+ // replace the original stuff by the new inset
+ //ar.erase(it + 1, jt + 1);
+ //(*it).reset(p);
+ }
+}
+
+
void extractStructure(MathArray & ar)
{
extractStrings(ar);
extractMatrices(ar);
extractDelims(ar);
extractFunctions(ar);
+ extractIntegrals(ar);
}
class MathScriptInset;
class MathStringInset;
class MathSpaceInset;
-class MathMacroTemplate;
+class MathSymbolInset;
class NormalStream;
class OctaveStream;
class LaTeXFeatures;
class BufferView;
class UpdatableInset;
+class MathMacroTemplate;
class MathInset {
virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; }
virtual MathStringInset * asStringInset() { return 0; }
+ virtual MathSymbolInset * asSymbolInset() { return 0; }
virtual UpdatableInset * asHyperActiveInset() const { return 0; }
/// identifies things that can get scripts
--- /dev/null
+#include "math_limitopinset.h"
+#include "math_support.h"
+#include "math_mathmlstream.h"
+#include "math_symbolinset.h"
+#include "debug.h"
+
+
+MathLimitOpInset::MathLimitOpInset(MathScriptInset const & scripts,
+ MathArray const & core)
+ : int_(new MathSymbolInset("int")),
+ scripts_(scripts), core_(core)
+{}
+
+
+MathInset * MathLimitOpInset::clone() const
+{
+ return new MathLimitOpInset(*this);
+}
+
+
+void MathLimitOpInset::write(WriteStream & os) const
+{
+ scripts_.write(int_.nucleus(), os);
+ os << core_ << "d" << diff_;
+}
+
+
+void MathLimitOpInset::normalize(NormalStream & os) const
+{
+ //os << "[int " << scripts_ << ' ' << core_ << ' ' << diff_ << ']'
+}
+
+
+void MathLimitOpInset::metrics(MathMetricsInfo const &) const
+{
+ lyxerr << "should not happen\n";
+}
+
+
+void MathLimitOpInset::draw(Painter &, int, int) const
+{
+ lyxerr << "should not happen\n";
+}
+
+
+void MathLimitOpInset::maplize(MapleStream & os) const
+{
+ //os << name_.c_str() << '(' << cell(0) << ')';
+}
+
+void MathLimitOpInset::mathmlize(MathMLStream & os) const
+{
+ //os << name_.c_str() << '(' << cell(0) << ')';
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_LIMITOPINSET_H
+#define MATH_LIMITOPINSET_H
+
+// /\sum_l^u f(x) in one block
+// for interfacing external programs
+
+#include "math_scriptinset.h"
+
+class MathLimitOpInset : public MathInset {
+public:
+ ///
+ MathLimitOpInset(MathScriptInset const &, MathArray const &);
+ ///
+ MathInset * clone() const;
+ ///
+ void metrics(MathMetricsInfo const & st) const;
+ ///
+ void draw(Painter &, int x, int y) const;
+ ///
+ void write(WriteStream & os) const;
+ ///
+ void normalize(NormalStream &) const;
+ ///
+ void maplize(MapleStream &) const;
+ ///
+ void mathmlize(MathMLStream &) const;
+private:
+ ///
+ MathAtom int_;
+ ///
+ MathScriptInset scripts_;
+ ///
+ MathArray core_;
+ ///
+ MathArray diff_;
+};
+#endif
///
MathInset * clone() const;
///
+ bool isActive() const { return false; }
+ ///
void metrics(MathMetricsInfo const & st) const;
///
void draw(Painter &, int x, int y) const;
///
- void write(WriteStream & os) const;
+ void substitute(MathMacro const & macro);
+
///
void normalize(NormalStream &) const;
///
- void substitute(MathMacro const & macro);
- ///
- bool isActive() const { return false; }
+ void write(WriteStream & os) const;
private:
/// A number between 1 and 9
#include "math_symbolinset.h"
#include "math_parser.h"
#include "math_mathmlstream.h"
-#include "debug.h"
#include "math_support.h"
+#include "debug.h"
MathSymbolInset::MathSymbolInset(const latexkeys * l)
}
-void MathSymbolInset::write(WriteStream & os) const
-{
- os << '\\' << sym_->name.c_str() << ' ';
-}
-
-
-void MathSymbolInset::normalize(NormalStream & os) const
-{
- os << "[symbol " << sym_->name.c_str() << "]";
-}
-
-
MathTextCodes MathSymbolInset::code() const
{
switch(sym_->token) {
}
+string MathSymbolInset::name() const
+{
+ return sym_->name;
+}
+
+
void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
{
mi_ = mi;
mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
}
if (isRelOp())
- width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
+ width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
}
}
+void MathSymbolInset::normalize(NormalStream & os) const
+{
+ os << "[symbol " << name().c_str() << "]";
+}
+
+
void MathSymbolInset::maplize(MapleStream & os) const
{
- if (sym_->name == "cdot")
+ if (name() == "cdot")
os << '*';
else
- os << sym_->name.c_str();
+ os << name().c_str();
}
void MathSymbolInset::mathmlize(MathMLStream & os) const
{
- os << sym_->name.c_str();
+ os << name().c_str();
}
void MathSymbolInset::octavize(OctaveStream & os) const
{
- if (sym_->name == "cdot")
+ if (name() == "cdot")
os << '*';
else
- os << sym_->name.c_str();
+ os << name().c_str();
+}
+
+
+void MathSymbolInset::write(WriteStream & os) const
+{
+ os << '\\' << name().c_str() << ' ';
}
///
MathInset * clone() const;
///
- void write(WriteStream & os) const;
- ///
- void normalize(NormalStream &) const;
- ///
void metrics(MathMetricsInfo const & st) const;
///
void draw(Painter &, int x, int y) const;
bool isScriptable() const;
/// identifies things that can get \limits or \nolimits
bool takesLimits() const;
+ ///
+ MathSymbolInset * asSymbolInset() { return this; }
+ ///
+ void normalize(NormalStream &) const;
///
void maplize(MapleStream &) const;
///
void mathmlize(MathMLStream &) const;
///
void octavize(OctaveStream &) const;
+ ///
+ void write(WriteStream & os) const;
+ ///
+ string name() const;
private:
///
MathTextCodes code() const;