]> git.lyx.org Git - features.git/commitdiff
mathed67.diff
authorLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 27 Apr 2001 12:35:55 +0000 (12:35 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 27 Apr 2001 12:35:55 +0000 (12:35 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1968 a592a061-630c-0410-9148-cb99ea01b6c8

20 files changed:
src/mathed/ChangeLog
src/mathed/array.C
src/mathed/array.h
src/mathed/math_accentinset.C
src/mathed/math_bigopinset.C
src/mathed/math_dotsinset.C
src/mathed/math_fracinset.C
src/mathed/math_fracinset.h
src/mathed/math_funcinset.C
src/mathed/math_hash.C
src/mathed/math_macro.C
src/mathed/math_macroarg.C
src/mathed/math_macrotable.C
src/mathed/math_parinset.C
src/mathed/math_parinset.h
src/mathed/math_parser.C
src/mathed/math_root.C
src/mathed/math_spaceinset.C
src/mathed/math_sqrtinset.C
src/mathed/math_xiter.C

index 74906a1cd414952b71da356b22cb93365a03dc43..5989fef9c3a307e709761286e13497a06e032cf1 100644 (file)
@@ -1,7 +1,25 @@
+
+2001-04-27 André Pönitz  <poenitz@htwm.de>
+
+       * math_parser.C: fix \frac handling bug introduced on 04-24
+       * math_xiter.C: hotfix for merging "shared" insets
+
+2001-04-25 André Pönitz  <poenitz@htwm.de>
+
+       * math_*.[Ch]: WriteNormal
+       * formula.C: Support for new "math extern" command
+
 2001-04-25  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * math_macrotable.C: include <iostream>
 
+2001-04-24 André Pönitz  <poenitz@htwm.de>
+
+       * math_macro.[Ch]:
+       * math_macrotable.[Ch]:
+       * math_macroarg.[Ch]: restructuring of macro handling
+       * several files: 
+
 2001-04-25  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * array.h (operator<<):
index 0cec697b09b2cac159cfd75d439c0ba75e19f167..c393574a94bfb6c5b34f55962a6993736d718824 100644 (file)
@@ -96,6 +96,19 @@ void MathedArray::substitute(MathMacro * m)
                                inset = m->arg(n)->Clone();
                        } else {
                                inset->substitute(m);
+/*                             
+                               if (it.IsActive()) {
+                                       MathParInset * pinset = static_cast<MathParInset *>(inset);
+                                       int n = pinset->getMaxArgumentIdx();
+                                       int idx = pinset->getArgumentIdx();
+                                       for (int i = 0; i <= n; ++i) {
+                                               pinset->setArgumentIdx(i);
+                                               pinset->GetData().substitute(m);
+                                       }
+                                       pinset->setArgumentIdx(idx);
+                               }
+*/
+
                                //lyxerr << "substituting in an ordinary inset\n";
                        }
                        raw_pointer_insert(inset, it.getPos() + 1);
@@ -112,6 +125,22 @@ MathedArray & MathedArray::operator=(MathedArray const & array)
        return *this;
 }
 
+void MathedArray::push_back(MathedInset * inset, int t)
+{
+       MathedIter it(this);
+       while (it.Next())
+               ;
+       it.insertInset(inset, t);
+}
+
+void MathedArray::push_back(byte b, MathedTextCodes c)
+{
+       MathedIter it(this);
+       while (it.Next())
+               ;
+       it.insert(b, c);
+}
+
 void MathedArray::clear()
 {
        last_ = 0;
index e0583eba58831d749637a2e77b67baf52c9b59b4..533d5955f508bf2f519d82e538162a39ff221118 100644 (file)
@@ -20,6 +20,7 @@
 #include <iosfwd>
 
 #include "mathed/support.h"
+#include "math_defs.h"
 
 class MathedInset;
 class MathMacro;
@@ -120,6 +121,10 @@ public:
        void deep_copy();
        ///
        void substitute(MathMacro *);
+       ///
+       void push_back(MathedInset * inset, int t);
+       ///
+       void push_back(byte, MathedTextCodes);
 private:
        /// Buffer
        buffer_type bf_;
index 7e7176e3097c511ad1ecd7b04e56c37c825b449b..c05e38b9f46674e6aafdac9976f91ea1260e5c2a 100644 (file)
@@ -115,24 +115,25 @@ void MathAccentInset::Write(ostream & os, bool fragile)
                os << '}';
 }
 
+
 void MathAccentInset::WriteNormal(ostream & os)
 {
        latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
-       os << "{accent " << l->name << " ";
+       os << "[accent " << l->name << " ";
 
        if (inset) {
                inset->WriteNormal(os);
        } else {
                if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) {
-                       os << "{font " << math_font_name[fn - LM_TC_RM] << "}";
+                       os << "[font " << math_font_name[fn - LM_TC_RM] << "]";
                }
                if (MathIsSymbol(fn)) {
                        latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
                        if (l) 
-                               os << "{symbol " << l->name << "}";
+                               os << "[symbol " << l->name << "] ";
                } else
-                       os << "{char " << char(c) << "}";
+                       os << "[char " << char(c) << "] ";
        }
 
-       os << "} ";
+       os << "] ";
 }
index 595b52ac97bdf31e890beaa8dba2ed818a1734fa..f0d6e8cfee6157950e955fcb3a3aa3e3c942400b 100644 (file)
@@ -19,8 +19,7 @@ MathedInset * MathBigopInset::Clone()
 }
 
 
-void
-MathBigopInset::draw(Painter & pain, int x, int y)
+void MathBigopInset::draw(Painter & pain, int x, int y)
 {
        string s;
        short t;
@@ -63,7 +62,7 @@ void MathBigopInset::WriteNormal(ostream & os)
 {
        bool const limp = GetLimits();
        
-       os << "{bigop " << name;
+       os << "[bigop " << name;
        
        if (limp && !(sym_ != LM_int && sym_ != LM_oint
                      && (GetStyle() == LM_ST_DISPLAY)))
@@ -73,7 +72,7 @@ void MathBigopInset::WriteNormal(ostream & os)
                              && (GetStyle() == LM_ST_DISPLAY)))
                        os << " nolimits";
        
-       os << "} ";
+       os << "] ";
 }
 
 void MathBigopInset::Metrics()
index 5f4e846a1812df2cc13b2131ed5300d9f4fb3c20..9d2e777d52148f568989f8b6a59b3409e1b7fea0 100644 (file)
@@ -50,7 +50,8 @@ void MathDotsInset::Write(ostream & os, bool /* fragile */)
        os << '\\' << name << ' ';
 }
 
+
 void MathDotsInset::WriteNormal(ostream & os)
 {
-       os << "{" << name << "} ";
+       os << "[" << name << "] ";
 }
index c9e054849a54d67ada151a6f1d4079ffafcd7d37..9d2fbf28c0a2da594dad1f306babaa8aacc498f3 100644 (file)
@@ -165,6 +165,11 @@ void MathFracInset::Metrics()
        idx_ = idxp;
 }
 
+MathParInset * MathFracInset::denom() 
+{
+       return &den_;
+}
+
 
 void MathFracInset::Write(ostream & os, bool fragile)
 {
@@ -175,11 +180,12 @@ void MathFracInset::Write(ostream & os, bool fragile)
        os << '}';
 }
 
+
 void MathFracInset::WriteNormal(ostream & os)
 {
-       os << '{' << name << ' ';
+       os << '[' << name << ' ';
        MathParInset::WriteNormal(os);
        os << " ";
        den_.WriteNormal(os);
-       os << "} ";
+       os << "] ";
 }
index cfb88694b9b6bad7a8f553117c80c2f37089277a..c26021774424c82316da3d6a82a97d89428fa44e 100644 (file)
@@ -50,6 +50,8 @@ public:
        int getMaxArgumentIdx() const;
        ///
        void  SetStyle(short);
+       ///
+       MathParInset * denom(); 
 private:
        ///
        int idx_;
index 3e06dfc3398dc89d782bb320115a503e3f2614fa..23eee24a038b60b93edb251a4f8d03bb3c994a33 100644 (file)
@@ -47,9 +47,10 @@ void MathFuncInset::Write(std::ostream & os, bool /* fragile */)
        os << "\\" << name << ' ';
 }
 
+
 void MathFuncInset::WriteNormal(std::ostream & os)
 {
-       os << "{" << name << "} ";
+       os << "[" << name << "] ";
 }
 
 
index a570157b8751b035acd4bda546271195da407619..e32c32d1e6f73fa64832a2afd90bc23a673f8eb8 100644 (file)
@@ -1,10 +1,10 @@
-
 #include <config.h>
 
 #include <map>
 
 #include "math_defs.h"
 #include "math_parser.h"
+#include "support/lstrings.h"
 
 namespace {
 
index 519c077b88fa69450c7174ffa95884524a29555f..add8c701c4a8871f2eccd5c11cf0076e6ff3e970 100644 (file)
@@ -287,8 +287,10 @@ void MathMacro::Write(ostream & os, bool fragile)
 
 void MathMacro::WriteNormal(ostream & os)
 {
-       os << "{macro " << name << " ";
-       for (int i = 0; i < nargs(); ++i) 
+       os << "[macro " << name << " ";
+       for (int i = 0; i < nargs(); ++i) {
                arg(i)->WriteNormal(os);
-       os << "} ";
+               os << ' ';
+       }
+       os << "] ";
 }
index 57d0e04c247d1217407945ca25f46557c9b4f198..7a512f7563f1a9ac8a10a1200f5e5505301f94f6 100644 (file)
@@ -67,5 +67,5 @@ void MathMacroArgument::Write(std::ostream & os, bool /*fragile*/)
 
 void MathMacroArgument::WriteNormal(std::ostream & os)
 {
-       os << "{macroarg " << number_ << "} ";
+       os << "[macroarg " << number_ << "] ";
 }
index 8eeb66fe0e2785e7dec807c639fc8ce985827408..e4a41c05ccf882adcd635b40abfd3c429b80df58 100644 (file)
@@ -9,7 +9,6 @@
 #include "math_macrotable.h"
 #include "math_macro.h"
 #include "math_macrotemplate.h"
-#include "math_iter.h"
 #include "array.h"
 #include "math_accentinset.h"
 #include "math_deliminset.h"
@@ -85,9 +84,7 @@ void MathMacroTable::builtinMacros()
        // This macro doesn't have arguments
        {
                MathMacroTemplate & m = provideTemplate("notin", 0);
-               MathedIter iter(&m.GetData());
-               iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
-                                LM_TC_INSET);
+               m.push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), LM_TC_INSET);
        }
 
        // This macro doesn't have arguments
@@ -99,18 +96,14 @@ void MathMacroTable::builtinMacros()
        mathed_parse(m.array, p, 0);
        }
 
-       // These two are only while we are still with LyX 2.x
        {
                MathMacroTemplate & m = provideTemplate("emptyset", 0);
-               MathedIter iter(&m.GetData());
-               iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
-                                LM_TC_INSET);
+               m.push_back(new MathAccentInset('0', LM_TC_RM, LM_not), LM_TC_INSET);
        }
 
        {
                MathMacroTemplate & m = provideTemplate("perp", 0);
-               MathedIter iter(&m.GetData());
-               iter.insert(LM_bot, LM_TC_BOP);
+               m.GetData().push_back(LM_bot, LM_TC_BOP);
        }
 
        {
@@ -121,70 +114,16 @@ void MathMacroTable::builtinMacros()
        mathed_parse(m.array, p, 0);
        }
 
-       {
-               MathMacroTemplate & m = provideTemplate("binom", 2);
-               istringstream is("\\choose{#1}{#2}");
-               mathed_parser_file(is, 0);
-               MathParInset * p = &m;
-       mathed_parse(m.array, p, 0);
-       }
-
        // binom has two arguments
        {
-               MathMacroTemplate & m = provideTemplate("binom1", 2);
-               MathedIter iter(&m.GetData());
-
-               MathParInset * inset = new MathDelimInset('(', ')');
-               iter.insertInset(inset, LM_TC_ACTIVE_INSET);
-
-               MathedArray array2;
-               MathedIter iter2(&array2);
                MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
-               iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
-               frac->setData(array2);
-
-               MathedArray array3;
-               MathedIter iter3(&array3);
-               iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
+               frac->push_back(new MathMacroArgument(1), LM_TC_INSET);
+               frac->denom()->push_back(new MathMacroArgument(2), LM_TC_INSET);
 
-               MathedArray array4;
-               MathedIter iter4(&array4);
-               iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
-
-               frac->SetData(array3, array4);
-       }
-
-/*    
-       {
-               boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
-               addTemplate(m);
-               MathedArray array;
-               MathedIter iter(&array);
-               iter.insert(LM_bot, LM_TC_BOP);
-               m->setData(array);
-       }
-
-       // binom has two arguments
-       {
-               boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
-               addTemplate(m);
-               MathedArray array;
-               m->setData(array);
-               MathedIter iter(&array);
                MathParInset * inset = new MathDelimInset('(', ')');
-               iter.insertInset(inset, LM_TC_ACTIVE_INSET);
-               array = MathedArray();
-               MathedIter iter2(&array);
-               MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
-               iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
-               inset->setData(array);
-               array = MathedArray();
-               MathedArray array2;
-               MathedIter iter3(&array);
-               iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
-               MathedIter iter4(&array2);
-               iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
-               frac->SetData(array, array2);
+               inset->push_back(frac, LM_TC_ACTIVE_INSET);
+
+               MathMacroTemplate & m = provideTemplate("binom", 2);
+               m.push_back(inset, LM_TC_ACTIVE_INSET);
        }
-*/
 }
index 3f93d81e495cfbaa3ae7e8a8c8045430f3cf2b0a..d51ffee57abe0dc79a5831a6fc88082387993299 100644 (file)
@@ -411,11 +411,11 @@ void MathParInset::Write(ostream & os, bool fragile)
 void MathParInset::WriteNormal(ostream & os)
 {
        if (array.empty()) {
-               os << "{}";
+               os << "[par] ";
                return;
        }
 
-       os << "{par ";
+       os << "[par ";
 
        int brace = 0;
        latexkeys const * l;
@@ -435,7 +435,7 @@ void MathParInset::WriteNormal(ostream & os)
                        string str = data.GetString();
                        
                        if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
-                               os << "{font " << math_font_name[data.fcode()-LM_TC_RM] << '{';
+                               os << "[font " << math_font_name[data.fcode()-LM_TC_RM] << " [";
                        }
                        for (string::const_iterator s = str.begin();
                             s != str.end(); ++s) {
@@ -444,7 +444,7 @@ void MathParInset::WriteNormal(ostream & os)
                                        l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
                                                             LM_TK_BIGSYM : LM_TK_SYM);
                                        if (l) {
-                                               os << '{' << l->name << '}';
+                                               os << " [" << l->name << "] ";
                                        } else {
 #ifdef WITH_WARNINGS
 #warning this does not compile on gcc 2.97
@@ -456,7 +456,7 @@ void MathParInset::WriteNormal(ostream & os)
                                        // Is there a standard logical XOR?
                                        if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
                                            (data.fcode() == LM_TC_SPECIAL))
-                                               os << '{';
+                                               os << "[";
                                        else {
                                                if (c == '{')
                                                        ++brace;
@@ -471,29 +471,29 @@ void MathParInset::WriteNormal(ostream & os)
                                }
                        }
                        if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
-                               os << "} ";
+                               os << "] ";
                } else {
                        if (MathIsInset(cx)) {
                                MathedInset * p = data.GetInset();
                                if (cx == LM_TC_UP)
-                                       os << "{superscript ";
+                                       os << "[superscript ";
                                if (cx == LM_TC_DOWN)
-                                       os << "{subscript ";
+                                       os << "[subscript ";
                                p->WriteNormal(os);
                                if (cx == LM_TC_UP || cx == LM_TC_DOWN)
-                                       os << "} ";
+                                       os << "] ";
                                data.Next();
                        } else {
                                switch (cx) {
                                case LM_TC_TAB:
                                {
-                                       os << "} {";
+                                       os << "] [";
                                        data.Next();
                                        break;
                                }
                                case LM_TC_CR:
                                {
-                                       os << "}} ";
+                                       os << "] ] ";
                                        data.Next();
                                        break;
                                }
@@ -508,7 +508,7 @@ void MathParInset::WriteNormal(ostream & os)
        if (brace > 0)
                os << string(brace, '}');
 
-       os << "} ";
+       os << "] ";
 }
 
 
@@ -563,6 +563,11 @@ MathedArray & MathParInset::GetData()
        return array;
 }
 
+void MathParInset::push_back(MathedInset * inset, int t)
+{
+       array.push_back(inset, t);
+}
+
 
 MathedArray const & MathParInset::GetData() const
 {
index 50ccc71b86e17a4f6dc56f59137cac88402a50a6..27bc85210313d7e1d127c30e9c6b1020430bf2fe 100644 (file)
@@ -42,6 +42,8 @@ public:
        virtual MathedArray & GetData();
        ///
        virtual MathedArray const & GetData() const;
+       ///
+       //virtual MathedArray & GetData(int i);
        /// Paragraph position
        virtual void GetXY(int &, int &) const;
        ///
@@ -82,6 +84,8 @@ public:
        void clear();
        ///
        string label() const;
+       ///
+       void push_back(MathedInset *, int);
 //protected:
        /// Paragraph data is stored here
        MathedArray array;
index d21f0377e220c5030ae1627622d8946dffe5e479..da195e5fc4d310b0c77f440fb0dbe56a49e18359 100644 (file)
@@ -141,7 +141,6 @@ istream * yyis;
 bool yy_mtextmode= false;
 
 
-inline
 void mathPrintError(string const & msg) 
 {
        lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
@@ -346,7 +345,6 @@ int yylex(void)
 }
 
 
-inline
 int parse_align(char * hor, char *)
 {
        int nc = 0;
@@ -359,7 +357,6 @@ int parse_align(char * hor, char *)
 int accent = 0;
 int nestaccent[8];
 
-inline
 void setAccent(int ac)
 {
        if (ac > 0 && accent < 8)
@@ -409,6 +406,18 @@ void do_insert(MathedIter & it, MathedInset * m, MathedTextCodes t)
                it.insertInset(m, t);
 }
 
+
+void handle_frac(MathedIter & it, MathParInset * & par, MathedInsetTypes t) 
+{
+       MathFracInset fc(t);
+       MathedArray num;
+       mathed_parse(num, par, FLAG_BRACE|FLAG_BRACE_LAST);
+       MathedArray den;
+       mathed_parse(den, par, FLAG_BRACE|FLAG_BRACE_LAST);
+       fc.SetData(num, den);
+       it.insertInset(fc.Clone(), LM_TC_ACTIVE_INSET);
+}
+
 } // namespace anon
 
 
@@ -675,19 +684,17 @@ void mathed_parse(MathedArray & array, MathParInset * & par, unsigned flags)
                }
                
                case LM_TK_CHOOSE:
+                       handle_frac(data, par, LM_OT_ATOP);     
+                       break;
+
                case LM_TK_STACK:
+                       handle_frac(data, par, LM_OT_STACKREL); 
+                       break;
+
                case LM_TK_FRAC:
-               {
-                       MathFracInset fc(t);
-                       MathedArray num;
-                       mathed_parse(num, par, FLAG_BRACE|FLAG_BRACE_LAST);
-                       MathedArray den;
-                       mathed_parse(den, par, FLAG_BRACE|FLAG_BRACE_LAST);
-                       fc.SetData(num, den);
-                       data.insertInset(fc.Clone(), LM_TC_ACTIVE_INSET);
+                       handle_frac(data, par, LM_OT_FRAC);     
                        break;
-               }
-               
+
                case LM_TK_SQRT:
                {           
                        char c;
index 938c375268570f93314b18fc59a9aed907d3f885..b8d763dce0ae75bdfcfaadff185cf57e2827aaf7 100644 (file)
@@ -154,11 +154,12 @@ void MathRootInset::Write(ostream & os, bool fragile)
        os << '}';
 }
 
+
 void MathRootInset::WriteNormal(ostream & os)
 {
-       os << "{root ";
+       os << "[root ";
        uroot_.WriteNormal(os);  
        os << " ";
        MathParInset::WriteNormal(os);
-       os << "} ";
+       os << "] ";
 }
index 90652b45a4616f1342abeb547b7a92151e3fc05e..ce715e133a0d03ffd8d2258cab5224a82caae112 100644 (file)
@@ -52,7 +52,7 @@ void MathSpaceInset::Write(ostream & os, bool /* fragile */)
 
 void MathSpaceInset::WriteNormal(ostream & os)
 {
-       os << "{space " << space_ << "} ";
+       os << "[space " << space_ << "] ";
 }
 
 
index 9d9d714741d7c33619f24430caad9d1e4d0fb660..25aa2e12ee50e06de6279b89bc0e20960999baee 100644 (file)
@@ -51,9 +51,9 @@ void MathSqrtInset::Write(ostream & os, bool fragile)
 
 void MathSqrtInset::WriteNormal(ostream & os)
 {
-       os << "{sqrt ";
+       os << "[sqrt ";
        MathParInset::WriteNormal(os); 
-       os << "} ";
+       os << "] ";
 }
 
 
index e349c4c5e28de388ac55467c10b2842b63b78065..100fbbb3abfbd6c949d809818d9e20f89710db6e 100644 (file)
@@ -137,8 +137,13 @@ void MathedXIter::Clean(int pos2)
 }
 
 
-void MathedXIter::Merge(MathedArray const & a)
+void MathedXIter::Merge(MathedArray const & arr)
 {
+#ifdef WITH_WARNINGS
+#warning quick and really dirty: make sure that we really own our inset
+#endif
+       MathedArray a = arr;
+
 #if 0
        array->insert(array->begin() + pos,
                      a.begin(), a.end());