mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
binom is binom is binom and choose is choose is choose ...
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4528 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3fac52583e
commit
cbafd3fc82
@ -63,14 +63,23 @@ InsetFormula::InsetFormula()
|
||||
: par_(MathAtom(new MathHullInset)), loader_(0)
|
||||
{}
|
||||
|
||||
/*
|
||||
|
||||
InsetFormula::InsetFormula(string const & type)
|
||||
: par_(MathAtom(new MathHullInset(type))), loader_(0)
|
||||
{}
|
||||
InsetFormula::InsetFormula(BufferView * bv)
|
||||
: par_(MathAtom(new MathHullInset)), loader_(0)
|
||||
{
|
||||
view_ = bv;
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
InsetFormula::InsetFormula(string const & data)
|
||||
: par_(MathAtom(new MathHullInset)), loader_(0)
|
||||
{
|
||||
if (!data.size())
|
||||
return;
|
||||
if (!mathed_parse_normal(par_, data))
|
||||
lyxerr << "cannot interpret '" << data << "' as math\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
Inset * InsetFormula::clone(Buffer const &, bool) const
|
||||
@ -95,23 +104,6 @@ int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
|
||||
}
|
||||
|
||||
|
||||
void InsetFormula::read(string const & s)
|
||||
{
|
||||
if (s.size()) {
|
||||
bool res = mathed_parse_normal(par_, s);
|
||||
|
||||
if (!res)
|
||||
res = mathed_parse_normal(par_, "$" + s + "$");
|
||||
|
||||
if (!res) {
|
||||
lyxerr << "cannot interpret '" << s << "' as math\n";
|
||||
par_ = MathAtom(new MathHullInset("simple"));
|
||||
}
|
||||
}
|
||||
metrics();
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
|
||||
int InsetFormula::ascii(Buffer const *, ostream & os, int) const
|
||||
{
|
||||
@ -184,7 +176,8 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
|
||||
if (canPreview()) {
|
||||
pi.pain.image(x + 1, y - a + 1, w - 2, h - 2, *(loader_->image()));
|
||||
} else {
|
||||
pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
|
||||
//pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
|
||||
pi.base.style = LM_ST_TEXT;
|
||||
pi.base.font = font;
|
||||
pi.base.font.setColor(LColor::math);
|
||||
if (lcolor.getX11Name(LColor::mathbg)
|
||||
@ -302,7 +295,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
|
||||
int x;
|
||||
int y;
|
||||
mathcursor->getPos(x, y);
|
||||
hull()->mutate(arg);
|
||||
mutate(arg);
|
||||
mathcursor->setPos(x, y);
|
||||
mathcursor->normalize();
|
||||
updateLocal(bv, true);
|
||||
@ -326,9 +319,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
|
||||
int y = 0;
|
||||
mathcursor->getPos(x, y);
|
||||
if (hullType() == "simple")
|
||||
hull()->mutate("equation");
|
||||
mutate("equation");
|
||||
else
|
||||
hull()->mutate("simple");
|
||||
mutate("simple");
|
||||
mathcursor->setPos(x, y);
|
||||
mathcursor->normalize();
|
||||
updateLocal(bv, true);
|
||||
@ -419,15 +412,16 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
|
||||
}
|
||||
|
||||
|
||||
string const & InsetFormula::hullType() const
|
||||
string InsetFormula::hullType() const
|
||||
{
|
||||
return hull()->getType();
|
||||
return hull() ? hull()->getType() : "none";
|
||||
}
|
||||
|
||||
|
||||
void InsetFormula::mutate(string const & type )
|
||||
{
|
||||
hull()->mutate(type);
|
||||
if (hull())
|
||||
hull()->mutate(type);
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,7 +34,9 @@ public:
|
||||
///
|
||||
InsetFormula();
|
||||
///
|
||||
//explicit InsetFormula(string const & type);
|
||||
explicit InsetFormula(BufferView *);
|
||||
///
|
||||
explicit InsetFormula(const string & data);
|
||||
///
|
||||
int ascent(BufferView *, LyXFont const &) const;
|
||||
///
|
||||
@ -49,8 +51,6 @@ public:
|
||||
///
|
||||
void read(Buffer const *, LyXLex & lex);
|
||||
///
|
||||
void read(const string & data);
|
||||
///
|
||||
int latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
|
||||
///
|
||||
int ascii(Buffer const *, std::ostream &, int linelen) const;
|
||||
@ -72,7 +72,7 @@ public:
|
||||
///
|
||||
std::vector<string> const getLabelList() const;
|
||||
///
|
||||
string const & hullType() const;
|
||||
string hullType() const;
|
||||
///
|
||||
MathAtom const & par() const { return par_; }
|
||||
///
|
||||
|
@ -79,7 +79,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
|
||||
delete new_inset;
|
||||
return false;
|
||||
}
|
||||
new_inset->edit(bv, 0, 0, mouse_button::none);
|
||||
new_inset->edit(bv, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -154,7 +154,8 @@ void InsetFormulaBase::metrics(BufferView * bv) const
|
||||
view_ = bv;
|
||||
MathMetricsInfo mi;
|
||||
mi.view = view_;
|
||||
mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
|
||||
//mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
|
||||
mi.base.style = LM_ST_TEXT;
|
||||
mi.base.font = font_;
|
||||
mi.base.font.setColor(LColor::math);
|
||||
par()->metrics(mi);
|
||||
@ -227,8 +228,8 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
|
||||
bv->hideLockedInsetCursor();
|
||||
else {
|
||||
metrics(bv);
|
||||
int x;
|
||||
int y;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
mathcursor->getPos(x, y);
|
||||
y -= yo_;
|
||||
int asc = 0;
|
||||
@ -935,45 +936,44 @@ bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
|
||||
|
||||
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
|
||||
{
|
||||
if (bv->available()) {
|
||||
// use selection if available..
|
||||
//string sel;
|
||||
//if (action == LFUN_MATH_IMPORT_SELECTION)
|
||||
// sel = "";
|
||||
//else
|
||||
if (!bv->available())
|
||||
return;
|
||||
|
||||
string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
|
||||
// use selection if available..
|
||||
//string sel;
|
||||
//if (action == LFUN_MATH_IMPORT_SELECTION)
|
||||
// sel = "";
|
||||
//else
|
||||
|
||||
if (sel.empty()) {
|
||||
InsetFormula * f = new InsetFormula;
|
||||
string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
|
||||
|
||||
if (sel.empty()) {
|
||||
InsetFormula * f = new InsetFormula(bv);
|
||||
if (openNewInset(bv, f)) {
|
||||
f->mutate("simple");
|
||||
if (openNewInset(bv, f)) {
|
||||
// don't do that also for LFUN_MATH_MODE unless you want end up with
|
||||
// always changing to mathrm when opening an inlined inset
|
||||
// -- I really hate "LyXfunc overloading"...
|
||||
if (display)
|
||||
f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
|
||||
f->localDispatch(bv, LFUN_INSERT_MATH, arg);
|
||||
}
|
||||
// don't do that also for LFUN_MATH_MODE unless you want end up with
|
||||
// always changing to mathrm when opening an inlined inset
|
||||
// -- I really hate "LyXfunc overloading"...
|
||||
if (display)
|
||||
f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
|
||||
f->localDispatch(bv, LFUN_INSERT_MATH, arg);
|
||||
}
|
||||
} else {
|
||||
// create a macro if we see "\\newcommand" somewhere, and an ordinary
|
||||
// formula otherwise
|
||||
if (sel.find("\\newcommand") == string::npos &&
|
||||
sel.find("\\def") == string::npos)
|
||||
{
|
||||
InsetFormula * f = new InsetFormula(sel);
|
||||
bv->getLyXText()->cutSelection(bv);
|
||||
openNewInset(bv, f);
|
||||
} else {
|
||||
// create a macro if we see "\\newcommand" somewhere, and an ordinary
|
||||
// formula otherwise
|
||||
if (sel.find("\\newcommand") == string::npos &&
|
||||
sel.find("\\def") == string::npos)
|
||||
{
|
||||
InsetFormula * f = new InsetFormula;
|
||||
f->mutate("simple");
|
||||
f->read(sel);
|
||||
bv->getLyXText()->cutSelection(bv);
|
||||
openNewInset(bv, f);
|
||||
} else {
|
||||
string name;
|
||||
if (!mathed_parse_macro(name, sel))
|
||||
return;
|
||||
InsetFormulaMacro * f = new InsetFormulaMacro(sel);
|
||||
bv->getLyXText()->cutSelection(bv);
|
||||
openNewInset(bv, f);
|
||||
}
|
||||
string name;
|
||||
if (!mathed_parse_macro(name, sel))
|
||||
return;
|
||||
InsetFormulaMacro * f = new InsetFormulaMacro(sel);
|
||||
bv->getLyXText()->cutSelection(bv);
|
||||
openNewInset(bv, f);
|
||||
}
|
||||
}
|
||||
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
|
||||
@ -1000,67 +1000,64 @@ void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
|
||||
|
||||
void mathDispatchMathMacro(BufferView * bv, string const & arg)
|
||||
{
|
||||
if (bv->available()) {
|
||||
if (arg.empty())
|
||||
bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
|
||||
else {
|
||||
string s = arg;
|
||||
string const s1 = token(s, ' ', 1);
|
||||
int const na = s1.empty() ? 0 : lyx::atoi(s1);
|
||||
openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
|
||||
}
|
||||
if (!bv->available())
|
||||
return;
|
||||
if (arg.empty())
|
||||
bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
|
||||
else {
|
||||
string s = arg;
|
||||
string const s1 = token(s, ' ', 1);
|
||||
int const na = s1.empty() ? 0 : lyx::atoi(s1);
|
||||
openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mathDispatchMathDelim(BufferView * bv, string const & arg)
|
||||
{
|
||||
if (bv->available()) {
|
||||
InsetFormula * f = new InsetFormula;
|
||||
if (!bv->available())
|
||||
return;
|
||||
InsetFormula * f = new InsetFormula(bv);
|
||||
if (openNewInset(bv, f)) {
|
||||
f->mutate("simple");
|
||||
if (openNewInset(bv, new InsetFormula))
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
|
||||
{
|
||||
if (bv->available()) {
|
||||
InsetFormula * f = new InsetFormula;
|
||||
if (!bv->available())
|
||||
return;
|
||||
InsetFormula * f = new InsetFormula(bv);
|
||||
if (openNewInset(bv, f)) {
|
||||
f->mutate("simple");
|
||||
if (openNewInset(bv, new InsetFormula))
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mathDispatchInsertMath(BufferView * bv, string const & arg)
|
||||
{
|
||||
if (bv->available()) {
|
||||
if (arg.size() && arg[0] == '\\') {
|
||||
InsetFormula * f = new InsetFormula;
|
||||
f->read(arg);
|
||||
if (!bv->insertInset(f))
|
||||
delete f;
|
||||
else if (!mathcursor) // hotfix
|
||||
bv->getLyXText()->cursorRight(bv);
|
||||
} else {
|
||||
mathDispatchMathMode(bv, arg);
|
||||
}
|
||||
if (!bv->available())
|
||||
return;
|
||||
InsetFormula * f = new InsetFormula(bv);
|
||||
if (openNewInset(bv, f)) {
|
||||
f->mutate("simple");
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATH, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mathDispatchGreek(BufferView * bv, string const & arg)
|
||||
{
|
||||
if (bv->available()) {
|
||||
InsetFormula * f = new InsetFormula;
|
||||
if (!bv->available())
|
||||
return;
|
||||
InsetFormula * f = new InsetFormula(bv);
|
||||
if (openNewInset(bv, f)) {
|
||||
f->mutate("simple");
|
||||
if (openNewInset(bv, f)) {
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, arg);
|
||||
bv->unlockInset(f);
|
||||
}
|
||||
bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, arg);
|
||||
bv->unlockInset(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
///
|
||||
virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
|
||||
///
|
||||
virtual string const & hullType() const = 0;
|
||||
virtual string hullType() const { return "none"; }
|
||||
/// lowest x coordinate
|
||||
virtual int xlow() const;
|
||||
/// highest x coordinate
|
||||
@ -125,6 +125,7 @@ private:
|
||||
/// common base for handling accents
|
||||
void handleAccent(BufferView * bv, string const & arg, string const & name);
|
||||
|
||||
protected:
|
||||
///
|
||||
mutable BufferView * view_;
|
||||
///
|
||||
|
@ -158,13 +158,6 @@ Inset::Code InsetFormulaMacro::lyxCode() const
|
||||
}
|
||||
|
||||
|
||||
string const & InsetFormulaMacro::hullType() const
|
||||
{
|
||||
static string macro("macro");
|
||||
return macro;
|
||||
}
|
||||
|
||||
|
||||
void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
|
||||
int y, float & xx, bool /*cleared*/) const
|
||||
{
|
||||
|
@ -64,8 +64,6 @@ public:
|
||||
///
|
||||
Inset::Code lyxCode() const;
|
||||
///
|
||||
string const & hullType() const;
|
||||
///
|
||||
MathAtom const & par() const;
|
||||
///
|
||||
MathAtom & par();
|
||||
|
@ -13,7 +13,8 @@
|
||||
using std::max;
|
||||
|
||||
|
||||
MathBinomInset::MathBinomInset()
|
||||
MathBinomInset::MathBinomInset(bool choose)
|
||||
: choose_(choose)
|
||||
{}
|
||||
|
||||
|
||||
@ -58,7 +59,10 @@ void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
|
||||
|
||||
void MathBinomInset::write(WriteStream & os) const
|
||||
{
|
||||
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
|
||||
if (choose_)
|
||||
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
|
||||
else
|
||||
os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
class MathBinomInset : public MathFracbaseInset {
|
||||
public:
|
||||
///
|
||||
MathBinomInset();
|
||||
explicit MathBinomInset(bool choose = false);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
@ -28,6 +28,8 @@ public:
|
||||
private:
|
||||
///
|
||||
int dw() const;
|
||||
///
|
||||
bool choose_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -297,7 +297,7 @@ MathAtom createMathInset(string const & s)
|
||||
if (s == "stack")
|
||||
return MathAtom(new MathStackrelInset);
|
||||
if (s == "binom" || s == "choose")
|
||||
return MathAtom(new MathBinomInset);
|
||||
return MathAtom(new MathBinomInset(s == "choose"));
|
||||
if (s == "over" || s == "frac")
|
||||
return MathAtom(new MathFracInset);
|
||||
if (s == "atop")
|
||||
|
@ -107,7 +107,7 @@ private:
|
||||
/// consistency check
|
||||
void check() const;
|
||||
|
||||
/// "simple", "display", "eqnarray",...
|
||||
/// "none", "simple", "display", "eqnarray",...
|
||||
string type_;
|
||||
///
|
||||
std::vector<int> nonum_;
|
||||
|
@ -582,7 +582,10 @@ bool Parser::parse_normal(MathAtom & at)
|
||||
if (ar.size() != 1) {
|
||||
lyxerr << "Unusual contents found: " << ar << endl;
|
||||
at.reset(new MathParInset);
|
||||
at->cell(0) = ar;
|
||||
if (at->nargs() > 0)
|
||||
at->cell(0) = ar;
|
||||
else
|
||||
lyxerr << "Unusual contents found: " << ar << endl;
|
||||
return true;
|
||||
}
|
||||
at = ar[0];
|
||||
@ -690,7 +693,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
|
||||
MathArray ar;
|
||||
parse_into(ar, FLAG_BRACE_LAST, mathmode);
|
||||
// reduce multiple nesting levels to a single one
|
||||
// this helps to keep the annoyance of a choose b to a minimum
|
||||
// this helps to keep the annoyance of "a choose b" to a minimum
|
||||
if (ar.size() && ar.front()->asBraceInset())
|
||||
ar = ar.front()->asBraceInset()->cell(0);
|
||||
cell->push_back(MathAtom(new MathBraceInset));
|
||||
|
Loading…
Reference in New Issue
Block a user