From 35d74b0e6f9dc98d54653cf6fa90f5d0c81eb388 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 18 Oct 2001 13:21:21 +0000 Subject: [PATCH] some visual support for \lefteqn fix some writeNormal() issues git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2895 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 8 +++ src/mathed/Makefile.am | 2 + src/mathed/array.C | 10 ++- src/mathed/formula.C | 28 +++++++- src/mathed/math_cursor.h | 1 + src/mathed/math_factory.C | 3 + src/mathed/math_gridinset.C | 16 +++++ src/mathed/math_gridinset.h | 2 + src/mathed/math_hash.C | 1 + src/mathed/math_inset.C | 4 +- src/mathed/math_lefteqninset.C | 56 +++++++++++++++ src/mathed/math_lefteqninset.h | 28 ++++++++ src/mathed/math_macrotable.C | 4 +- src/mathed/math_matrixinset.C | 120 ++++++++++++++++++--------------- src/mathed/math_matrixinset.h | 2 + src/mathed/math_parser.C | 14 ++-- src/mathed/math_parser.h | 5 ++ 17 files changed, 233 insertions(+), 71 deletions(-) create mode 100644 src/mathed/math_lefteqninset.C create mode 100644 src/mathed/math_lefteqninset.h diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 88612d353f..9aef0b2763 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,4 +1,12 @@ +2001-10-17 André Pönitz + + * formula.C: + * array.C: add missing/broken writeNormal() + + * math_lefteqn.[Ch]: some visual support for \lefteqn + + 2001-10-10 André Pönitz * math_cursor.C: introduce dummy "inner" position "between" diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index cc3b6915d3..15fadc46a0 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -54,6 +54,8 @@ libmathed_la_SOURCES = \ math_inset.h \ math_kerninset.C \ math_kerninset.h \ + math_lefteqninset.C \ + math_lefteqninset.h \ math_macro.C \ math_macro.h \ math_macroarg.C \ diff --git a/src/mathed/array.C b/src/mathed/array.C index 715350fda6..c91d52ed84 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -201,12 +201,10 @@ void MathArray::write(ostream & os, bool fragile) const void MathArray::writeNormal(ostream & os) const { - if (empty()) { - os << "[par] "; - return; - } - - write(os, true); + os << "[par "; + for (const_iterator it = begin(); it != end(); ++it) + (*it)->writeNormal(os); + os << "]"; } diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 2c1723812a..6a427b9c41 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -24,6 +24,7 @@ #include "commandtags.h" #include "math_cursor.h" #include "math_parser.h" +#include "math_charinset.h" #include "lyx_main.h" #include "BufferView.h" #include "gettext.h" @@ -48,6 +49,7 @@ using std::endl; using std::vector; + InsetFormula::InsetFormula() : par_(MathAtom(new MathMatrixInset)) {} @@ -302,17 +304,39 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, void InsetFormula::handleExtern(const string & arg, BufferView *) { + // where are we? + MathArray & ar = mathcursor->cursor().cell(); + + // find position of last '=' in the array for handleExtern + MathArray::size_type pos = ar.size(); + for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) + if ((*it)->getChar() == '=') + pos = it - ar.begin(); + + // delete everything behind this position + ar.erase(pos, ar.size()); + + // create normalized expression //string outfile = lyx::tempName("maple.out"); string outfile = "/tmp/lyx2" + arg + ".out"; ostringstream os; - mat()->writeNormal(os); + ar.writeNormal(os); string code = os.str().c_str(); + + // run external sript string script = "lyx2" + arg + " '" + code + "' " + outfile; lyxerr << "calling: " << script << endl; Systemcalls cmd(Systemcalls::System, script, 0); + // append a '=' + ar.push_back(MathAtom(new MathCharInset('='))); + + // append result ifstream is(outfile.c_str()); - mathed_parse_normal(par_, is); + mathed_parse_cell(ar, is); + mathcursor->end(); + + // re-compute inset dimension metrics(); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 3129380265..ce9c89cc97 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -23,6 +23,7 @@ #include "math_defs.h" #include "math_inset.h" +#include "LString.h" class MathInset; class MathAtom; diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 4a6d21c336..280b48f5d7 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -8,6 +8,7 @@ #include "math_funcliminset.h" #include "math_fracinset.h" #include "math_kerninset.h" +#include "math_lefteqninset.h" #include "math_macro.h" #include "math_macrotable.h" #include "math_macroarg.h" @@ -49,6 +50,8 @@ MathAtom createMathInset(latexkeys const * l) return MathAtom(new MathFracInset(true)); case LM_TK_NOT: return MathAtom(new MathNotInset); + case LM_TK_LEFTEQN: + return MathAtom(new MathLefteqnInset); case LM_TK_SQRT: return MathAtom(new MathSqrtInset); case LM_TK_ROOT: diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 9957c17b82..c7edf132a5 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -276,6 +276,22 @@ void MathGridInset::write(std::ostream & os, bool fragile) const } +void MathGridInset::writeNormal(std::ostream & os) const +{ + os << "[grid "; + for (row_type row = 0; row < nrows(); ++row) { + os << "[row "; + for (col_type col = 0; col < ncols(); ++col) { + os << "[cell "; + cell(index(row, col)).writeNormal(os); + os << "]"; + } + os << "]"; + } + os << "]"; +} + + string MathGridInset::eolString(row_type row) const { if (row + 1 == nrows()) diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index b7fbd2f4d6..8253ec3066 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -66,6 +66,8 @@ public: /// void write(std::ostream &, bool fragile) const; /// + void writeNormal(std::ostream &) const; + /// void metrics(MathStyles st) const; /// void draw(Painter &, int x, int y) const; diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 7e8b07f3ba..80f5dbfe63 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -75,6 +75,7 @@ latexkeys_a wordlist_array[] = {"ker", LM_TK_FUNC, 0}, {"kern", LM_TK_KERN, 0}, {"label", LM_TK_LABEL, 0}, + {"lefteqn", LM_TK_LEFTEQN, 1}, {"ldots", LM_TK_DOTS, 0}, {"left", LM_TK_LEFT, 0}, {"lg", LM_TK_FUNC, 0}, diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 6c757f9dde..b4e340b508 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -215,7 +215,9 @@ void MathInset::userSetSize(MathStyles sz) void MathInset::writeNormal(std::ostream & os) const { - os << "[unknown] "; + os << "[unknown "; + write(os, false); + os << "] "; } diff --git a/src/mathed/math_lefteqninset.C b/src/mathed/math_lefteqninset.C new file mode 100644 index 0000000000..162c2ab88d --- /dev/null +++ b/src/mathed/math_lefteqninset.C @@ -0,0 +1,56 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_lefteqninset.h" +#include "support/LOstream.h" +#include "LColor.h" +#include "Painter.h" +#include "math_cursor.h" + + +MathLefteqnInset::MathLefteqnInset() + : MathNestInset(1) +{} + + +MathInset * MathLefteqnInset::clone() const +{ + return new MathLefteqnInset(*this); +} + + +void MathLefteqnInset::draw(Painter & pain, int x, int y) const +{ + xcell(0).draw(pain, x + 2, y); + if (mathcursor && mathcursor->isInside(this)) { + pain.rectangle(x, y - ascent(), xcell(0).width(), height(), + LColor::mathframe); + } +} + + +void MathLefteqnInset::write(std::ostream & os, bool fragile) const +{ + os << "\\lefteqn{"; + cell(0).write(os, fragile); + os << "}"; +} + + +void MathLefteqnInset::writeNormal(std::ostream & os) const +{ + os << "[lefteqn "; + cell(0).write(os, false); + os << "] "; +} + + +void MathLefteqnInset::metrics(MathStyles st) const +{ + MathNestInset::metrics(st); + size_ = st; + ascent_ = xcell(0).ascent() + 2; + descent_ = xcell(0).descent() + 2; + width_ = 4; +} diff --git a/src/mathed/math_lefteqninset.h b/src/mathed/math_lefteqninset.h new file mode 100644 index 0000000000..de99a1273a --- /dev/null +++ b/src/mathed/math_lefteqninset.h @@ -0,0 +1,28 @@ +// -*- C++ -*- +#ifndef MATH_LEFTEQNINSET_H +#define MATH_LEFTEQNINSET_H + +#include "math_nestinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/// The \kern primitive + +class MathLefteqnInset : public MathNestInset { +public: + /// + MathLefteqnInset(); + /// + MathInset * clone() const; + /// + void draw(Painter &, int x, int y) const; + /// + void write(std::ostream &, bool fragile) const; + /// + void writeNormal(std::ostream &) const; + /// + void metrics(MathStyles st) const; +}; +#endif diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 1e6902618a..2c0e274368 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -13,8 +13,6 @@ #include "debug.h" #include "support.h" // math_font_available -MathArray mathed_parse_cell(string const &); - MathMacroTable::table_type MathMacroTable::macro_table; @@ -49,7 +47,7 @@ MathAtom & MathMacroTable::provide(string const & name) void MathMacroTable::create(string const & name, int na, string const & text) { MathAtom t(new MathMacroTemplate(name, na)); - t->cell(0) = mathed_parse_cell(text); + mathed_parse_cell(t->cell(0), text); macro_table[name] = t; } diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index bada6e4756..5e61d8671e 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -14,40 +14,71 @@ namespace { + int getCols(MathInsetTypes type) + { + switch (type) { + case LM_OT_EQNARRAY: + return 3; + case LM_OT_ALIGN: + case LM_OT_ALIGNAT: + case LM_OT_XALIGNAT: + case LM_OT_XXALIGNAT: + return 2; + default:; + } + return 1; + } -int getCols(MathInsetTypes type) -{ - switch (type) { - case LM_OT_EQNARRAY: - return 3; - case LM_OT_ALIGN: - case LM_OT_ALIGNAT: - case LM_OT_XALIGNAT: - case LM_OT_XXALIGNAT: - return 2; - default:; + + // returns position of first relation operator in the array + // used for "intelligent splitting" + int firstRelOp(MathArray const & ar) + { + for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) + if ((*it)->isRelOp()) + return it - ar.begin(); + return ar.size(); } - return 1; -} -// returns position of first relation operator in the array -// used for "intelligent splitting" -int firstRelOp(MathArray const & array) -{ - for (MathArray::const_iterator it = array.begin(); it != array.end(); ++it) - if ((*it)->isRelOp()) - return it - array.begin(); - return array.size(); -} + char const * star(bool numbered) + { + return numbered ? "" : "*"; + } + MathInsetTypes typecode(string const & s) + { + if (s == "equation") return LM_OT_EQUATION; + if (s == "display") return LM_OT_EQUATION; + if (s == "eqnarray") return LM_OT_EQNARRAY; + if (s == "align") return LM_OT_ALIGN; + if (s == "alignat") return LM_OT_ALIGNAT; + if (s == "xalignat") return LM_OT_XALIGNAT; + if (s == "xxalignat") return LM_OT_XXALIGNAT; + if (s == "multline") return LM_OT_MULTLINE; + if (s == "gather") return LM_OT_GATHER; + return LM_OT_SIMPLE; + } -char const * star(bool numbered) -{ - return numbered ? "" : "*"; -} -} + string normalName(MathInsetTypes t) + { + switch (t) { + case LM_OT_EQUATION: return "equation"; + case LM_OT_EQNARRAY: return "eqnarray"; + case LM_OT_ALIGN: return "align"; + case LM_OT_ALIGNAT: return "alignat"; + case LM_OT_XALIGNAT: return "xalignat"; + case LM_OT_XXALIGNAT: return "xxalignat"; + case LM_OT_MULTLINE: return "multline"; + case LM_OT_GATHER: return "gather"; + case LM_OT_SIMPLE: return "simple"; + default: break; + } + return "unknown"; + } + +} // end anon namespace MathMatrixInset::MathMatrixInset() @@ -180,6 +211,15 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const } +void MathMatrixInset::writeNormal(std::ostream & os) const +{ + os << "[formula " << normalName(getType()) << " "; + MathGridInset::writeNormal(os); + os << "] "; +} + + + string MathMatrixInset::label(row_type row) const { return label_[row]; @@ -434,32 +474,6 @@ string MathMatrixInset::nicelabel(row_type row) const } -namespace { - MathInsetTypes typecode(string const & s) - { - if (s == "equation") - return LM_OT_EQUATION; - if (s == "display") - return LM_OT_EQUATION; - if (s == "eqnarray") - return LM_OT_EQNARRAY; - if (s == "align") - return LM_OT_ALIGN; - if (s == "alignat") - return LM_OT_ALIGN; - if (s == "xalignat") - return LM_OT_XALIGNAT; - if (s == "xxalignat") - return LM_OT_XXALIGNAT; - if (s == "multline") - return LM_OT_MULTLINE; - if (s == "gather") - return LM_OT_GATHER; - return LM_OT_SIMPLE; - } -} - - void MathMatrixInset::mutate(string const & newtype) { if (newtype == "dump") { diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index b90279af3b..32c5fa43e8 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -29,6 +29,8 @@ public: /// void write(std::ostream &, bool fragile) const; /// + void writeNormal(std::ostream &) const; + /// void metrics(MathStyles st) const; /// void draw(Painter &, int x, int y) const; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index ba96a36feb..66d455e4b9 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -954,14 +954,16 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } // anonymous namespace - -MathArray mathed_parse_cell(string const & str) +void mathed_parse_cell(MathArray & ar, string const & str) { istringstream is(str.c_str()); - Parser parser(is); - MathArray ar; - parser.parse_into(ar, 0); - return ar; + mathed_parse_cell(ar, is); +} + + +void mathed_parse_cell(MathArray & ar, istream & is) +{ + Parser(is).parse_into(ar, 0); } diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index cf06a946ce..7acfa475d9 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -52,6 +52,8 @@ enum MathTokenEnum /// LM_TK_ROOT, /// + LM_TK_LEFTEQN, + /// LM_TK_BEGIN, /// LM_TK_END, @@ -143,4 +145,7 @@ string mathed_parse_macro(string const &); string mathed_parse_macro(std::istream &); string mathed_parse_macro(LyXLex &); +void mathed_parse_cell(MathArray & ar, string const & str); +void mathed_parse_cell(MathArray & ar, std::istream & is); + #endif -- 2.39.2