if (pos == string::npos || pos < 15)
break; // caret position not found
pos -= 15; // skip the "on line ..." part
- if (expr[pos] == '*')
+ if (expr[pos] == '*' || (pos > 0 && expr[pos - 1] == '*'))
break; // two '*' in a row are definitely bad
expr.insert(pos, "*");
}
}
-void MathExFuncInset::write(WriteStream & os) const
+void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
{
- os << '\\' << name_.c_str() << '{' << cell(0) << '}';
+ mi_ = mi;
+ mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
+}
+
+
+void MathExFuncInset::draw(Painter & pain, int x, int y) const
+{
+ drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
}
}
-void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
+void MathExFuncInset::maplize(MapleStream & os) const
{
- mi_ = mi;
- mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
+ os << name_.c_str() << '(' << cell(0) << ')';
}
-void MathExFuncInset::draw(Painter & pain, int x, int y) const
-{
- drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
+void MathExFuncInset::mathmlize(MathMLStream & os) const
+{
+ os << MTag(name_.c_str()) << cell(0) << ETag(name_.c_str());
}
{
os << name_.c_str() << '(' << cell(0) << ')';
}
+
+
+void MathExFuncInset::write(WriteStream & os) const
+{
+ os << '\\' << name_.c_str() << '{' << cell(0) << '}';
+}
+
+
///
MathInset * clone() const;
///
- void write(WriteStream & os) const;
+ void metrics(MathMetricsInfo const & st) const;
+ ///
+ void draw(Painter &, int x, int y) const;
+
///
void normalize(NormalStream &) const;
///
- void metrics(MathMetricsInfo const & st) const;
+ void maplize(MapleStream &) const;
///
- void draw(Painter &, int x, int y) const;
+ void mathmlize(MathMLStream &) const;
///
void octavize(OctaveStream &) const;
+ ///
+ void write(WriteStream & os) const;
private:
///
#include "debug.h"
-std::ostream & operator<<(ostream & os, MathArray const & ar)
+std::ostream & operator<<(std::ostream & os, MathArray const & ar)
{
- NormalStream ws(os);
- ws << ar;
+ NormalStream ns(os);
+ ns << ar;
return os;
}
}
-void glueChars(MathArray & dat)
+void extractStrings(MathArray & dat)
{
+ //lyxerr << "\nStrings from: " << ar << "\n";
MathArray ar;
MathArray::const_iterator it = dat.begin();
while (it != dat.end()) {
}
}
ar.swap(dat);
+ //lyxerr << "\nStrings to: " << ar << "\n";
}
void extractMatrices(MathArray & ar)
{
+ lyxerr << "\nMatrices from: " << ar << "\n";
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
if (!it->nucleus())
continue;
if (!arr || !arr->asArrayInset())
continue;
*it = MathAtom(new MathMatrixInset(*(arr->asArrayInset())));
+ lyxerr << "\nMatrices to: " << ar << "\n";
}
}
+// convert this inset somehow to a string
+string extractString(MathInset * p)
+{
+ if (p && p->getChar())
+ return string(1, p->getChar());
+ if (p && p->asStringInset())
+ return p->asStringInset()->str();
+ return string();
+}
+
+// replace '('...')' sequences by a real MathDelimInset
void extractDelims(MathArray & ar) {
// 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) {
MathArray::iterator it = ar.begin() + i;
- if (!it->nucleus())
- continue;
- if ((*it)->getChar() != '(')
+ if (extractString(it->nucleus()) != "(")
continue;
- // search last closing paranthesis
- MathArray::iterator et = ar.end();
- for (MathArray::iterator jt = it + 1; jt != ar.end(); ++jt)
- if ((*jt)->getChar() == ')')
- et = jt;
- if (et == ar.end())
+ // 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;
+ }
+ if (jt == ar.end())
continue;
// create a proper deliminset
MathAtom at(new MathDelimInset("(", ")"));
- at->cell(0) = MathArray(it + 1, et);
+ at->cell(0) = MathArray(it + 1, jt);
// replace the original stuff by the new inset
- ar.erase(it + 1, et + 1);
+ ar.erase(it + 1, jt + 1);
*it = at;
+ lyxerr << "\nDelims to: " << ar << "\n";
}
}
+// replace 'f' '(...)' and 'f' '^n' '(...)' sequences by a real MathExFuncInset
// assume 'extractDelims' ran before
void extractFunctions(MathArray & ar)
{
if (ar.size() <= 1)
return;
+ lyxerr << "\nFunctions from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
MathArray::iterator it = ar.begin() + i;
// remove the source of the argument from the array
ar.erase(jt);
+ lyxerr << "\nFunctions to: " << ar << "\n";
}
}
void extractStructure(MathArray & ar)
{
- glueChars(ar);
+ extractStrings(ar);
extractMatrices(ar);
extractDelims(ar);
extractFunctions(ar);
void write(MathArray const & dat, WriteStream & wi)
{
MathArray ar = dat;
- glueChars(ar);
+ extractStrings(ar);
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
MathInset const * p = it->nucleus();
if (it + 1 != ar.end()) {
}
-void normalize(MathArray const & dat, NormalStream & os)
+void normalize(MathArray const & ar, NormalStream & os)
{
- MathArray ar = dat;
- glueChars(ar);
- for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
- MathInset const * p = it->nucleus();
- if (it + 1 != ar.end()) {
- if (MathScriptInset const * q = asScript(it)) {
- q->normalize(p, os);
- ++it;
- continue;
- }
- }
- p->normalize(os);
- }
+ for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
+ (*it)->normalize(os);
}
class MathMatrixInset;
class MathNestInset;
class MathScriptInset;
+class MathStringInset;
class MathSpaceInset;
class MathMacroTemplate;
///
virtual bool covers(int x, int y) const;
- /// identifies NestInsets
- virtual MathNestInset * asNestInset() { return 0; }
- /// identifies CharInsets
- virtual MathCharInset const * asCharInset() const { return 0; }
- /// identifies ScriptInsets
- virtual MathScriptInset * asScriptInset() { return 0; }
- virtual MathScriptInset const * asScriptInset() const { return 0; }
- /// identifies HullInsets
- virtual MathHullInset * asHullInset() { return 0; }
- virtual MathHullInset const * asHullInset() const { return 0; }
- /// identifies SpaceInset
- virtual MathSpaceInset * asSpaceInset() { return 0; }
- /// identifies GridInset
- virtual MathGridInset * asGridInset() { return 0; }
- /// identifies ArrayInsets
+ /// identifies certain types of insets
virtual MathArrayInset * asArrayInset() { return 0; }
- /// identifies MatrixInsets
- virtual MathMatrixInset const * asMatrixInset() const { return 0; }
- /// identifies BoxInsets
virtual MathBoxInset * asBoxInset() { return 0; }
- /// identifies DelimInsets
+ virtual MathCharInset const * asCharInset() const { return 0; }
virtual MathDelimInset * asDelimInset() { return 0; }
virtual MathDelimInset const * asDelimInset() const { return 0; }
- /// identifies FuncInsets
virtual MathFuncInset * asFuncInset() { return 0; }
- /// identifies macro templates
+ virtual MathGridInset * asGridInset() { return 0; }
+ virtual MathHullInset * asHullInset() { return 0; }
+ virtual MathHullInset const * asHullInset() const { return 0; }
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
- /// identifies hyperactive insets
+ virtual MathMatrixInset const * asMatrixInset() const { return 0; }
+ virtual MathNestInset * asNestInset() { return 0; }
+ virtual MathScriptInset * asScriptInset() { return 0; }
+ virtual MathScriptInset const * asScriptInset() const { return 0; }
+ virtual MathSpaceInset * asSpaceInset() { return 0; }
+ virtual MathStringInset * asStringInset() { return 0; }
virtual UpdatableInset * asHyperActiveInset() const { return 0; }
/// identifies things that can get scripts
void metrics(MathMetricsInfo const & st) const;
///
void draw(Painter &, int x, int y) const;
- ///
- void write(WriteStream & os) const;
- ///
- void normalize(NormalStream &) const;
///
int ascent() const;
///
///
int width() const;
///
+ string str() const { return str_; }
+ ///
+ MathStringInset * asStringInset() { return this; }
+
+ ///
+ void normalize(NormalStream &) const;
+ ///
void octavize(OctaveStream &) const;
///
void maplize(MapleStream &) const;
///
void mathmlize(MathMLStream &) const;
+ ///
+ void write(WriteStream & os) const;
private:
/// the string