mathed102.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2229 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-13 07:55:55 +00:00
parent 487f6eb3b4
commit 4a40b711f2
14 changed files with 189 additions and 318 deletions

View File

@ -22,8 +22,6 @@ libmathed_la_SOURCES = \
macro_support.h \ macro_support.h \
math_arrayinset.C \ math_arrayinset.C \
math_arrayinset.h \ math_arrayinset.h \
math_accentinset.C \
math_accentinset.h \
math_bigopinset.C \ math_bigopinset.C \
math_bigopinset.h \ math_bigopinset.h \
math_cursor.C \ math_cursor.C \

View File

@ -77,10 +77,10 @@ void handleFont(BufferView * bv, MathTextCodes t)
mathcursor->handleFont(t); mathcursor->handleFont(t);
} }
void handleAccent(BufferView * bv, int code) void handleAccent(BufferView * bv, string const & name, int code)
{ {
bv->lockedInsetStoreUndo(Undo::EDIT); bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->handleAccent(code); mathcursor->handleAccent(name, code);
} }
void handleDelim(BufferView * bv, int l, int r) void handleDelim(BufferView * bv, int l, int r)
@ -636,16 +636,16 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
// --- accented characters ------------------------------ // --- accented characters ------------------------------
case LFUN_UMLAUT: handleAccent(bv, LM_ddot); break; case LFUN_UMLAUT: handleAccent(bv, "ddot", LM_ddot); break;
case LFUN_CIRCUMFLEX: handleAccent(bv, LM_hat); break; case LFUN_CIRCUMFLEX: handleAccent(bv, "hat", LM_hat); break;
case LFUN_GRAVE: handleAccent(bv, LM_grave); break; case LFUN_GRAVE: handleAccent(bv, "grave", LM_grave); break;
case LFUN_ACUTE: handleAccent(bv, LM_acute); break; case LFUN_ACUTE: handleAccent(bv, "acute", LM_acute); break;
case LFUN_TILDE: handleAccent(bv, LM_tilde); break; case LFUN_TILDE: handleAccent(bv, "tilde", LM_tilde); break;
case LFUN_MACRON: handleAccent(bv, LM_bar); break; case LFUN_MACRON: handleAccent(bv, "bar", LM_bar); break;
case LFUN_DOT: handleAccent(bv, LM_dot); break; case LFUN_DOT: handleAccent(bv, "dot", LM_dot); break;
case LFUN_CARON: handleAccent(bv, LM_check); break; case LFUN_CARON: handleAccent(bv, "check", LM_check); break;
case LFUN_BREVE: handleAccent(bv, LM_breve); break; case LFUN_BREVE: handleAccent(bv, "breve", LM_breve); break;
case LFUN_VECTOR: handleAccent(bv, LM_vec); break; case LFUN_VECTOR: handleAccent(bv, "vec", LM_vec); break;
// Greek mode // Greek mode
case LFUN_GREEK: case LFUN_GREEK:
@ -724,7 +724,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
int ilt = '('; int ilt = '(';
int irt = '.'; int irt = '.';
static const string vdelim("(){}[]./|"); static const string vdelim("(){}[]./|");
lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n"; //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
if (arg.empty()) if (arg.empty())
break; break;
@ -733,8 +733,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string lt; string lt;
string rt; string rt;
is >> lt >> rt; is >> lt >> rt;
lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n"; //lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n"; //lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
if (lt.size() > 1) { if (lt.size() > 1) {
latexkeys const * l = in_word_set(lt); latexkeys const * l = in_word_set(lt);

View File

@ -1,69 +0,0 @@
#include <config.h>
#include "math_accentinset.h"
#include "mathed/support.h"
#include "math_parser.h"
#include "support/LOstream.h"
using std::ostream;
MathAccentInset::MathAccentInset(int f)
: MathInset(1), code(f)
{}
MathInset * MathAccentInset::clone() const
{
return new MathAccentInset(*this);
}
void MathAccentInset::Metrics(MathStyles st, int, int)
{
xcell(0).Metrics(st);
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent();
width_ = xcell(0).width();
dh = 5;
if (code == LM_not) {
ascent_ += dh;
descent_ += dh;
dh = height();
} else
ascent_ += dh + 2;
dy = ascent_;
}
void MathAccentInset::draw(Painter & pain, int x, int y)
{
xcell(0).draw(pain, x, y);
mathed_draw_deco(pain, x, y - dy, width(), dh, code);
}
void MathAccentInset::Write(ostream & os, bool fragile) const
{
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
os << '\\' << l->name;
if (code == LM_not)
os << ' ';
else
os << '{';
cell(0).Write(os, fragile);
if (code != LM_not)
os << '}';
}
void MathAccentInset::WriteNormal(ostream & os) const
{
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
os << "[accent " << l->name << " ";
cell(0).WriteNormal(os);
os << "] ";
}

View File

@ -1,37 +0,0 @@
// -*- C++ -*-
#ifndef MATH_ACCENTINSET_H
#define MATH_ACCENTINSET_H
#include "math_inset.h"
#include "mathed/support.h"
#include "math_defs.h"
/// Accents
class MathAccentInset : public MathInset {
public:
///
explicit MathAccentInset(int);
///
MathInset * clone() const;
///
void draw(Painter &, int, int);
///
void Write(std::ostream &, bool fragile) const;
///
void WriteNormal(std::ostream &) const;
///
void Metrics(MathStyles st, int asc = 0, int des = 0);
///
int getAccentCode() const;
///
bool isAccentInset() const { return true; }
private:
///
int code;
///
int dh;
///
int dy;
};
#endif

View File

@ -43,7 +43,6 @@
#include "math_decorationinset.h" #include "math_decorationinset.h"
#include "math_dotsinset.h" #include "math_dotsinset.h"
#include "math_deliminset.h" #include "math_deliminset.h"
#include "math_accentinset.h"
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "math_scriptinset.h" #include "math_scriptinset.h"
@ -66,12 +65,11 @@ bool IsMacro(short tok, int id)
return tok != LM_TK_STACK && return tok != LM_TK_STACK &&
tok != LM_TK_FRAC && tok != LM_TK_FRAC &&
tok != LM_TK_SQRT && tok != LM_TK_SQRT &&
tok != LM_TK_WIDE && tok != LM_TK_DECORATION &&
tok != LM_TK_SPACE && tok != LM_TK_SPACE &&
tok != LM_TK_DOTS && tok != LM_TK_DOTS &&
tok != LM_TK_FUNCLIM && tok != LM_TK_FUNCLIM &&
tok != LM_TK_BIGSYM && tok != LM_TK_BIGSYM &&
tok != LM_TK_ACCENT &&
!(tok == LM_TK_SYM && id < 255); !(tok == LM_TK_SYM && id < 255);
} }
@ -638,8 +636,8 @@ in_word_set(s) << " \n";
p = new MathSqrtInset; p = new MathSqrtInset;
break; break;
case LM_TK_WIDE: case LM_TK_DECORATION:
p = new MathDecorationInset(l->id); p = new MathDecorationInset(l->name, l->id);
break; break;
case LM_TK_FUNCLIM: case LM_TK_FUNCLIM:
@ -654,10 +652,6 @@ in_word_set(s) << " \n";
p = new MathDotsInset(l->name, l->id); p = new MathDotsInset(l->name, l->id);
break; break;
case LM_TK_ACCENT:
p = new MathAccentInset(l->id);
break;
case LM_TK_MACRO: case LM_TK_MACRO:
p = new MathMacro(MathMacroTable::provideTemplate(s)); p = new MathMacro(MathMacroTable::provideTemplate(s));
break; break;
@ -884,14 +878,15 @@ void MathCursor::handleFont(MathTextCodes t)
} }
void MathCursor::handleAccent(int code) void MathCursor::handleAccent(string const & name, int code)
{ {
MathAccentInset * p = new MathAccentInset(code); MathDecorationInset * p = new MathDecorationInset(name, code);
if (selection) { if (selection) {
SelCut(); SelCut();
p->cell(0) = selarray; p->cell(0) = selarray;
} }
insert(p); insert(p);
push(p, true);
} }
void MathCursor::handleDelim(int l, int r) void MathCursor::handleDelim(int l, int r)
@ -902,6 +897,7 @@ void MathCursor::handleDelim(int l, int r)
p->cell(0) = selarray; p->cell(0) = selarray;
} }
insert(p); insert(p);
push(p, true);
} }

View File

@ -114,7 +114,7 @@ public:
/// ///
void handleFont(MathTextCodes t); void handleFont(MathTextCodes t);
/// ///
void handleAccent(int code); void handleAccent(string const & name, int code);
/// ///
void handleDelim(int l, int r); void handleDelim(int l, int r);
/// Splits cells and shifts right part to the next cell /// Splits cells and shifts right part to the next cell

View File

@ -14,8 +14,8 @@
using std::ostream; using std::ostream;
MathDecorationInset::MathDecorationInset(int d) MathDecorationInset::MathDecorationInset(string const & name, int d)
: MathInset(1), deco_(d) : MathInset(1, name), deco_(d)
{ {
upper_ = deco_ != LM_underline && deco_ != LM_underbrace; upper_ = deco_ != LM_underline && deco_ != LM_underbrace;
} }
@ -45,6 +45,13 @@ void MathDecorationInset::Metrics(MathStyles st, int, int)
dy_ = descent_ + 1; dy_ = descent_ + 1;
descent_ += dh_ + 2; descent_ += dh_ + 2;
} }
if (deco_ == LM_not) {
ascent_ += dh_;
descent_ += dh_;
dh_ = height();
dy_ = - ascent_;
}
} }
void MathDecorationInset::draw(Painter & pain, int x, int y) void MathDecorationInset::draw(Painter & pain, int x, int y)
@ -58,14 +65,28 @@ void MathDecorationInset::draw(Painter & pain, int x, int y)
void MathDecorationInset::Write(ostream & os, bool fragile) const void MathDecorationInset::Write(ostream & os, bool fragile) const
{ {
latexkeys const * l = lm_get_key_by_id(deco_, LM_TK_WIDE);
if (fragile && if (fragile &&
(compare(l->name, "overbrace") == 0 || (name_ == "overbrace" ||
compare(l->name, "underbrace") == 0 || name_ == "underbrace" ||
compare(l->name, "overleftarrow") == 0 || name_ == "overleftarrow" ||
compare(l->name, "overrightarrow") == 0)) name_ == "overrightarrow"))
os << "\\protect"; os << "\\protect";
os << '\\' << l->name << '{'; os << '\\' << name_;
if (deco_ == LM_not)
os << ' ';
else
os << '{';
cell(0).Write(os, fragile); cell(0).Write(os, fragile);
if (deco_ != LM_not)
os << '}'; os << '}';
} }
void MathDecorationInset::WriteNormal(ostream & os) const
{
os << "[" << name_ << " ";
cell(0).WriteNormal(os);
os << "] ";
}

View File

@ -8,13 +8,13 @@
#pragma interface #pragma interface
#endif #endif
/** Decorations over (below) a math object /** Decorations and accents over (below) a math object
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
class MathDecorationInset : public MathInset { class MathDecorationInset : public MathInset {
public: public:
/// ///
explicit MathDecorationInset(int); MathDecorationInset(string const & name, int);
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///
@ -23,6 +23,8 @@ public:
void Write(std::ostream &, bool fragile) const; void Write(std::ostream &, bool fragile) const;
/// ///
void Metrics(MathStyles st, int asc = 0, int des = 0); void Metrics(MathStyles st, int asc = 0, int des = 0);
///
void WriteNormal(ostream & os) const;
private: private:
/// ///
int deco_; int deco_;

View File

@ -43,7 +43,7 @@ latexkeys const wordlist[] =
{"approx", LM_TK_SYM, LM_approx}, {"approx", LM_TK_SYM, LM_approx},
{"triangleleft", LM_TK_SYM, LM_triangleleft}, {"triangleleft", LM_TK_SYM, LM_triangleleft},
{"triangleright", LM_TK_SYM, LM_triangleright}, {"triangleright", LM_TK_SYM, LM_triangleright},
{"tilde", LM_TK_ACCENT, LM_tilde}, {"tilde", LM_TK_DECORATION, LM_tilde},
{"lambda", LM_TK_SYM, LM_lambda}, {"lambda", LM_TK_SYM, LM_lambda},
{"emptyset", LM_TK_MACRO, LM_emptyset}, {"emptyset", LM_TK_MACRO, LM_emptyset},
{"triangle", LM_TK_SYM, LM_triangle}, {"triangle", LM_TK_SYM, LM_triangle},
@ -62,10 +62,10 @@ latexkeys const wordlist[] =
{"swarrow", LM_TK_SYM, LM_swarrow}, {"swarrow", LM_TK_SYM, LM_swarrow},
{"top", LM_TK_SYM, LM_top}, {"top", LM_TK_SYM, LM_top},
{"Rightarrow", LM_TK_SYM, LM_Rightarrow}, {"Rightarrow", LM_TK_SYM, LM_Rightarrow},
{"underline", LM_TK_WIDE, LM_underline}, {"underline", LM_TK_DECORATION, LM_underline},
{"underbrace", LM_TK_WIDE, LM_underbrace}, {"underbrace", LM_TK_DECORATION, LM_underbrace},
{"eta", LM_TK_SYM, LM_eta}, {"eta", LM_TK_SYM, LM_eta},
{"acute", LM_TK_ACCENT, LM_acute}, {"acute", LM_TK_DECORATION, LM_acute},
{"angle", LM_TK_SYM, LM_angle}, {"angle", LM_TK_SYM, LM_angle},
{"exp", LM_TK_FUNC, 0}, {"exp", LM_TK_FUNC, 0},
{"leftarrow", LM_TK_SYM, LM_leftarrow}, {"leftarrow", LM_TK_SYM, LM_leftarrow},
@ -80,14 +80,14 @@ latexkeys const wordlist[] =
{"Psi", LM_TK_SYM, LM_Psi}, {"Psi", LM_TK_SYM, LM_Psi},
{"longleftrightarrow", LM_TK_SYM, LM_longleftrightarrow}, {"longleftrightarrow", LM_TK_SYM, LM_longleftrightarrow},
{"alpha", LM_TK_SYM, LM_alpha}, {"alpha", LM_TK_SYM, LM_alpha},
{"widehat", LM_TK_WIDE, LM_widehat}, {"widehat", LM_TK_DECORATION, LM_widehat},
{"sin", LM_TK_FUNC, 0}, {"sin", LM_TK_FUNC, 0},
{"asymp", LM_TK_SYM, LM_asymp}, {"asymp", LM_TK_SYM, LM_asymp},
{"nolimits", LM_TK_LIMIT, 0 }, {"nolimits", LM_TK_LIMIT, 0 },
{"perp", LM_TK_MACRO, LM_perp}, {"perp", LM_TK_MACRO, LM_perp},
{"wedge", LM_TK_SYM, LM_wedge}, {"wedge", LM_TK_SYM, LM_wedge},
{"ln", LM_TK_FUNC, 0}, {"ln", LM_TK_FUNC, 0},
{"widetilde", LM_TK_WIDE, LM_widetilde}, {"widetilde", LM_TK_DECORATION, LM_widetilde},
{"Omega", LM_TK_SYM, LM_Omega}, {"Omega", LM_TK_SYM, LM_Omega},
{"natural", LM_TK_SYM, LM_natural}, {"natural", LM_TK_SYM, LM_natural},
{"iota", LM_TK_SYM, LM_iota}, {"iota", LM_TK_SYM, LM_iota},
@ -100,7 +100,7 @@ latexkeys const wordlist[] =
{"star", LM_TK_SYM, LM_star}, {"star", LM_TK_SYM, LM_star},
{"leftharpoondown", LM_TK_SYM, LM_leftharpoondown}, {"leftharpoondown", LM_TK_SYM, LM_leftharpoondown},
{"wp", LM_TK_SYM, LM_wp}, {"wp", LM_TK_SYM, LM_wp},
{"not", LM_TK_ACCENT, LM_not}, {"not", LM_TK_DECORATION, LM_not},
{"tan", LM_TK_FUNC, 0}, {"tan", LM_TK_FUNC, 0},
{"Theta", LM_TK_SYM, LM_Theta}, {"Theta", LM_TK_SYM, LM_Theta},
{"rceil", LM_TK_SYM, LM_rceil}, {"rceil", LM_TK_SYM, LM_rceil},
@ -125,7 +125,7 @@ latexkeys const wordlist[] =
{"arcsin", LM_TK_FUNC, 0}, {"arcsin", LM_TK_FUNC, 0},
{"arctan", LM_TK_FUNC, 0}, {"arctan", LM_TK_FUNC, 0},
{"flat", LM_TK_SYM, LM_flat}, {"flat", LM_TK_SYM, LM_flat},
{"check", LM_TK_ACCENT, LM_check}, {"check", LM_TK_DECORATION, LM_check},
{"rangle", LM_TK_SYM, LM_rangle}, {"rangle", LM_TK_SYM, LM_rangle},
{"cot", LM_TK_FUNC, 0}, {"cot", LM_TK_FUNC, 0},
{"cdot", LM_TK_SYM, LM_cdot}, {"cdot", LM_TK_SYM, LM_cdot},
@ -177,15 +177,15 @@ latexkeys const wordlist[] =
{"mp", LM_TK_SYM, LM_mp}, {"mp", LM_TK_SYM, LM_mp},
{"pm", LM_TK_SYM, LM_pm}, {"pm", LM_TK_SYM, LM_pm},
{"nonumber", LM_TK_NONUM, 0}, {"nonumber", LM_TK_NONUM, 0},
{"breve", LM_TK_ACCENT, LM_breve}, {"breve", LM_TK_DECORATION, LM_breve},
{"bigvee", LM_TK_BIGSYM, LM_vee}, {"bigvee", LM_TK_BIGSYM, LM_vee},
{"bowtie", LM_TK_SYM, LM_bowtie}, {"bowtie", LM_TK_SYM, LM_bowtie},
{"bigwedge", LM_TK_BIGSYM, LM_wedge}, {"bigwedge", LM_TK_BIGSYM, LM_wedge},
{"frown", LM_TK_SYM, LM_frown}, {"frown", LM_TK_SYM, LM_frown},
{"rightharpoondown", LM_TK_SYM, LM_rightharpoondown}, {"rightharpoondown", LM_TK_SYM, LM_rightharpoondown},
{"det", LM_TK_FUNCLIM, 0}, {"det", LM_TK_FUNCLIM, 0},
{"dot", LM_TK_ACCENT, LM_dot}, {"dot", LM_TK_DECORATION, LM_dot},
{"ddot", LM_TK_ACCENT, LM_ddot}, {"ddot", LM_TK_DECORATION, LM_ddot},
{"lg", LM_TK_FUNC, 0}, {"lg", LM_TK_FUNC, 0},
{"log", LM_TK_FUNC, 0}, {"log", LM_TK_FUNC, 0},
{"oplus", LM_TK_SYM, LM_oplus}, {"oplus", LM_TK_SYM, LM_oplus},
@ -195,7 +195,7 @@ latexkeys const wordlist[] =
{"diamondsuit", LM_TK_SYM, LM_diamondsuit}, {"diamondsuit", LM_TK_SYM, LM_diamondsuit},
{"rfloor", LM_TK_SYM, LM_rfloor}, {"rfloor", LM_TK_SYM, LM_rfloor},
{"end", LM_TK_END, 0}, {"end", LM_TK_END, 0},
{"hat", LM_TK_ACCENT, LM_hat}, {"hat", LM_TK_DECORATION, LM_hat},
{"tanh", LM_TK_FUNC, 0}, {"tanh", LM_TK_FUNC, 0},
{"vdots", LM_TK_DOTS, LM_vdots}, {"vdots", LM_TK_DOTS, LM_vdots},
{"bigcap", LM_TK_BIGSYM, LM_cap}, {"bigcap", LM_TK_BIGSYM, LM_cap},
@ -209,7 +209,7 @@ latexkeys const wordlist[] =
{"delta", LM_TK_SYM, LM_delta}, {"delta", LM_TK_SYM, LM_delta},
{"odot", LM_TK_SYM, LM_odot}, {"odot", LM_TK_SYM, LM_odot},
{"oint", LM_TK_BIGSYM, LM_oint}, {"oint", LM_TK_BIGSYM, LM_oint},
{"grave", LM_TK_ACCENT, LM_grave}, {"grave", LM_TK_DECORATION, LM_grave},
{"pmod", LM_TK_PMOD, 0}, {"pmod", LM_TK_PMOD, 0},
{"prod", LM_TK_BIGSYM, LM_prod}, {"prod", LM_TK_BIGSYM, LM_prod},
{"frac", LM_TK_FRAC, 0}, {"frac", LM_TK_FRAC, 0},
@ -217,9 +217,9 @@ latexkeys const wordlist[] =
{"circ", LM_TK_SYM, LM_circ}, {"circ", LM_TK_SYM, LM_circ},
{"aleph", LM_TK_SYM, LM_aleph}, {"aleph", LM_TK_SYM, LM_aleph},
{"min", LM_TK_FUNCLIM, 0}, {"min", LM_TK_FUNCLIM, 0},
{"overline", LM_TK_WIDE, LM_overline}, {"overline", LM_TK_DECORATION, LM_overline},
{"arg", LM_TK_FUNC, 0}, {"arg", LM_TK_FUNC, 0},
{"overbrace", LM_TK_WIDE, LM_overbrace}, {"overbrace", LM_TK_DECORATION, LM_overbrace},
{"amalg", LM_TK_SYM, LM_amalg}, {"amalg", LM_TK_SYM, LM_amalg},
{"gamma", LM_TK_SYM, LM_gamma}, {"gamma", LM_TK_SYM, LM_gamma},
{"vee", LM_TK_SYM, LM_vee}, {"vee", LM_TK_SYM, LM_vee},
@ -238,12 +238,12 @@ latexkeys const wordlist[] =
{"bigtriangledown", LM_TK_SYM, LM_bigtriangledown}, {"bigtriangledown", LM_TK_SYM, LM_bigtriangledown},
{"mathbf", LM_TK_FONT, LM_TC_BF}, {"mathbf", LM_TK_FONT, LM_TC_BF},
{"mathsf", LM_TK_FONT, LM_TC_SF}, {"mathsf", LM_TK_FONT, LM_TC_SF},
{"bar", LM_TK_ACCENT, LM_bar}, {"bar", LM_TK_DECORATION, LM_bar},
{"varpi", LM_TK_SYM, LM_varpi}, {"varpi", LM_TK_SYM, LM_varpi},
{"varphi", LM_TK_SYM, LM_varphi}, {"varphi", LM_TK_SYM, LM_varphi},
{"newcommand", LM_TK_NEWCOMMAND, 0 }, {"newcommand", LM_TK_NEWCOMMAND, 0 },
{"overleftarrow", LM_TK_WIDE, LM_overleftarrow}, {"overleftarrow", LM_TK_DECORATION, LM_overleftarrow},
{"overrightarrow", LM_TK_WIDE, LM_overightarrow}, {"overrightarrow", LM_TK_DECORATION, LM_overightarrow},
{"Leftarrow", LM_TK_SYM, LM_Leftarrow}, {"Leftarrow", LM_TK_SYM, LM_Leftarrow},
{"Longleftarrow", LM_TK_SYM, LM_Longleftarrow}, {"Longleftarrow", LM_TK_SYM, LM_Longleftarrow},
{"Leftrightarrow", LM_TK_SYM, LM_Leftrightarrow}, {"Leftrightarrow", LM_TK_SYM, LM_Leftrightarrow},
@ -261,7 +261,7 @@ latexkeys const wordlist[] =
{"coth", LM_TK_FUNC, 0}, {"coth", LM_TK_FUNC, 0},
{"rho", LM_TK_SYM, LM_rho}, {"rho", LM_TK_SYM, LM_rho},
{"cong", LM_TK_SYM, LM_cong}, {"cong", LM_TK_SYM, LM_cong},
{"vec", LM_TK_ACCENT, LM_vec}, {"vec", LM_TK_DECORATION, LM_vec},
{"dim", LM_TK_FUNC, 0}, {"dim", LM_TK_FUNC, 0},
{"mid", LM_TK_SYM, LM_mid}, {"mid", LM_TK_SYM, LM_mid},
{"hom", LM_TK_FUNC, 0}, {"hom", LM_TK_FUNC, 0},

View File

@ -171,8 +171,6 @@ public:
bool covers(int x, int y) const; bool covers(int x, int y) const;
/// Identifies ScriptInsets /// Identifies ScriptInsets
virtual bool isUpDownInset() const { return false; } virtual bool isUpDownInset() const { return false; }
/// Identifies AccentInsets
virtual bool isAccentInset() const { return false; }
/// Identifies BigopInsets /// Identifies BigopInsets
virtual bool isBigopInset() const { return false; } virtual bool isBigopInset() const { return false; }
/// ///

View File

@ -11,7 +11,7 @@
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
#include "math_parser.h" #include "math_parser.h"
#include "array.h" #include "array.h"
#include "math_accentinset.h" #include "math_decorationinset.h"
#include "math_deliminset.h" #include "math_deliminset.h"
#include "math_fracinset.h" #include "math_fracinset.h"
#include "math_inset.h" #include "math_inset.h"
@ -94,7 +94,7 @@ void MathMacroTable::builtinMacros()
// This macro doesn't have arguments // This macro doesn't have arguments
{ {
MathMacroTemplate * t = new MathMacroTemplate("notin", 0); MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
MathAccentInset * p = new MathAccentInset(LM_not); MathDecorationInset * p = new MathDecorationInset("not", LM_not);
p->cell(0).push_back(LM_in, LM_TC_BOPS); p->cell(0).push_back(LM_in, LM_TC_BOPS);
t->push_back(p); t->push_back(p);
insertTemplate(t); insertTemplate(t);
@ -113,7 +113,7 @@ void MathMacroTable::builtinMacros()
{ {
MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0); MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
MathAccentInset * p = new MathAccentInset(LM_not); MathDecorationInset * p = new MathDecorationInset("not", LM_not);
p->cell(0).push_back('O', LM_TC_VAR); p->cell(0).push_back('O', LM_TC_VAR);
t->push_back(p); t->push_back(p);
insertTemplate(t); insertTemplate(t);

View File

@ -35,7 +35,6 @@
#include "math_arrayinset.h" #include "math_arrayinset.h"
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "math_matrixinset.h" #include "math_matrixinset.h"
#include "math_accentinset.h"
#include "math_bigopinset.h" #include "math_bigopinset.h"
#include "math_funcinset.h" #include "math_funcinset.h"
#include "math_spaceinset.h" #include "math_spaceinset.h"
@ -94,23 +93,18 @@ const unsigned char LM_TK_CLOSE = '}';
enum { enum {
FLAG_BRACE = 1 << 0, // A { needed //} FLAG_BRACE = 1 << 0, // A { needed //}
FLAG_BRACE_OPT = 1 << 2, // Optional { //}
FLAG_BRACE_LAST = 1 << 3, // // { Last } ends the parsing process FLAG_BRACE_LAST = 1 << 3, // // { Last } ends the parsing process
FLAG_BRACK_ARG = 1 << 4, // Optional [ //]
FLAG_RIGHT = 1 << 5, // Next right ends the parsing process FLAG_RIGHT = 1 << 5, // Next right ends the parsing process
FLAG_END = 1 << 6, // Next end ends the parsing process FLAG_END = 1 << 6, // Next end ends the parsing process
FLAG_BRACE_FONT = 1 << 7, // // { Next } closes a font FLAG_BRACE_FONT = 1 << 7, // // { Next } closes a font
FLAG_BRACK_END = 1 << 9, // // [ Next ] ends the parsing process FLAG_BRACK_END = 1 << 9, // // [ Next ] ends the parsing process
FLAG_AMPERSAND = 1 << 10, // Next & ends the parsing process FLAG_AMPERSAND = 1 << 10, // Next & ends the parsing process
FLAG_NEWLINE = 1 << 11, // Next \\ ends the parsing process FLAG_NEWLINE = 1 << 11, // Next \\ ends the parsing process
FLAG_ITEM = 1 << 12, // read a (possibly braced token)
// Read a (possibly braced token) FLAG_LEAVE = 1 << 13, // marker for leaving the
FLAG_ITEM = FLAG_BRACE_OPT | FLAG_BRACE_LAST FLAG_OPTARG = 1 << 14 // reads an argument in []
}; };
}
/// ///
union { union {
/// ///
@ -157,11 +151,12 @@ int const latex_mathenv_num = sizeof(latex_mathenv)/sizeof(latex_mathenv[0]);
void mathPrintError(string const & msg) void mathPrintError(string const & msg)
{ {
lyxerr[Debug::MATHED] << "Line ~" << yylineno << ": Math parse error: " << msg << endl; //lyxerr[Debug::MATHED] << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
} }
void LexInitCodes() void lexInit()
{ {
for (int i = 0; i <= 255; ++i) { for (int i = 0; i <= 255; ++i) {
if (isdigit(i)) if (isdigit(i))
@ -196,39 +191,43 @@ void LexInitCodes()
} }
unsigned char LexGetArg(unsigned char lf, bool accept_spaces = false) string lexArg(unsigned char lf, bool accept_spaces = false)
{ {
string result;
unsigned char c = 0;
while (yyis->good()) { while (yyis->good()) {
unsigned char c = getuchar(yyis); c = getuchar(yyis);
if (c > ' ') { if (!isspace(c))
if (!lf)
lf = c;
else if (c != lf) {
lyxerr[Debug::MATHED] << "Math parse error: unexpected '" << c << "'" << endl;
return '\0';
}
break; break;
} }
if (c != lf) {
yyis->putback(c);
return result;
} }
unsigned char rg = 0; unsigned char rg = 0;
if (lf == '{') rg = '}'; if (lf == '{') rg = '}';
if (lf == '[') rg = ']'; if (lf == '[') rg = ']';
if (lf == '(') rg = ')'; if (lf == '(') rg = ')';
if (!rg) { if (!rg) {
lyxerr[Debug::MATHED] << "Math parse error: unknown bracket '" << lf << "'" << endl; lyxerr[Debug::MATHED] << "Math parse error: unknown bracket '"
return '\0'; << lf << "'" << endl;
return result;
} }
yytext.erase();
int bcnt = 1; int depth = 1;
do { do {
unsigned char c = getuchar(yyis); unsigned char c = getuchar(yyis);
if (c == lf) ++bcnt; if (c == lf)
if (c == rg) --bcnt; ++depth;
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0) if (c == rg)
yytext += c; --depth;
} while (bcnt > 0 && yyis->good()); if ((!isspace(c) || (c == ' ' && accept_spaces)) && depth > 0)
result += c;
} while (depth > 0 && yyis->good());
return rg; return result;
} }
@ -237,7 +236,7 @@ int yylex()
static bool init_done = false; static bool init_done = false;
if (!init_done) { if (!init_done) {
LexInitCodes(); lexInit();
init_done = true; init_done = true;
} }
@ -317,15 +316,15 @@ int yylex()
} }
if (yyis->good()) if (yyis->good())
yyis->putback(c); yyis->putback(c);
lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n"; //lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n";
latexkeys const * l = in_word_set(yytext); latexkeys const * l = in_word_set(yytext);
if (!l) if (!l)
return LM_TK_UNDEF; return LM_TK_UNDEF;
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) { if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
LexGetArg('{'); string name = lexArg('{');
int i = 0; int i = 0;
while (i < latex_mathenv_num && yytext != latex_mathenv[i].name) while (i < latex_mathenv_num && name != latex_mathenv[i].name)
++i; ++i;
yylval.i = i; yylval.i = i;
} else if (l->token == LM_TK_SPACE) } else if (l->token == LM_TK_SPACE)
@ -412,36 +411,30 @@ MathInset * mathed_parse()
switch (t) { switch (t) {
case LM_TK_NEWCOMMAND: { case LM_TK_NEWCOMMAND: {
LexGetArg('{'); string name = lexArg('{').substr(1);
string name = yytext.substr(1); string arg = lexArg('[');
int narg = arg.empty() ? 0 : atoi(arg.c_str());
int na = 0; p = new MathMacroTemplate(name, narg);
unsigned char const c = yyis->peek();
if (c == '[') {
LexGetArg('[');
na = atoi(yytext.c_str());
}
p = new MathMacroTemplate(name, na);
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
lyxerr[Debug::MATHED] << "LM_TK_NEWCOMMAND: name: " << name << " na: " << na << "\n"; //lyxerr[Debug::MATHED] << "LM_TK_NEWCOMMAND: name: "
// << name << " nargs: " << narg << "\n";
break; break;
} }
case LM_TK_BEGIN: { case LM_TK_BEGIN: {
int i = yylval.i; int i = yylval.i;
lyxerr[Debug::MATHED] << "reading math environment " << i << " " //lyxerr[Debug::MATHED] << "reading math environment " << i << " "
<< latex_mathenv[i].name << "\n"; // << latex_mathenv[i].name << "\n";
MathInsetTypes typ = latex_mathenv[i].typ; MathInsetTypes typ = latex_mathenv[i].typ;
p = new MathMatrixInset(typ); p = new MathMatrixInset(typ);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
switch (typ) { switch (typ) {
case LM_OT_SIMPLE: { case LM_OT_SIMPLE: {
curr_num = latex_mathenv[i].numbered; curr_num = latex_mathenv[i].numbered;
curr_label = string(); curr_label = string();
mathed_parse(p->cell(0), 0); mathed_parse(m->cell(0), 0);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
m->numbered(0, curr_num); m->numbered(0, curr_num);
m->label(0, curr_label); m->label(0, curr_label);
break; break;
@ -450,24 +443,26 @@ MathInset * mathed_parse()
case LM_OT_EQUATION: { case LM_OT_EQUATION: {
curr_num = latex_mathenv[i].numbered; curr_num = latex_mathenv[i].numbered;
curr_label = string(); curr_label = string();
mathed_parse(p->cell(0), FLAG_END); mathed_parse(m->cell(0), FLAG_END);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
m->numbered(0, curr_num); m->numbered(0, curr_num);
m->label(0, curr_label); m->label(0, curr_label);
break; break;
} }
case LM_OT_EQNARRAY: { case LM_OT_EQNARRAY: {
mathed_parse_lines(p, 3, latex_mathenv[i].numbered, true); mathed_parse_lines(m, 3, latex_mathenv[i].numbered, true);
break;
}
case LM_OT_ALIGN: {
m->halign(lexArg('{'));
mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
break; break;
} }
case LM_OT_ALIGNAT: { case LM_OT_ALIGNAT: {
LexGetArg('{'); m->halign(lexArg('{'));
//int c = atoi(yytext.c_str()); mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
lyxerr[Debug::MATHED] << "LM_OT_ALIGNAT: not implemented\n";
mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true);
lyxerr[Debug::MATHED] << "LM_OT_ALIGNAT: par: " << *p << "\n";
break; break;
} }
@ -488,9 +483,6 @@ MathInset * mathed_parse()
} }
namespace {
void handle_frac(MathArray & array, string const & name) void handle_frac(MathArray & array, string const & name)
{ {
MathFracInset * p = new MathFracInset(name); MathFracInset * p = new MathFracInset(name);
@ -511,18 +503,31 @@ void mathed_parse(MathArray & array, unsigned flags)
++plevel; ++plevel;
while (t) { while (t) {
//lyxerr << "t: " << t << " flags: " << flags; //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << " "
// << " plevel: " << plevel << " ";
//array.dump(lyxerr); //array.dump(lyxerr);
//lyxerr << "\n"; //lyxerr << "\n";
if (flags & FLAG_ITEM) {
flags &= ~FLAG_ITEM;
if (t == LM_TK_OPEN) {
// skip the brace and regard everything to the next matching
// closing brace
t = yylex();
++brace;
flags |= FLAG_BRACE_LAST;
} else {
// regard only this single token
flags |= FLAG_LEAVE;
}
}
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) { if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
if (!(flags & FLAG_BRACK_ARG) || t != '[') {
mathPrintError( mathPrintError(
"Expected {. Maybe you forgot to enclose an argument in {}"); "Expected {. Maybe you forgot to enclose an argument in {}");
panic = true; panic = true;
break; break;
} }
}
switch (t) { switch (t) {
@ -544,11 +549,6 @@ void mathed_parse(MathArray & array, unsigned flags)
case LM_TK_OPEN: case LM_TK_OPEN:
++brace; ++brace;
if (flags & FLAG_BRACE_OPT) {
flags &= ~FLAG_BRACE_OPT;
flags |= FLAG_BRACE;
}
if (flags & FLAG_BRACE) if (flags & FLAG_BRACE)
flags &= ~FLAG_BRACE; flags &= ~FLAG_BRACE;
else else
@ -567,31 +567,20 @@ void mathed_parse(MathArray & array, unsigned flags)
flags &= ~FLAG_BRACE_FONT; flags &= ~FLAG_BRACE_FONT;
break; break;
} }
if (brace == 0 && (flags & FLAG_BRACE_LAST)) { if (brace == 0 && (flags & FLAG_BRACE_LAST))
--plevel; flags |= FLAG_LEAVE;
return; else
}
array.push_back('}', LM_TC_TEX); array.push_back('}', LM_TC_TEX);
break; break;
case '[': case '[':
if (flags & FLAG_BRACK_ARG) {
flags &= ~FLAG_BRACK_ARG;
unsigned char const rg = LexGetArg('[');
if (rg != ']') {
mathPrintError("Expected ']'");
panic = true;
break;
}
} else
array.push_back('[', LM_TC_CONST); array.push_back('[', LM_TC_CONST);
break; break;
case ']': case ']':
if (flags & FLAG_BRACK_END) { if (flags & FLAG_BRACK_END)
--plevel; flags |= FLAG_LEAVE;
return; else
}
array.push_back(']', LM_TC_CONST); array.push_back(']', LM_TC_CONST);
break; break;
@ -735,18 +724,11 @@ void mathed_parse(MathArray & array, unsigned flags)
} }
case LM_TK_WIDE: case LM_TK_DECORATION:
{ {
MathDecorationInset * p = new MathDecorationInset(yylval.l->id); MathDecorationInset * p
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); = new MathDecorationInset(yylval.l->name, yylval.l->id);
array.push_back(p); mathed_parse(p->cell(0), FLAG_ITEM);
break;
}
case LM_TK_ACCENT:
{
MathAccentInset * p = new MathAccentInset(yylval.l->id);
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
array.push_back(p); array.push_back(p);
break; break;
} }
@ -757,9 +739,6 @@ void mathed_parse(MathArray & array, unsigned flags)
case LM_TK_PMOD: case LM_TK_PMOD:
case LM_TK_FUNC: case LM_TK_FUNC:
//if (accent)
// array.push_back(t, LM_TC_CONST);
//else
array.push_back(new MathFuncInset(yylval.l->name)); array.push_back(new MathFuncInset(yylval.l->name));
break; break;
@ -788,22 +767,17 @@ void mathed_parse(MathArray & array, unsigned flags)
MathInsetTypes typ = latex_mathenv[i].typ; MathInsetTypes typ = latex_mathenv[i].typ;
if (typ == LM_OT_MATRIX) { if (typ == LM_OT_MATRIX) {
string valign = "\0"; string valign = lexArg('[') + 'c';
unsigned char rg = LexGetArg(0); string halign = lexArg('{');
if (rg == ']') { //lyxerr << "valign: '" << valign << "'\n";
valign = yytext; //lyxerr << "halign: '" << halign << "'\n";
rg = LexGetArg('{'); MathArrayInset * m = new MathArrayInset(halign.size(), 1);
} m->valign(valign[0]);
m->halign(halign);
string halign = yytext; mathed_parse_lines(m, halign.size(), latex_mathenv[i].numbered, false);
MathArrayInset * mm = new MathArrayInset(halign.size(), 1); array.push_back(m);
valign += 'c'; //lyxerr << "read matrix " << *m << "\n";
mm->valign(valign[0]);
mm->halign(halign);
mathed_parse_lines(mm, halign.size(), latex_mathenv[i].numbered, false);
array.push_back(mm);
//lyxerr << "read matrix " << *mm << "\n";
break; break;
} else } else
lyxerr[Debug::MATHED] << "unknow math inset " << typ << "\n"; lyxerr[Debug::MATHED] << "unknow math inset " << typ << "\n";
@ -815,19 +789,8 @@ void mathed_parse(MathArray & array, unsigned flags)
break; break;
case LM_TK_LABEL: case LM_TK_LABEL:
{ curr_label = lexArg('{', true);
unsigned char const rg = LexGetArg('\0', true);
if (rg != '}') {
mathPrintError("Expected '{'");
// debug info
lyxerr[Debug::MATHED] << "[" << yytext << "]" << endl;
panic = true;
break; break;
}
//lyxerr << " setting label to " << yytext << "\n";
curr_label = yytext;
break;
}
default: default:
mathPrintError("Unrecognized token"); mathPrintError("Unrecognized token");
@ -836,6 +799,11 @@ void mathed_parse(MathArray & array, unsigned flags)
} // end of big switch } // end of big switch
if (flags & FLAG_LEAVE) {
flags &= ~FLAG_LEAVE;
break;
}
if (panic) { if (panic) {
lyxerr << " Math Panic, expect problems!" << endl; lyxerr << " Math Panic, expect problems!" << endl;
// Search for the end command. // Search for the end command.
@ -845,10 +813,6 @@ void mathed_parse(MathArray & array, unsigned flags)
} else } else
t = yylex(); t = yylex();
if (flags & FLAG_BRACE_OPT) {
flags &= ~FLAG_BRACE_OPT;
break;
}
} }
--plevel; --plevel;
} }

View File

@ -63,9 +63,7 @@ enum MathTokenEnum
/// ///
LM_TK_RIGHT, LM_TK_RIGHT,
/// ///
LM_TK_ACCENT, LM_TK_DECORATION,
///
LM_TK_WIDE,
/// ///
LM_TK_FUNC, LM_TK_FUNC,
/// ///

View File

@ -159,7 +159,7 @@ void MathUpDownInset::Metrics(MathStyles st, int asc, int des)
// we assume that asc, des, wid are the metrics of the item in front // we assume that asc, des, wid are the metrics of the item in front
// of this MathScriptInset // of this MathScriptInset
width_ = std::max(xcell(0).width(), xcell(1).width()); width_ = std::max(xcell(0).width(), xcell(1).width());
ascent_ = up() ? xcell(0).height() + 9 : 0; ascent_ = up() ? xcell(0).height() + asc : 0;
descent_ = down() ? xcell(1).height() : 0; descent_ = down() ? xcell(1).height() : 0;
dy0_ = - asc - xcell(0).descent(); dy0_ = - asc - xcell(0).descent();
dy1_ = des + xcell(1).ascent(); dy1_ = des + xcell(1).ascent();