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
This commit is contained in:
André Pönitz 2001-10-18 13:21:21 +00:00
parent a0b0fecd9f
commit 35d74b0e6f
17 changed files with 234 additions and 72 deletions

View 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"

View 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 \

View 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 << "]";
}

View 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();
}

View File

@ -23,6 +23,7 @@
#include "math_defs.h"
#include "math_inset.h"
#include "LString.h"
class MathInset;
class MathAtom;

View 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:

View 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())

View 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;

View 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},

View 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 << "] ";
}

View File

@ -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;
}

View File

@ -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

View 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;
}

View File

@ -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:;
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;
}
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();
}
// 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();
}
char const * star(bool numbered)
{
return numbered ? "" : "*";
}
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;
}
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") {

View 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;

View 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);
}

View 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