+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"
math_inset.h \
math_kerninset.C \
math_kerninset.h \
+ math_lefteqninset.C \
+ math_lefteqninset.h \
math_macro.C \
math_macro.h \
math_macroarg.C \
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 << "]";
}
#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"
using std::vector;
+
InsetFormula::InsetFormula()
: par_(MathAtom(new MathMatrixInset))
{}
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();
}
#include "math_defs.h"
#include "math_inset.h"
+#include "LString.h"
class MathInset;
class MathAtom;
#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"
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:
}
+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())
///
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;
{"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},
void MathInset::writeNormal(std::ostream & os) const
{
- os << "[unknown] ";
+ os << "[unknown ";
+ write(os, false);
+ os << "] ";
}
--- /dev/null
+#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;
+}
--- /dev/null
+// -*- 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
#include "debug.h"
#include "support.h" // math_font_available
-MathArray mathed_parse_cell(string const &);
-
MathMacroTable::table_type MathMacroTable::macro_table;
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;
}
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()
}
+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];
}
-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") {
///
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;
} // 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);
}
///
LM_TK_ROOT,
///
+ LM_TK_LEFTEQN,
+ ///
LM_TK_BEGIN,
///
LM_TK_END,
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