]> git.lyx.org Git - features.git/commitdiff
recognize a few "well known functions"
authorAndré Pönitz <poenitz@gmx.net>
Fri, 9 Nov 2001 12:01:10 +0000 (12:01 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 9 Nov 2001 12:01:10 +0000 (12:01 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2993 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formula.C
src/mathed/math_exfuncinset.C
src/mathed/math_exfuncinset.h
src/mathed/math_extern.C
src/mathed/math_inset.h
src/mathed/math_stringinset.h

index 2e808ab513909ef39c1232bb502b167e2aa34d47..2a4d0e054d91efb943d99b219c7412a5736ef46e 100644 (file)
@@ -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,  "*");
                }
index 475932c23bb63d0144adfea38a318227607ef9d8..7882daa993cecbde9a9e483603bb633725ed468d 100644 (file)
@@ -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) << '}';
+}
+
+
index 5144bb6825ec33593df031c5f23caa0eb8646557..d7832cd28dbe9d59571ece8a1c79fdfa1feb6a80 100644 (file)
@@ -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:
        ///
index 7e1f1122bf4b3745671a24c5c98a25a4a9c4d473..908c6f73eda54eb4a4bfbb21ad59f1044f7b85c3 100644 (file)
 #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);
 }
 
 
index 8b611d3efa3563ba7112893f146f9c4a3245c8e3..6c46d2a655b82a439553905957963213f0d27882 100644 (file)
@@ -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
index 79774ff7577a615f5fe1d3ad76877c4b9931ee0b..85c97fc5818948aff3f16b9d8ee798a6d200fce2 100644 (file)
@@ -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