]> git.lyx.org Git - features.git/commitdiff
some visual support for \lefteqn
authorAndré Pönitz <poenitz@gmx.net>
Thu, 18 Oct 2001 13:21:21 +0000 (13:21 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 18 Oct 2001 13:21:21 +0000 (13:21 +0000)
fix some writeNormal() issues

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2895 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/array.C
src/mathed/formula.C
src/mathed/math_cursor.h
src/mathed/math_factory.C
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_hash.C
src/mathed/math_inset.C
src/mathed/math_lefteqninset.C [new file with mode: 0644]
src/mathed/math_lefteqninset.h [new file with mode: 0644]
src/mathed/math_macrotable.C
src/mathed/math_matrixinset.C
src/mathed/math_matrixinset.h
src/mathed/math_parser.C
src/mathed/math_parser.h

index 88612d353f5776ce839564d25a9046c2b5b2dd5d..9aef0b27634b6eb504706de28f4f0345cc91aecd 100644 (file)
@@ -1,4 +1,12 @@
 
+2001-10-17  André Pönitz  <poenitz@gmx.net>
+
+       * formula.C:
+       * array.C: add missing/broken  writeNormal()
+
+       * math_lefteqn.[Ch]: some visual support for \lefteqn
+       
+
 2001-10-10  André Pönitz  <poenitz@gmx.net>
 
        * math_cursor.C: introduce dummy "inner" position "between"
index cc3b6915d3f9206077157e3d846ba98d0133350f..15fadc46a06263354691a88e43d50181114beead 100644 (file)
@@ -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 \
index 715350fda60eec914dc0ab26aec15d2fb55b2733..c91d52ed84626a27048c3b5d9d349d68ed60425c 100644 (file)
@@ -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 << "]";
 }
 
 
index 2c1723812a80d2d41b3876bcc3628aa215410da8..6a427b9c4131288b7c6635f37287981e9ee4aa6c 100644 (file)
@@ -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();
 }
 
index 312938026523b1632454353f44c37fc84793f04b..ce9c89cc970261000833ac97303cb28cebd89e36 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "math_defs.h"
 #include "math_inset.h"
+#include "LString.h"
 
 class MathInset;
 class MathAtom;
index 4a6d21c336708dc8f6e0285e203b148b086e0d17..280b48f5d7ccb4c5f081b27c7bd0bfb649c294ff 100644 (file)
@@ -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:
index 9957c17b82982dc2b9f06d1ac23a98f4107a6790..c7edf132a50203b90918ccdd608aeeb30f82c8b7 100644 (file)
@@ -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()) 
index b7fbd2f4d6d2c5ad50bb9f5b56f76d338fe25960..8253ec30663bf7c4fb2b92fdbf552114a4300ae9 100644 (file)
@@ -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;
index 7e8b07f3ba924979b1094f7841b9e3241848c016..80f5dbfe63bf928edcbedf545353ec3879fe6490 100644 (file)
@@ -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},
index 6c757f9ddeb3b5c6e173f308e7c4062e067b4e5e..b4e340b5086c9cee2ede07458ca95a14fdce3924 100644 (file)
@@ -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 (file)
index 0000000..162c2ab
--- /dev/null
@@ -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 (file)
index 0000000..de99a12
--- /dev/null
@@ -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
index 1e6902618a859d42125047ab9d8dc9540ca3fba7..2c0e274368476169d968b5206d976ef69ff879e1 100644 (file)
@@ -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;
 }
 
index bada6e475666015528c9eaf71a8275bff9c72f9d..5e61d8671e24023ddaf973a7d2a7ed2595a6e7d3 100644 (file)
 
 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") {
index b90279af3bb0d9dad950a52b8f609dfe4401105a..32c5fa43e862bbe6ff776771840c5ea95a10470f 100644 (file)
@@ -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;
index ba96a36feb9884b3682612b3e65ce08fa2535bf2..66d455e4b93e55cf2008dfe45cc3aae525764baa 100644 (file)
@@ -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);
 }
 
 
index cf06a946ceeed0beb536a291580cacaf57d8cd82..7acfa475d9388e85d512f34a9315b9507c0ec333 100644 (file)
@@ -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