From: André Pönitz Date: Fri, 9 Nov 2001 12:01:10 +0000 (+0000) Subject: recognize a few "well known functions" X-Git-Tag: 1.6.10~20372 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3516a9a2fcaac4aad47039ee244d2c6601803b9f;p=features.git recognize a few "well known functions" git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2993 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 2e808ab513..2a4d0e054d 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -124,7 +124,7 @@ namespace { 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, "*"); } diff --git a/src/mathed/math_exfuncinset.C b/src/mathed/math_exfuncinset.C index 475932c23b..7882daa993 100644 --- a/src/mathed/math_exfuncinset.C +++ b/src/mathed/math_exfuncinset.C @@ -19,9 +19,16 @@ MathInset * MathExFuncInset::clone() const } -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_); } @@ -31,16 +38,15 @@ void MathExFuncInset::normalize(NormalStream & os) const } -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()); } @@ -48,3 +54,11 @@ void MathExFuncInset::octavize(OctaveStream & os) const { os << name_.c_str() << '(' << cell(0) << ')'; } + + +void MathExFuncInset::write(WriteStream & os) const +{ + os << '\\' << name_.c_str() << '{' << cell(0) << '}'; +} + + diff --git a/src/mathed/math_exfuncinset.h b/src/mathed/math_exfuncinset.h index 5144bb6825..d7832cd28d 100644 --- a/src/mathed/math_exfuncinset.h +++ b/src/mathed/math_exfuncinset.h @@ -14,15 +14,20 @@ public: /// 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: /// diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 7e1f1122bf..908c6f73ed 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -15,10 +15,10 @@ #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; } @@ -55,8 +55,9 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end) } -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()) { @@ -71,6 +72,7 @@ void glueChars(MathArray & dat) } } ar.swap(dat); + //lyxerr << "\nStrings to: " << ar << "\n"; } @@ -110,6 +112,7 @@ MathInset * singleItem(MathArray & ar) void extractMatrices(MathArray & ar) { + lyxerr << "\nMatrices from: " << ar << "\n"; for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) { if (!it->nucleus()) continue; @@ -120,39 +123,59 @@ void extractMatrices(MathArray & ar) 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) { @@ -160,6 +183,7 @@ 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; @@ -197,13 +221,14 @@ void extractFunctions(MathArray & ar) // 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); @@ -213,7 +238,7 @@ void extractStructure(MathArray & 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()) { @@ -228,21 +253,10 @@ void write(MathArray const & dat, WriteStream & wi) } -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); } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 8b611d3efa..6c46d2a655 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -48,6 +48,7 @@ class MathHullInset; class MathMatrixInset; class MathNestInset; class MathScriptInset; +class MathStringInset; class MathSpaceInset; class MathMacroTemplate; @@ -170,34 +171,23 @@ public: /// 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 diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h index 79774ff757..85c97fc581 100644 --- a/src/mathed/math_stringinset.h +++ b/src/mathed/math_stringinset.h @@ -22,10 +22,6 @@ public: 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; /// @@ -33,11 +29,20 @@ public: /// 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