Allow using \binom without amsmath and add support for \brace and \brack

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@24418 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2008-04-21 22:03:18 +00:00
parent 6bc6ca6c4d
commit aec651ca55
5 changed files with 59 additions and 13 deletions

View File

@ -14,6 +14,7 @@
#include "MathData.h"
#include "MathSupport.h"
#include "MathStream.h"
#include "LaTeXFeatures.h"
namespace lyx {
@ -23,8 +24,8 @@ using std::max;
using std::auto_ptr;
InsetMathBinom::InsetMathBinom(bool choose)
: choose_(choose)
InsetMathBinom::InsetMathBinom(Kind kind)
: kind_(kind)
{}
@ -62,29 +63,43 @@ bool InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
{
docstring const bra = kind_ == BRACE ? from_ascii("{") :
kind_ == BRACK ? from_ascii("[") : from_ascii("(");
docstring const ket = kind_ == BRACE ? from_ascii("}") :
kind_ == BRACK ? from_ascii("]") : from_ascii(")");
int m = x + dim_.width() / 2;
FracChanger dummy(pi.base);
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 3 - 5);
mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), from_ascii("("));
mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), bra);
mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
dw(), dim_.height(), from_ascii(")"));
dw(), dim_.height(), ket);
drawMarkers2(pi, x, y);
}
bool InsetMathBinom::extraBraces() const
{
return choose_;
return kind_ == CHOOSE || kind_ == BRACE || kind_ == BRACK;
}
void InsetMathBinom::write(WriteStream & os) const
{
if (choose_)
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
else
switch (kind_) {
case BINOM:
os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
break;
case CHOOSE:
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
break;
case BRACE:
os << '{' << cell(0) << " \\brace " << cell(1) << '}';
break;
case BRACK:
os << '{' << cell(0) << " \\brack " << cell(1) << '}';
break;
}
}
@ -94,4 +109,13 @@ void InsetMathBinom::normalize(NormalStream & os) const
}
void InsetMathBinom::validate(LaTeXFeatures & features) const
{
if (kind_ == BINOM) {
features.require("binom");
InsetMathNest::validate(features);
}
}
} // namespace lyx

View File

@ -22,7 +22,15 @@ namespace lyx {
class InsetMathBinom : public InsetMathFracBase {
public:
///
explicit InsetMathBinom(bool choose = false);
enum Kind {
BINOM,
CHOOSE,
BRACE,
BRACK
};
///
explicit InsetMathBinom(Kind kind = BINOM);
///
void write(WriteStream & os) const;
///
@ -36,12 +44,14 @@ public:
{ drawMarkers2(pi, x, y); }
///
bool extraBraces() const;
///
void validate(LaTeXFeatures & features) const;
private:
virtual std::auto_ptr<Inset> doClone() const;
///
int dw() const;
///
bool choose_;
Kind kind_;
};

View File

@ -365,8 +365,14 @@ MathAtom createInsetMath(docstring const & s)
return MathAtom(new InsetMathTabular(s, 1, 1));
if (s == "stackrel")
return MathAtom(new InsetMathStackrel);
if (s == "binom" || s == "choose")
return MathAtom(new InsetMathBinom(s == "choose"));
if (s == "binom")
return MathAtom(new InsetMathBinom(InsetMathBinom::BINOM));
if (s == "choose")
return MathAtom(new InsetMathBinom(InsetMathBinom::CHOOSE));
if (s == "brace")
return MathAtom(new InsetMathBinom(InsetMathBinom::BRACE));
if (s == "brack")
return MathAtom(new InsetMathBinom(InsetMathBinom::BRACK));
if (s == "frac")
return MathAtom(new InsetMathFrac);
if (s == "over")

View File

@ -1289,7 +1289,9 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
}
}
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
else if (t.cs() == "choose" || t.cs() == "over"
|| t.cs() == "atop" || t.cs() == "brace"
|| t.cs() == "brack") {
MathAtom at = createInsetMath(t.cs());
at.nucleus()->cell(0) = *cell;
cell->clear();

View File

@ -44,6 +44,10 @@ What's new
- New layout files "article (beamer)" and "article (koma + beamer)"
that support beamer's article mode.
- Allow using the \binom command without the amsmath package.
- Add support for \brace and \brack commands in mathed.
* DOCUMENT INPUT/OUTPUT