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 \
math_arrayinset.C \
math_arrayinset.h \
math_accentinset.C \
math_accentinset.h \
math_bigopinset.C \
math_bigopinset.h \
math_cursor.C \

View File

@ -77,10 +77,10 @@ void handleFont(BufferView * bv, MathTextCodes t)
mathcursor->handleFont(t);
}
void handleAccent(BufferView * bv, int code)
void handleAccent(BufferView * bv, string const & name, int code)
{
bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->handleAccent(code);
mathcursor->handleAccent(name, code);
}
void handleDelim(BufferView * bv, int l, int r)
@ -636,16 +636,16 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
// --- accented characters ------------------------------
case LFUN_UMLAUT: handleAccent(bv, LM_ddot); break;
case LFUN_CIRCUMFLEX: handleAccent(bv, LM_hat); break;
case LFUN_GRAVE: handleAccent(bv, LM_grave); break;
case LFUN_ACUTE: handleAccent(bv, LM_acute); break;
case LFUN_TILDE: handleAccent(bv, LM_tilde); break;
case LFUN_MACRON: handleAccent(bv, LM_bar); break;
case LFUN_DOT: handleAccent(bv, LM_dot); break;
case LFUN_CARON: handleAccent(bv, LM_check); break;
case LFUN_BREVE: handleAccent(bv, LM_breve); break;
case LFUN_VECTOR: handleAccent(bv, LM_vec); break;
case LFUN_UMLAUT: handleAccent(bv, "ddot", LM_ddot); break;
case LFUN_CIRCUMFLEX: handleAccent(bv, "hat", LM_hat); break;
case LFUN_GRAVE: handleAccent(bv, "grave", LM_grave); break;
case LFUN_ACUTE: handleAccent(bv, "acute", LM_acute); break;
case LFUN_TILDE: handleAccent(bv, "tilde", LM_tilde); break;
case LFUN_MACRON: handleAccent(bv, "bar", LM_bar); break;
case LFUN_DOT: handleAccent(bv, "dot", LM_dot); break;
case LFUN_CARON: handleAccent(bv, "check", LM_check); break;
case LFUN_BREVE: handleAccent(bv, "breve", LM_breve); break;
case LFUN_VECTOR: handleAccent(bv, "vec", LM_vec); break;
// Greek mode
case LFUN_GREEK:
@ -724,7 +724,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
int ilt = '(';
int irt = '.';
static const string vdelim("(){}[]./|");
lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
//lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
if (arg.empty())
break;
@ -733,8 +733,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string lt;
string rt;
is >> lt >> rt;
lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
//lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
//lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
if (lt.size() > 1) {
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_dotsinset.h"
#include "math_deliminset.h"
#include "math_accentinset.h"
#include "math_macrotemplate.h"
#include "math_sqrtinset.h"
#include "math_scriptinset.h"
@ -66,12 +65,11 @@ bool IsMacro(short tok, int id)
return tok != LM_TK_STACK &&
tok != LM_TK_FRAC &&
tok != LM_TK_SQRT &&
tok != LM_TK_WIDE &&
tok != LM_TK_DECORATION &&
tok != LM_TK_SPACE &&
tok != LM_TK_DOTS &&
tok != LM_TK_FUNCLIM &&
tok != LM_TK_BIGSYM &&
tok != LM_TK_ACCENT &&
!(tok == LM_TK_SYM && id < 255);
}
@ -638,8 +636,8 @@ in_word_set(s) << " \n";
p = new MathSqrtInset;
break;
case LM_TK_WIDE:
p = new MathDecorationInset(l->id);
case LM_TK_DECORATION:
p = new MathDecorationInset(l->name, l->id);
break;
case LM_TK_FUNCLIM:
@ -654,10 +652,6 @@ in_word_set(s) << " \n";
p = new MathDotsInset(l->name, l->id);
break;
case LM_TK_ACCENT:
p = new MathAccentInset(l->id);
break;
case LM_TK_MACRO:
p = new MathMacro(MathMacroTable::provideTemplate(s));
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) {
SelCut();
p->cell(0) = selarray;
}
insert(p);
push(p, true);
}
void MathCursor::handleDelim(int l, int r)
@ -902,6 +897,7 @@ void MathCursor::handleDelim(int l, int r)
p->cell(0) = selarray;
}
insert(p);
push(p, true);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@
#include "math_macrotemplate.h"
#include "math_parser.h"
#include "array.h"
#include "math_accentinset.h"
#include "math_decorationinset.h"
#include "math_deliminset.h"
#include "math_fracinset.h"
#include "math_inset.h"
@ -94,7 +94,7 @@ void MathMacroTable::builtinMacros()
// This macro doesn't have arguments
{
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);
t->push_back(p);
insertTemplate(t);
@ -113,7 +113,7 @@ void MathMacroTable::builtinMacros()
{
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);
t->push_back(p);
insertTemplate(t);

View File

@ -35,7 +35,6 @@
#include "math_arrayinset.h"
#include "math_sqrtinset.h"
#include "math_matrixinset.h"
#include "math_accentinset.h"
#include "math_bigopinset.h"
#include "math_funcinset.h"
#include "math_spaceinset.h"
@ -94,23 +93,18 @@ const unsigned char LM_TK_CLOSE = '}';
enum {
FLAG_BRACE = 1 << 0, // A { needed //}
FLAG_BRACE_OPT = 1 << 2, // Optional { //}
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_END = 1 << 6, // Next end ends the parsing process
FLAG_BRACE_FONT = 1 << 7, // // { Next } closes a font
FLAG_BRACK_END = 1 << 9, // // [ Next ] ends the parsing process
FLAG_AMPERSAND = 1 << 10, // Next & ends the parsing process
FLAG_NEWLINE = 1 << 11, // Next \\ ends the parsing process
// Read a (possibly braced token)
FLAG_ITEM = FLAG_BRACE_OPT | FLAG_BRACE_LAST
FLAG_ITEM = 1 << 12, // read a (possibly braced token)
FLAG_LEAVE = 1 << 13, // marker for leaving the
FLAG_OPTARG = 1 << 14 // reads an argument in []
};
}
///
union {
///
@ -157,11 +151,12 @@ int const latex_mathenv_num = sizeof(latex_mathenv)/sizeof(latex_mathenv[0]);
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) {
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()) {
unsigned char c = getuchar(yyis);
if (c > ' ') {
if (!lf)
lf = c;
else if (c != lf) {
lyxerr[Debug::MATHED] << "Math parse error: unexpected '" << c << "'" << endl;
return '\0';
}
c = getuchar(yyis);
if (!isspace(c))
break;
}
}
if (c != lf) {
yyis->putback(c);
return result;
}
unsigned char rg = 0;
if (lf == '{') rg = '}';
if (lf == '[') rg = ']';
if (lf == '(') rg = ')';
if (!rg) {
lyxerr[Debug::MATHED] << "Math parse error: unknown bracket '" << lf << "'" << endl;
return '\0';
lyxerr[Debug::MATHED] << "Math parse error: unknown bracket '"
<< lf << "'" << endl;
return result;
}
yytext.erase();
int bcnt = 1;
int depth = 1;
do {
unsigned char c = getuchar(yyis);
if (c == lf) ++bcnt;
if (c == rg) --bcnt;
if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt > 0)
yytext += c;
} while (bcnt > 0 && yyis->good());
if (c == lf)
++depth;
if (c == rg)
--depth;
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;
if (!init_done) {
LexInitCodes();
lexInit();
init_done = true;
}
@ -317,15 +316,15 @@ int yylex()
}
if (yyis->good())
yyis->putback(c);
lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n";
//lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n";
latexkeys const * l = in_word_set(yytext);
if (!l)
return LM_TK_UNDEF;
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
LexGetArg('{');
string name = lexArg('{');
int i = 0;
while (i < latex_mathenv_num && yytext != latex_mathenv[i].name)
while (i < latex_mathenv_num && name != latex_mathenv[i].name)
++i;
yylval.i = i;
} else if (l->token == LM_TK_SPACE)
@ -412,36 +411,30 @@ MathInset * mathed_parse()
switch (t) {
case LM_TK_NEWCOMMAND: {
LexGetArg('{');
string name = yytext.substr(1);
int na = 0;
unsigned char const c = yyis->peek();
if (c == '[') {
LexGetArg('[');
na = atoi(yytext.c_str());
}
p = new MathMacroTemplate(name, na);
string name = lexArg('{').substr(1);
string arg = lexArg('[');
int narg = arg.empty() ? 0 : atoi(arg.c_str());
p = new MathMacroTemplate(name, narg);
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;
}
case LM_TK_BEGIN: {
int i = yylval.i;
lyxerr[Debug::MATHED] << "reading math environment " << i << " "
<< latex_mathenv[i].name << "\n";
//lyxerr[Debug::MATHED] << "reading math environment " << i << " "
// << latex_mathenv[i].name << "\n";
MathInsetTypes typ = latex_mathenv[i].typ;
p = new MathMatrixInset(typ);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
switch (typ) {
case LM_OT_SIMPLE: {
curr_num = latex_mathenv[i].numbered;
curr_label = string();
mathed_parse(p->cell(0), 0);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
mathed_parse(m->cell(0), 0);
m->numbered(0, curr_num);
m->label(0, curr_label);
break;
@ -450,24 +443,26 @@ MathInset * mathed_parse()
case LM_OT_EQUATION: {
curr_num = latex_mathenv[i].numbered;
curr_label = string();
mathed_parse(p->cell(0), FLAG_END);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
mathed_parse(m->cell(0), FLAG_END);
m->numbered(0, curr_num);
m->label(0, curr_label);
break;
}
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;
}
case LM_OT_ALIGNAT: {
LexGetArg('{');
//int c = atoi(yytext.c_str());
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";
m->halign(lexArg('{'));
mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
break;
}
@ -488,9 +483,6 @@ MathInset * mathed_parse()
}
namespace {
void handle_frac(MathArray & array, string const & name)
{
MathFracInset * p = new MathFracInset(name);
@ -502,7 +494,7 @@ void handle_frac(MathArray & array, string const & name)
void mathed_parse(MathArray & array, unsigned flags)
{
int t = yylex();
int t = yylex();
bool panic = false;
static int plevel = -1;
yyvarcode = LM_TC_VAR;
@ -511,19 +503,32 @@ void mathed_parse(MathArray & array, unsigned flags)
++plevel;
while (t) {
//lyxerr << "t: " << t << " flags: " << flags;
//lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << " "
// << " plevel: " << plevel << " ";
//array.dump(lyxerr);
//lyxerr << "\n";
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
if (!(flags & FLAG_BRACK_ARG) || t != '[') {
mathPrintError(
"Expected {. Maybe you forgot to enclose an argument in {}");
panic = true;
break;
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) {
mathPrintError(
"Expected {. Maybe you forgot to enclose an argument in {}");
panic = true;
break;
}
switch (t) {
case LM_TK_ALPHA:
@ -544,11 +549,6 @@ void mathed_parse(MathArray & array, unsigned flags)
case LM_TK_OPEN:
++brace;
if (flags & FLAG_BRACE_OPT) {
flags &= ~FLAG_BRACE_OPT;
flags |= FLAG_BRACE;
}
if (flags & FLAG_BRACE)
flags &= ~FLAG_BRACE;
else
@ -567,32 +567,21 @@ void mathed_parse(MathArray & array, unsigned flags)
flags &= ~FLAG_BRACE_FONT;
break;
}
if (brace == 0 && (flags & FLAG_BRACE_LAST)) {
--plevel;
return;
}
array.push_back('}', LM_TC_TEX);
if (brace == 0 && (flags & FLAG_BRACE_LAST))
flags |= FLAG_LEAVE;
else
array.push_back('}', LM_TC_TEX);
break;
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;
case ']':
if (flags & FLAG_BRACK_END) {
--plevel;
return;
}
array.push_back(']', LM_TC_CONST);
if (flags & FLAG_BRACK_END)
flags |= FLAG_LEAVE;
else
array.push_back(']', LM_TC_CONST);
break;
case '^':
@ -673,7 +662,7 @@ void mathed_parse(MathArray & array, unsigned flags)
break;
case LM_TK_SQRT:
{
{
unsigned char c = getuchar(yyis);
if (c == '[') {
array.push_back(new MathRootInset);
@ -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);
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
array.push_back(p);
break;
}
case LM_TK_ACCENT:
{
MathAccentInset * p = new MathAccentInset(yylval.l->id);
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
MathDecorationInset * p
= new MathDecorationInset(yylval.l->name, yylval.l->id);
mathed_parse(p->cell(0), FLAG_ITEM);
array.push_back(p);
break;
}
@ -757,10 +739,7 @@ void mathed_parse(MathArray & array, unsigned flags)
case LM_TK_PMOD:
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;
case LM_TK_FUNCLIM:
@ -788,22 +767,17 @@ void mathed_parse(MathArray & array, unsigned flags)
MathInsetTypes typ = latex_mathenv[i].typ;
if (typ == LM_OT_MATRIX) {
string valign = "\0";
unsigned char rg = LexGetArg(0);
if (rg == ']') {
valign = yytext;
rg = LexGetArg('{');
}
string valign = lexArg('[') + 'c';
string halign = lexArg('{');
//lyxerr << "valign: '" << valign << "'\n";
//lyxerr << "halign: '" << halign << "'\n";
MathArrayInset * m = new MathArrayInset(halign.size(), 1);
m->valign(valign[0]);
m->halign(halign);
string halign = yytext;
MathArrayInset * mm = new MathArrayInset(halign.size(), 1);
valign += 'c';
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";
mathed_parse_lines(m, halign.size(), latex_mathenv[i].numbered, false);
array.push_back(m);
//lyxerr << "read matrix " << *m << "\n";
break;
} else
lyxerr[Debug::MATHED] << "unknow math inset " << typ << "\n";
@ -815,19 +789,8 @@ void mathed_parse(MathArray & array, unsigned flags)
break;
case LM_TK_LABEL:
{
unsigned char const rg = LexGetArg('\0', true);
if (rg != '}') {
mathPrintError("Expected '{'");
// debug info
lyxerr[Debug::MATHED] << "[" << yytext << "]" << endl;
panic = true;
break;
}
//lyxerr << " setting label to " << yytext << "\n";
curr_label = yytext;
curr_label = lexArg('{', true);
break;
}
default:
mathPrintError("Unrecognized token");
@ -835,7 +798,12 @@ void mathed_parse(MathArray & array, unsigned flags)
break;
} // end of big switch
if (flags & FLAG_LEAVE) {
flags &= ~FLAG_LEAVE;
break;
}
if (panic) {
lyxerr << " Math Panic, expect problems!" << endl;
// Search for the end command.
@ -844,11 +812,7 @@ void mathed_parse(MathArray & array, unsigned flags)
} while (t != LM_TK_END && t);
} else
t = yylex();
if (flags & FLAG_BRACE_OPT) {
flags &= ~FLAG_BRACE_OPT;
break;
}
}
--plevel;
}

View File

@ -63,9 +63,7 @@ enum MathTokenEnum
///
LM_TK_RIGHT,
///
LM_TK_ACCENT,
///
LM_TK_WIDE,
LM_TK_DECORATION,
///
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
// of this MathScriptInset
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;
dy0_ = - asc - xcell(0).descent();
dy1_ = des + xcell(1).ascent();