mathcursor->handleFont(t);
}
-void handleAccent(BufferView * bv, string const & name, int code)
+void handleAccent(BufferView * bv, string const & name)
{
bv->lockedInsetStoreUndo(Undo::EDIT);
- mathcursor->handleAccent(name, code);
+ mathcursor->handleAccent(name);
}
void handleDelim(BufferView * bv, int l, int r)
// --- accented characters ------------------------------
- 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;
+ case LFUN_UMLAUT: handleAccent(bv, "ddot"); break;
+ case LFUN_CIRCUMFLEX: handleAccent(bv, "hat"); break;
+ case LFUN_GRAVE: handleAccent(bv, "grave"); break;
+ case LFUN_ACUTE: handleAccent(bv, "acute"); break;
+ case LFUN_TILDE: handleAccent(bv, "tilde"); break;
+ case LFUN_MACRON: handleAccent(bv, "bar"); break;
+ case LFUN_DOT: handleAccent(bv, "dot"); break;
+ case LFUN_CARON: handleAccent(bv, "check"); break;
+ case LFUN_BREVE: handleAccent(bv, "breve"); break;
+ case LFUN_VECTOR: handleAccent(bv, "vec"); break;
// Greek mode
case LFUN_GREEK:
break;
case LM_TK_DECORATION:
- p = new MathDecorationInset(l->name, l->id);
+ p = new MathDecorationInset(l);
break;
case LM_TK_SPACE:
break;
case LM_TK_DOTS:
- p = new MathDotsInset(l->name, l->id);
+ p = new MathDotsInset(l);
break;
case LM_TK_MACRO:
}
-void MathCursor::handleAccent(string const & name, int code)
+void MathCursor::handleAccent(string const & name)
{
- MathDecorationInset * p = new MathDecorationInset(name, code);
+ latexkeys const * l = in_word_set(name);
+ if (!l)
+ return;
+
+ MathDecorationInset * p = new MathDecorationInset(l);
if (selection_) {
selCut();
p->cell(0) = theSelection.glue();
///
void handleFont(MathTextCodes t);
///
- void handleAccent(string const & name, int code);
+ void handleAccent(string const & name);
///
void handleDelim(int l, int r);
/// Splits cells and shifts right part to the next cell
using std::ostream;
-MathDecorationInset::MathDecorationInset(string const & name, int d)
- : MathInset(1, name), deco_(d)
+MathDecorationInset::MathDecorationInset(latexkeys const * key)
+ : MathInset(1), key_(key)
{
- upper_ = deco_ != LM_underline && deco_ != LM_underbrace;
+ upper_ = key_->id != LM_underline && key_->id != LM_underbrace;
}
descent_ += dh_ + 2;
}
- if (deco_ == LM_not) {
+ if (key_->id == LM_not) {
ascent_ += dh_;
descent_ += dh_;
dh_ = height();
xo(x);
yo(x);
xcell(0).draw(pain, x, y);
- mathed_draw_deco(pain, x, y + dy_, width_, dh_, deco_);
+ mathed_draw_deco(pain, x, y + dy_, width_, dh_, key_->id);
}
void MathDecorationInset::write(ostream & os, bool fragile) const
{
+ string name = key_->name;
if (fragile &&
- (name_ == "overbrace" ||
- name_ == "underbrace" ||
- name_ == "overleftarrow" ||
- name_ == "overrightarrow"))
+ (name == "overbrace" ||
+ name == "underbrace" ||
+ name == "overleftarrow" ||
+ name == "overrightarrow"))
os << "\\protect";
- os << '\\' << name_;
+ os << '\\' << name;
- if (deco_ == LM_not)
+ if (key_->id == LM_not)
os << ' ';
else
os << '{';
cell(0).write(os, fragile);
- if (deco_ != LM_not)
+ if (key_->id != LM_not)
os << '}';
}
void MathDecorationInset::writeNormal(ostream & os) const
{
- os << "[" << name_ << " ";
+ os << "[" << key_->name << " ";
cell(0).writeNormal(os);
os << "] ";
}
/** Decorations and accents over (below) a math object
\author Alejandro Aguilar Sierra
*/
+
+struct latexkeys;
+
class MathDecorationInset : public MathInset {
public:
///
- MathDecorationInset(string const & name, int);
+ explicit MathDecorationInset(latexkeys const *);
///
MathInset * clone() const;
///
void writeNormal(std::ostream & os) const;
private:
///
- int deco_;
+ latexkeys const * key_;
///
bool upper_;
/// height of deco
#include "math_dotsinset.h"
#include "mathed/support.h"
+#include "mathed/math_parser.h"
#include "support/LOstream.h"
using std::ostream;
-MathDotsInset::MathDotsInset(string const & name, int id)
- : MathInset(0, name), code_(id)
+MathDotsInset::MathDotsInset(latexkeys const * key)
+ : key_(key)
{}
void MathDotsInset::draw(Painter & pain, int x, int y)
{
- mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, code_);
- if (code_ == LM_vdots || code_ == LM_ddots)
+ mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id);
+ if (key_->id == LM_vdots || key_->id == LM_ddots)
++x;
- if (code_ != LM_vdots)
+ if (key_->id != LM_vdots)
--y;
- mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, code_);
+ mathed_draw_deco(pain, x + 2, y - dh_, width_ - 2, ascent_, key_->id);
}
{
size(st);
mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);
- switch (code_) {
+ switch (key_->id) {
case LM_ldots: dh_ = 0; break;
- case LM_cdots: dh_ = ascent_/2; break;
+ case LM_cdots: dh_ = ascent_ / 2; break;
case LM_vdots: width_ /= 2;
case LM_ddots: dh_ = ascent_; break;
}
void MathDotsInset::write(ostream & os, bool /* fragile */) const
{
- os << '\\' << name() << ' ';
+ os << '\\' << key_->name << ' ';
}
void MathDotsInset::writeNormal(ostream & os) const
{
- os << "[" << name() << "] ";
+ os << "[" << key_->name << "] ";
}
#pragma interface
#endif
+struct latexkeys;
+
/// The different kinds of ellipsis
class MathDotsInset : public MathInset {
public:
///
- MathDotsInset(string const &, int);
+ explicit MathDotsInset(latexkeys const *);
///
- MathInset * clone() const;
+ MathInset * clone() const;
///
void draw(Painter &, int, int);
///
///
int dh_;
///
- int code_;
+ latexkeys const * key_;
};
#endif
using std::endl;
+MathArray mathed_parse_cell(string const &);
+
+
MathMacroTable::table_type MathMacroTable::macro_table;
}
+void MathMacroTable::createTemplate
+ (string const & name, int na, string const & text)
+{
+ MathMacroTemplate * t = new MathMacroTemplate(name, na);
+ t->cell(0) = mathed_parse_cell(text);
+ insertTemplate(t);
+}
+
+
bool MathMacroTable::hasTemplate(string const & name)
{
builtinMacros();
built = true;
lyxerr[Debug::MATHED] << "Building macros" << endl;
-
+
+/*
// This macro doesn't have arguments
{
MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
- MathDecorationInset * p = new MathDecorationInset("not", LM_not);
+ MathDecorationInset * p = new MathDecorationInset("not");
p->cell(0).push_back(LM_in, LM_TC_SYMB);
t->push_back(p);
insertTemplate(t);
}
-
-/*
- // This macro doesn't have arguments
- {
- MathMacroTemplate & m = createTemplate("silentmult", 0);
- istringstream is("\\cdot\0");
- mathed_parser_file(is, 0);
- MathMatrixInset * p = &m;
- mathed_parse(m.array, p, 0);
- }
*/
+ createTemplate("silentmult", 0, "\\cdot");
+ createTemplate("emptyset", 0, "\\not0");
+ createTemplate("notin", 0, "\\not\\in");
+
+
+
+/*
{
MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
MathDecorationInset * p = new MathDecorationInset("not", LM_not);
t->push_back(p);
insertTemplate(t);
}
+*/
{
+
MathMacroTemplate * t = new MathMacroTemplate("land", 0);
t->push_back(LM_wedge, LM_TC_SYMB);
insertTemplate(t);
static bool hasTemplate(string const &);
///
static MathMacro * cloneTemplate(string const &);
+ ///
+ static void createTemplate(string const &, int, string const &);
private:
///
static void builtinMacros();
}
if (lexcode[c] == LexAlpha) {
yytext.erase();
- while (lexcode[c] == LexAlpha) {
+ while (lexcode[c] == LexAlpha && yyis->good()) {
yytext += c;
c = getuchar(yyis);
}
++plevel;
while (t) {
- //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i
- // << " TK_LIMIT " << LM_TK_LIMIT << "\n";
-
+ //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << "\n";
// << " plevel: " << plevel << " ";
//array.dump(lyxerr);
//lyxerr << "\n";
break;
case LM_TK_DOTS:
- array.push_back(new MathDotsInset(yylval.l->name, yylval.l->id));
+ array.push_back(new MathDotsInset(yylval.l));
break;
case LM_TK_CHOOSE:
case LM_TK_DECORATION:
{
- MathDecorationInset * p
- = new MathDecorationInset(yylval.l->name, yylval.l->id);
+ MathDecorationInset * p = new MathDecorationInset(yylval.l);
mathed_parse(p->cell(0), FLAG_ITEM);
array.push_back(p);
break;
// Search for the end command.
do {
t = yylex();
- } while (t != LM_TK_END && t);
+ } while (yyis->good() && t != LM_TK_END && t);
} else
t = yylex();
}
+
+MathArray mathed_parse_cell(string const & str)
+{
+ istringstream is(str.c_str());
+ yyis = &is;
+ yylineno = 0;
+ MathArray ar;
+ mathed_parse(ar, 0);
+ return ar;
+}
+
+
MathInset * mathed_parse(string const & str)
{
istringstream is(str.c_str());