From b9d25422e0e54b298a6706918e03765c10bd4c7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Fri, 27 Apr 2001 12:35:55 +0000 Subject: [PATCH] mathed67.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1968 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 18 ++++++++ src/mathed/array.C | 29 +++++++++++++ src/mathed/array.h | 5 +++ src/mathed/math_accentinset.C | 11 ++--- src/mathed/math_bigopinset.C | 7 ++-- src/mathed/math_dotsinset.C | 3 +- src/mathed/math_fracinset.C | 10 ++++- src/mathed/math_fracinset.h | 2 + src/mathed/math_funcinset.C | 3 +- src/mathed/math_hash.C | 2 +- src/mathed/math_macro.C | 8 ++-- src/mathed/math_macroarg.C | 2 +- src/mathed/math_macrotable.C | 79 ++++------------------------------- src/mathed/math_parinset.C | 29 +++++++------ src/mathed/math_parinset.h | 4 ++ src/mathed/math_parser.C | 33 +++++++++------ src/mathed/math_root.C | 5 ++- src/mathed/math_spaceinset.C | 2 +- src/mathed/math_sqrtinset.C | 4 +- src/mathed/math_xiter.C | 7 +++- 20 files changed, 144 insertions(+), 119 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 74906a1cd4..5989fef9c3 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,7 +1,25 @@ + +2001-04-27 André Pönitz + + * 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 + + * math_*.[Ch]: WriteNormal + * formula.C: Support for new "math extern" command + 2001-04-25 Lars Gullik Bjønnes * math_macrotable.C: include +2001-04-24 André Pönitz + + * math_macro.[Ch]: + * math_macrotable.[Ch]: + * math_macroarg.[Ch]: restructuring of macro handling + * several files: + 2001-04-25 Angus Leeming * array.h (operator<<): diff --git a/src/mathed/array.C b/src/mathed/array.C index 0cec697b09..c393574a94 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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(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; diff --git a/src/mathed/array.h b/src/mathed/array.h index e0583eba58..533d5955f5 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -20,6 +20,7 @@ #include #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_; diff --git a/src/mathed/math_accentinset.C b/src/mathed/math_accentinset.C index 7e7176e309..c05e38b9f4 100644 --- a/src/mathed/math_accentinset.C +++ b/src/mathed/math_accentinset.C @@ -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 << "] "; } diff --git a/src/mathed/math_bigopinset.C b/src/mathed/math_bigopinset.C index 595b52ac97..f0d6e8cfee 100644 --- a/src/mathed/math_bigopinset.C +++ b/src/mathed/math_bigopinset.C @@ -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() diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 5f4e846a18..9d2e777d52 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -50,7 +50,8 @@ void MathDotsInset::Write(ostream & os, bool /* fragile */) os << '\\' << name << ' '; } + void MathDotsInset::WriteNormal(ostream & os) { - os << "{" << name << "} "; + os << "[" << name << "] "; } diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index c9e054849a..9d2fbf28c0 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -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 << "] "; } diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index cfb88694b9..c260217744 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -50,6 +50,8 @@ public: int getMaxArgumentIdx() const; /// void SetStyle(short); + /// + MathParInset * denom(); private: /// int idx_; diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index 3e06dfc339..23eee24a03 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -47,9 +47,10 @@ void MathFuncInset::Write(std::ostream & os, bool /* fragile */) os << "\\" << name << ' '; } + void MathFuncInset::WriteNormal(std::ostream & os) { - os << "{" << name << "} "; + os << "[" << name << "] "; } diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index a570157b87..e32c32d1e6 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -1,10 +1,10 @@ - #include #include #include "math_defs.h" #include "math_parser.h" +#include "support/lstrings.h" namespace { diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 519c077b88..add8c701c4 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -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 << "] "; } diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index 57d0e04c24..7a512f7563 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -67,5 +67,5 @@ void MathMacroArgument::Write(std::ostream & os, bool /*fragile*/) void MathMacroArgument::WriteNormal(std::ostream & os) { - os << "{macroarg " << number_ << "} "; + os << "[macroarg " << number_ << "] "; } diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 8eeb66fe0e..e4a41c05cc 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -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 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 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); } -*/ } diff --git a/src/mathed/math_parinset.C b/src/mathed/math_parinset.C index 3f93d81e49..d51ffee57a 100644 --- a/src/mathed/math_parinset.C +++ b/src/mathed/math_parinset.C @@ -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 { diff --git a/src/mathed/math_parinset.h b/src/mathed/math_parinset.h index 50ccc71b86..27bc852103 100644 --- a/src/mathed/math_parinset.h +++ b/src/mathed/math_parinset.h @@ -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; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index d21f0377e2..da195e5fc4 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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; diff --git a/src/mathed/math_root.C b/src/mathed/math_root.C index 938c375268..b8d763dce0 100644 --- a/src/mathed/math_root.C +++ b/src/mathed/math_root.C @@ -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 << "] "; } diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 90652b45a4..ce715e133a 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -52,7 +52,7 @@ void MathSpaceInset::Write(ostream & os, bool /* fragile */) void MathSpaceInset::WriteNormal(ostream & os) { - os << "{space " << space_ << "} "; + os << "[space " << space_ << "] "; } diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 9d9d714741..25aa2e12ee 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -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 << "] "; } diff --git a/src/mathed/math_xiter.C b/src/mathed/math_xiter.C index e349c4c5e2..100fbbb3ab 100644 --- a/src/mathed/math_xiter.C +++ b/src/mathed/math_xiter.C @@ -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()); -- 2.39.2