----------------------------------------------------------------------
+"R. Lahaye" <lahaye@users.sourceforge.net>
+- Mathematical \frac with subscripts, for example:
+ \begin_inset Formula $\frac{\alpha _{1} }{\beta _{2} }$
+ is wrongly displayed
Dekel:
Angus:
- make math lables editable
+
+Tuukka:
+
+- An inline equation does not get a number, so putting a label there is not
+ overly sensible...
+ Ok. In that case show a message in the bottom similarly as the message
+ "you cannot type two spaces this way". Eg. "You can insert math labels
+ only in display mode"
+
* math_matrixinset.C: fix mis-alignment of eqnarray columns
+ * formula*.[Ch]: seperation of the "pimpl" MathInset * into
+ MathMatrixInset * and MathMacroTemplate * to save a few casts
+
2001-07-25 André Pönitz <poenitz@gmx.net>
* formulabase.C: re-enable 'space enlargement' feature
InsetFormula::InsetFormula()
- : InsetFormulaBase(new MathMatrixInset)
+ : par_(new MathMatrixInset)
{}
InsetFormula::InsetFormula(MathInsetTypes t)
- : InsetFormulaBase(new MathMatrixInset(t))
+ : par_(new MathMatrixInset(t))
{}
-InsetFormula::InsetFormula(string const & s)
- : InsetFormulaBase(mathed_parse(s))
+InsetFormula::InsetFormula(string const & s)
+ : par_(mathed_parse_normal(s))
{
metrics();
}
+InsetFormula::~InsetFormula()
+{
+ delete par_;
+}
+
+
Inset * InsetFormula::clone(Buffer const &, bool) const
{
return new InsetFormula(*this);
int InsetFormula::latex(ostream & os, bool fragile, bool) const
{
- par()->write(os, fragile);
+ par_->write(os, fragile);
return 1;
}
int InsetFormula::ascii(ostream & os, int) const
{
- par()->write(os, false);
+ par_->write(os, false);
return 1;
}
void InsetFormula::read(LyXLex & lex)
{
- par(mathed_parse(lex));
+ par(mathed_parse_normal(lex));
metrics();
}
Painter & pain = bv->painter();
metrics();
- int w = par()->width();
- int h = par()->height();
- int a = par()->ascent();
+ int w = par_->width();
+ int h = par_->height();
+ int a = par_->ascent();
pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
if (mathcursor && mathcursor->formula() == this) {
pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
- par()->draw(pain, x, y);
- xx += par()->width();
+ par_->draw(pain, x, y);
+ xx += par_->width();
setCursorVisible(false);
}
void InsetFormula::metrics() const
{
- const_cast<MathInset *>(par_)->metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+ const_cast<MathMatrixInset *>(par_)
+ -> metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
}
vector<string> const InsetFormula::getLabelList() const
{
- return par()->getLabelList();
+ return par_->getLabelList();
}
//lyxerr << "toggling all numbers\n";
if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
- bool old = par()->numberedType();
- for (int row = 0; row < par()->nrows(); ++row)
- par()->numbered(row, !old);
+ bool old = par_->numberedType();
+ for (int row = 0; row < par_->nrows(); ++row)
+ par_->numbered(row, !old);
bv->owner()->message(old ? _("No number") : _("Number"));
updateLocal(bv, true);
}
if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
int row = mathcursor->row();
- bool old = par()->numbered(row);
+ bool old = par_->numbered(row);
bv->owner()->message(old ? _("No number") : _("Number"));
- par()->numbered(row, !old);
+ par_->numbered(row, !old);
updateLocal(bv, true);
}
break;
bv->lockedInsetStoreUndo(Undo::INSERT);
int row = mathcursor->row();
- string old_label = par()->label(row);
+ string old_label = par_->label(row);
string new_label = arg;
if (new_label.empty()) {
if (!new_label.empty()) {
lyxerr << "setting label to '" << new_label << "'\n";
- par()->numbered(row, true);
+ par_->numbered(row, true);
}
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw();
- par()->label(row, new_label);
+ par_->label(row, new_label);
updateLocal(bv, true);
break;
int x;
int y;
mathcursor->getPos(x, y);
- par()->mutate(arg);
+ par_->mutate(arg);
mathcursor->setPos(x, y);
mathcursor->normalize();
updateLocal(bv, true);
int x;
int y;
mathcursor->getPos(x, y);
- if (par()->getType() == LM_OT_SIMPLE)
- par()->mutate(LM_OT_EQUATION);
+ if (par_->getType() == LM_OT_SIMPLE)
+ par_->mutate(LM_OT_EQUATION);
else
- par()->mutate(LM_OT_SIMPLE);
+ par_->mutate(LM_OT_SIMPLE);
mathcursor->setPos(x, y);
mathcursor->normalize();
updateLocal(bv, true);
{
string const clip = bv->getClipboard();
if (!clip.empty())
- par(mathed_parse(clip));
+ par(mathed_parse_normal(clip));
break;
}
//string outfile = lyx::tempName("maple.out");
string outfile = "/tmp/lyx2" + arg + ".out";
ostringstream os;
- par()->writeNormal(os);
+ par_->writeNormal(os);
string code = os.str().c_str();
string script = "lyx2" + arg + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
ifstream is(outfile.c_str());
- par(mathed_parse(is));
+ par(mathed_parse_normal(is));
metrics();
}
bool InsetFormula::display() const
{
- return par()->getType() != LM_OT_SIMPLE;
+ return par_->getType() != LM_OT_SIMPLE;
}
-MathMatrixInset * InsetFormula::par() const
+MathInset * InsetFormula::par() const
{
- return static_cast<MathMatrixInset *>(par_);
+ return par_;
}
-void InsetFormula::par(MathInset * p)
+void InsetFormula::par(MathMatrixInset * p)
{
delete par_;
- par_ = p ? p : new MathMatrixInset;
+ par_ = p ? static_cast<MathMatrixInset *>(p) : new MathMatrixInset;
}
void InsetFormula::validate(LaTeXFeatures & features) const
{
- par()->validate(features);
+ par_->validate(features);
}
bool InsetFormula::insetAllowed(Inset::Code code) const
int InsetFormula::ascent(BufferView *, LyXFont const &) const
{
- return par()->ascent() + 1;
+ return par_->ascent() + 1;
}
int InsetFormula::descent(BufferView *, LyXFont const &) const
{
- return par()->descent() + 1;
+ return par_->descent() + 1;
}
int InsetFormula::width(BufferView *, LyXFont const &) const
{
metrics();
- return par()->width();
+ return par_->width();
}
MathInsetTypes InsetFormula::getType() const
{
- return par()->getType();;
+ return par_->getType();;
}
///
explicit InsetFormula(string const &);
///
+ ~InsetFormula();
+ ///
int ascent(BufferView *, LyXFont const &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
void handleExtern(string const & arg, BufferView * bv);
///
- MathMatrixInset * par() const;
+ MathInset * par() const;
///
bool display() const;
///
MathInsetTypes getType() const;
private:
/// Safe setting of contents
- void par(MathInset *);
+ void par(MathMatrixInset *);
+ ///
+ MathMatrixInset * par_;
};
#endif
extern char const * latex_special_chars;
-int greek_kb_flag = 0;
extern char const * latex_mathenv[];
MathCursor * mathcursor = 0;
-InsetFormulaBase::InsetFormulaBase(MathInset * par)
- : par_(par)
+InsetFormulaBase::InsetFormulaBase()
{
#ifdef WITH_WARNINGS
#warning This is needed as long the math parser is not re-entrant
}
-InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
- : UpdatableInset(f), par_(f.par_->clone())
-{}
-
-
-InsetFormulaBase::~InsetFormulaBase()
-{
- delete par_;
-}
-
-
void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
{
read(lex);
}
+
void InsetFormulaBase::write(Buffer const *, ostream & os) const
{
write(os);
void InsetFormulaBase::edit(BufferView * bv, bool front)
{
#warning Please have a look if this is right (Jug)
+#warning Does not look wrong... although I do not know what it is supposed to do (Andre)
edit(bv, front ? 0 : 1, 0, 0);
}
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
{
mathcursor->getPos(x, y);
- x -= par_->xo();
- y -= par_->yo();
+ x -= par()->xo();
+ y -= par()->yo();
}
int x;
int y;
mathcursor->getPos(x, y);
- //x -= par_->xo();
- y -= par_->yo();
+ //x -= par()->xo();
+ y -= par()->yo();
int asc;
int desc;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
int x;
int y;
mathcursor->getPos(x, y);
- x -= par_->xo();
- y -= par_->yo();
+ x -= par()->xo();
+ y -= par()->yo();
int asc;
int desc;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
}
-void InsetFormulaBase::metrics() const
-{
- const_cast<MathInset *>(par_)->metrics(LM_ST_TEXT);
-}
-
-
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
int x, int y, int /*button*/)
{
if (mathcursor) {
hideInsetCursor(bv);
- x += par_->xo();
- y += par_->yo();
+ x += par()->xo();
+ y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
if (sel_flag) {
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
sel_flag = true;
hideInsetCursor(bv);
- mathcursor->setPos(sel_x + par_->xo(), sel_y + par_->yo());
+ mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo());
mathcursor->selStart();
showInsetCursor(bv);
mathcursor->getPos(sel_x, sel_y);
} else if (sel_flag) {
hideInsetCursor(bv);
- x += par_->xo();
- y += par_->yo();
+ x += par()->xo();
+ y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
mathcursor->getPos(x, y);
//lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
+ static int greek_kb_flag = 0;
+
if (!mathcursor)
return UNDISPATCHED;
int y1;
istringstream is(arg.c_str());
is >> x >> y;
- par_->getXY(x1, y1);
+ par()->getXY(x1, y1);
mathcursor->setPos(x1 + x, y1 + y);
updateLocal(bv, false);
}
return font;
}
-MathInset * InsetFormulaBase::par() const
-{
- return par_;
-}
-
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
///
class InsetFormulaBase : public UpdatableInset {
public:
- ///
- InsetFormulaBase(InsetFormulaBase const & p);
- ///
- explicit InsetFormulaBase(MathInset *);
///
- virtual ~InsetFormulaBase();
+ InsetFormulaBase();
///
virtual int ascent(BufferView *, LyXFont const &) const = 0;
///
///
virtual std::vector<string> const getLabelList() const;
///
- MathInset * par() const;
+ virtual MathInset * par() const = 0;
///
- virtual void metrics() const;
+ virtual void metrics() const = 0;
protected:
///
virtual void updateLocal(BufferView * bv, bool mark_dirty);
- ///
- MathInset * par_;
private:
/// unimplemented
void operator=(const InsetFormulaBase &);
extern MathCursor * mathcursor;
InsetFormulaMacro::InsetFormulaMacro()
- : InsetFormulaBase(new MathMacroTemplate("unknown", 0))
+ : tmacro_(new MathMacroTemplate("unknown", 0))
{}
InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
- : InsetFormulaBase(new MathMacroTemplate(nm, na))
+ : tmacro_(new MathMacroTemplate(nm, na))
{
- MathMacroTable::insertTemplate(tmacro());
+ MathMacroTable::insertTemplate(tmacro_);
+}
+
+
+InsetFormulaMacro::~InsetFormulaMacro()
+{
+#ifdef WITH_WARNINGS
+#warning Need to unregister from MathMacroTable.
+#endif
+ // Instead of unregister an delete leak this until it gets fixed
+ //delete tmacro_;
}
Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
{
+#ifdef WITH_WARNINGS
+#warning This should not be needed in reality...
+#endif
return new InsetFormulaMacro(*this);
}
void InsetFormulaMacro::write(ostream & os) const
{
os << "FormulaMacro ";
- tmacro()->write(os, false);
+ tmacro().write(os, false);
}
int InsetFormulaMacro::latex(ostream & os, bool fragile,
bool /*free_spacing*/) const
{
- tmacro()->write(os, fragile);
+ tmacro().write(os, fragile);
return 2;
}
int InsetFormulaMacro::ascii(ostream & os, int) const
{
- tmacro()->write(os, false);
+ tmacro().write(os, false);
return 0;
}
void InsetFormulaMacro::read(LyXLex & lex)
{
// Awful hack...
- delete par_;
- par_ = mathed_parse(lex);
- MathMacroTable::insertTemplate(tmacro());
- par_->metrics(LM_ST_TEXT);
+ delete tmacro_;
+ tmacro_ = mathed_parse_macro(lex);
+ MathMacroTable::insertTemplate(tmacro_);
+ metrics();
}
string InsetFormulaMacro::prefix() const
{
- return string(" ") + _("Macro: ") + tmacro()->name() + ": ";
+ return string(" ") + _("Macro: ") + tmacro().name() + ": ";
}
int InsetFormulaMacro::ascent(BufferView *, LyXFont const &) const
{
- return tmacro()->ascent() + 5;
+ return tmacro().ascent() + 5;
}
int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const
{
- return tmacro()->descent() + 5;
+ return tmacro().descent() + 5;
}
int InsetFormulaMacro::width(BufferView *, LyXFont const & f) const
{
- tmacro()->metrics(LM_ST_TEXT);
- return 10 + lyxfont::width(prefix(), f) + tmacro()->width();
+ metrics();
+ return 10 + lyxfont::width(prefix(), f) + tmacro().width();
}
-void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
- int baseline, float & x, bool /*cleared*/) const
-{
- Painter & pain = bv->painter();
- LyXFont font(f);
-
- // label
- font.setColor(LColor::math);
-
- int const y = baseline - ascent(bv, font) + 1;
- int const w = width(bv, font) - 2;
- int const h = ascent(bv, font) + descent(bv, font) - 2;
-
- // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
- pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
- pain.rectangle(int(x), y, w, h, LColor::mathframe);
-
- if (mathcursor && mathcursor->formula() == this)
- mathcursor->drawSelection(pain);
-
- pain.text(int(x + 2), baseline, prefix(), font);
- x += width(bv, font);
-
- // formula
- float t = tmacro()->width() + 5;
- x -= t;
- tmacro()->draw(pain, int(x), baseline);
- x += t;
-}
-
UpdatableInset::RESULT
InsetFormulaMacro::localDispatch(BufferView * bv,
case LFUN_MATH_MACROARG: {
int const i = lyx::atoi(arg);
lyxerr << "inserting macro arg " << i << "\n";
- if (i > 0 && i <= tmacro()->numargs()) {
+ if (i > 0 && i <= tmacro().numargs()) {
mathcursor->insert(new MathMacroArgument(i));
updateLocal(bv, true);
} else {
- lyxerr << "not in range 0.." << tmacro()->numargs() << "\n";
+ lyxerr << "not in range 0.." << tmacro().numargs() << "\n";
}
break;
}
}
-MathMacroTemplate * InsetFormulaMacro::tmacro() const
+MathMacroTemplate const & InsetFormulaMacro::tmacro() const
{
- return static_cast<MathMacroTemplate *>(par_);
+ return *tmacro_;
}
{
return LM_OT_MACRO;
}
+
+
+MathInset * InsetFormulaMacro::par() const
+{
+ return const_cast<MathMacroTemplate *>(tmacro_);
+}
+
+
+void InsetFormulaMacro::metrics() const
+{
+ par()->metrics(LM_ST_TEXT);
+}
+
+
+void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
+ int baseline, float & x, bool /*cleared*/) const
+{
+ Painter & pain = bv->painter();
+ LyXFont font(f);
+
+ // label
+ font.setColor(LColor::math);
+
+ int const y = baseline - ascent(bv, font) + 1;
+ int const w = width(bv, font) - 2;
+ int const h = ascent(bv, font) + descent(bv, font) - 2;
+
+ // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
+ pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
+ pain.rectangle(int(x), y, w, h, LColor::mathframe);
+
+ if (mathcursor && mathcursor->formula() == this)
+ mathcursor->drawSelection(pain);
+
+ pain.text(int(x + 2), baseline, prefix(), font);
+ x += width(bv, font);
+
+ // formula
+ float t = tmacro().width() + 5;
+ x -= t;
+ par()->draw(pain, int(x), baseline);
+ x += t;
+}
+
///
explicit InsetFormulaMacro(string name, int na);
///
+ ~InsetFormulaMacro();
+ ///
int ascent(BufferView *, LyXFont const &) const;
///
int descent(BufferView *, LyXFont const &) const;
RESULT localDispatch(BufferView *, kb_action, string const &);
///
MathInsetTypes getType() const;
+ ///
+ MathInset * par() const;
+ ///
+ void metrics() const;
private:
+ ///
+ MathMacroTemplate const & tmacro() const;
/// prefix in inset
string prefix() const;
///
- MathMacroTemplate * tmacro() const;
+ MathMacroTemplate const * tmacro_;
};
#endif
{
if (!prevIsInset())
return false;
- MathInset * p = prevInset();
+ MathScriptInset * p = prevScriptInset();
int old = p->limits();
p->limits(old < 0 ? 1 : -1);
return old != p->limits();
MathInset::MathInset(int nargs, string const & name)
: name_(name), width_(0), ascent_(0), descent_(0),
- size_(LM_ST_DISPLAY), cells_(nargs), xo_(0), yo_(0)
+ size_(LM_ST_DISPLAY), code_(LM_TC_MIN), cells_(nargs), xo_(0), yo_(0)
{}
}
-int MathInset::limits() const
-{
- return false;
-}
-
-
-void MathInset::limits(int)
-{}
-
-
string const & MathInset::name() const
{
return name_;
size_ = s;
}
+
std::ostream & operator<<(std::ostream & os, MathInset const & inset)
{
inset.write(os, false);
}
-
MathXArray & MathInset::xcell(int i)
{
return cells_[i];
}
+
MathXArray const & MathInset::xcell(int i) const
{
return cells_[i];
}
-
MathArray & MathInset::cell(int i)
{
return cells_[i].data_;
}
+
MathArray const & MathInset::cell(int i) const
{
return cells_[i].data_;
array.push_back(p);
}
+
void MathInset::metrics(MathStyles st)
{
size_ = st;
xcell(i).metrics(st);
}
+
void MathInset::draw(Painter & pain, int x, int y)
{
xo_ = x;
return idxPrev(idx, pos);
}
+
bool MathInset::idxUp(int &, int &) const
{
return false;
return true;
}
+
bool MathInset::idxLast(int & i, int & pos) const
{
if (nargs() == 0)
return false;
}
+
void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
{
popit = false;
deleteit = false;
}
+
void MathInset::idxDeleteRange(int, int)
{}
y <= yo_ + descent_;
}
+
void MathInset::validate(LaTeXFeatures & features) const
{
for (int i = 0; i < nargs(); ++i)
cell(i).validate(features);
}
+
std::vector<int> MathInset::idxBetween(int from, int to) const
{
std::vector<int> res;
res.push_back(i);
return res;
}
+
+
+MathTextCodes MathInset::code() const
+{
+ return code_;
+}
+
+
+void MathInset::code(MathTextCodes t)
+{
+ code_ = t;
+}
///
virtual int height() const;
///
- virtual int limits() const;
- ///
- virtual void limits(int);
- ///
string const & name() const;
///
virtual void setName(string const & n);
virtual bool isArray() const { return false; }
///
virtual bool isActive() const { return nargs() > 0; }
+ /// identifies insets that display scripts directly above and below
///
///
static int workwidth;
+
+ /// the inherited text style
+ MathTextCodes code() const;
+ ///
+ void code(MathTextCodes t);
+
protected:
/// usually the LaTeX name of the thingy
string name_;
void size(MathStyles s);
/// the used font size
MathStyles size_;
+ /// the inherited text style
+ MathTextCodes code_;
protected:
///
}
-void MathMacroTable::insertTemplate(MathMacroTemplate * p)
+void MathMacroTable::insertTemplate(MathMacroTemplate const * p)
{
- macro_table[p->name()] = p;
+ macro_table[p->name()] = const_cast<MathMacroTemplate *>(p);
}
struct MathMacroTable {
public:
///
- static void updateTemplate(MathMacroTemplate *);
- ///
- static void insertTemplate(MathMacroTemplate *);
+ static void insertTemplate(MathMacroTemplate const *);
///
static MathMacroTemplate & provideTemplate(string const &);
///
#include "debug.h"
-MathMacroTemplate::MathMacroTemplate() :
- MathInset(1, "undefined"), numargs_(0)
+MathMacroTemplate::MathMacroTemplate()
+ : MathInset(1), numargs_(0)
{}
-MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs) :
- MathInset(1, nm), numargs_(numargs)
+MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
+ : MathInset(1, nm), numargs_(numargs)
{}
unsigned char getuchar(std::istream * is)
{
- char c;
+ char c = 0;
is->get(c);
if (!is->good()) {
lyxerr << "The input stream is not well..." << endl;
string yytext;
int yylineno;
istream * yyis;
-MathTextCodes yyvarcode;
unsigned char c = getuchar(yyis);
//lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
- if (yyvarcode == LM_TC_TEXTRM && c == ' ') {
- yylval.i = ' ';
- return LM_TK_ALPHA;
- } else if (lexcode[c] == LexNewLine) {
+ if (lexcode[c] == LexNewLine) {
++yylineno;
continue;
} else if (lexcode[c] == LexComment) {
|| lexcode[c] == LexMathSpace) {
yylval.i = c;
return LM_TK_STR;
- } else if (lexcode[c] == LexAlpha) {
+ } else if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
yylval.i = c;
return LM_TK_ALPHA;
} else if (lexcode[c] == LexBOP) {
yytext += c;
c = getuchar(yyis);
}
- if (yyis->good())
+ while (lexcode[c] == LexSpace && yyis->good())
+ c = getuchar(yyis);
+ if (yyis->good() && lexcode[c] != LexSpace)
yyis->putback(c);
+
//lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n";
latexkeys const * l = in_word_set(yytext);
if (!l)
}
-MathInset * mathed_parse()
+MathMacroTemplate * mathed_parse_macro()
+{
+ if (yylex() != LM_TK_NEWCOMMAND) {
+ lyxerr << "\\newcommand expected\n";
+ return 0;
+ }
+
+ string name = lexArg('{').substr(1);
+ string arg = lexArg('[');
+ int narg = arg.empty() ? 0 : atoi(arg.c_str());
+ MathMacroTemplate * p = new MathMacroTemplate(name, narg);
+ mathed_parse_into(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
+ return p;
+}
+
+
+MathMatrixInset * mathed_parse_normal()
{
- MathInset * p = 0;
+ MathMatrixInset * p = 0;
int t = yylex();
switch (t) {
- case LM_TK_NEWCOMMAND: {
- string const name = lexArg('{').substr(1);
- string const arg = lexArg('[');
- int narg = arg.empty() ? 0 : atoi(arg.c_str());
- p = new MathMacroTemplate(name, narg);
- mathed_parse_into(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
- //lyxerr[Debug::MATHED] << "LM_TK_NEWCOMMAND: name: "
- // << name << " nargs: " << narg << "\n";
- break;
- }
-
case LM_TK_MATH:
case LM_TK_BEGIN: {
int i = yylval.i;
static int plevel = -1;
++plevel;
- yyvarcode = LM_TC_VAR;
+ MathTextCodes yyvarcode = LM_TC_VAR;
int t = yylex();
bool panic = false;
switch (t) {
case LM_TK_ALPHA:
- array.push_back(yylval.i, yyvarcode);
+ if (!isspace(yylval.i) || yyvarcode == LM_TC_TEXTRM)
+ array.push_back(yylval.i, yyvarcode);
break;
- case LM_TK_ARGUMENT:
- array.push_back(new MathMacroArgument(yylval.i));
+ case LM_TK_ARGUMENT: {
+ MathMacroArgument * p = new MathMacroArgument(yylval.i);
+ p->code(yyvarcode);
+ array.push_back(p);
break;
+ }
case LM_TK_SPECIAL:
array.push_back(yylval.i, LM_TC_SPECIAL);
}
-MathInset * mathed_parse(string const & str)
+MathMacroTemplate * mathed_parse_macro(string const & str)
+{
+ istringstream is(str.c_str());
+ return mathed_parse_macro(is);
+}
+
+
+MathMatrixInset * mathed_parse_normal(string const & str)
{
istringstream is(str.c_str());
- return mathed_parse(is);
+ return mathed_parse_normal(is);
}
-MathInset * mathed_parse(istream & is)
+
+MathMatrixInset * mathed_parse_normal(istream & is)
{
yyis = &is;
yylineno = 0;
- return mathed_parse();
+ return mathed_parse_normal();
}
-MathInset * mathed_parse(LyXLex & lex)
+MathMacroTemplate * mathed_parse_macro(istream & is)
+{
+ yyis = &is;
+ yylineno = 0;
+ return mathed_parse_macro();
+}
+
+
+
+MathMatrixInset * mathed_parse_normal(LyXLex & lex)
{
yyis = &lex.getStream();
yylineno = lex.GetLineNo();
- MathInset * p = mathed_parse();
+ MathMatrixInset * p = mathed_parse_normal();
// Update line number
lex.setLineNo(yylineno);
return p;
}
+MathMacroTemplate * mathed_parse_macro(LyXLex & lex)
+{
+ yyis = &lex.getStream();
+ yylineno = lex.GetLineNo();
+
+ MathMacroTemplate * p = mathed_parse_macro();
+
+ // Update line number
+ lex.setLineNo(yylineno);
+
+ // reading of end_inset
+ while (lex.IsOK()) {
+ lex.nextToken();
+ if (lex.GetString() == "\\end_inset")
+ break;
+ lyxerr[Debug::MATHED] << "InsetFormula::Read: Garbage before \\end_inset,"
+ " or missing \\end_inset!" << endl;
+ }
+
+ return p;
+}
//]})
#include "symbol_def.h"
class MathArray;
-class MathInset;
+class MathMatrixInset;
+class MathMacroTemplate;
class LyXLex;
///
latexkeys const * lm_get_key_by_id(unsigned int id, short tc);
-MathInset * mathed_parse(string const &);
-MathInset * mathed_parse(std::istream &);
-MathInset * mathed_parse(LyXLex &);
+MathMatrixInset * mathed_parse_normal(string const &);
+MathMatrixInset * mathed_parse_normal(std::istream &);
+MathMatrixInset * mathed_parse_normal(LyXLex &);
+
+MathMacroTemplate * mathed_parse_macro(string const &);
+MathMacroTemplate * mathed_parse_macro(std::istream &);
+MathMacroTemplate * mathed_parse_macro(LyXLex &);
#endif