From: Enrico Forestieri Date: Mon, 31 Mar 2008 01:23:25 +0000 (+0000) Subject: Allow using \binom without amsmath and add support for \brace and \brack X-Git-Tag: 1.6.10~5336 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b5acd0389165ad9b10a8414353bb9652e1289568;p=features.git Allow using \binom without amsmath and add support for \brace and \brack git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24067 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index 1ac2348230..ac2d894e09 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -472,8 +472,8 @@ void InsetMathTFrac::validate(LaTeXFeatures & features) const ///////////////////////////////////////////////////////////////////// -InsetMathBinom::InsetMathBinom(bool choose) - : choose_(choose) +InsetMathBinom::InsetMathBinom(Kind kind) + : kind_(kind) {} @@ -512,29 +512,43 @@ void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const Dimension const dim = dimension(*pi.base.bv); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); Dimension const & dim1 = cell(1).dimension(*pi.base.bv); + 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 - dim0.width() / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); - mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("(")); + mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), bra); mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(), - dw(dim.height()), dim.height(), from_ascii(")")); + dw(dim.height()), 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; + } } @@ -544,6 +558,15 @@ void InsetMathBinom::normalize(NormalStream & os) const } +void InsetMathBinom::validate(LaTeXFeatures & features) const +{ + if (kind_ == BINOM) { + features.require("binom"); + InsetMathNest::validate(features); + } +} + + ///////////////////////////////////////////////////////////////////// // // InsetMathDBinom diff --git a/src/mathed/InsetMathFrac.h b/src/mathed/InsetMathFrac.h index ffcab06353..966d99d129 100644 --- a/src/mathed/InsetMathFrac.h +++ b/src/mathed/InsetMathFrac.h @@ -132,7 +132,15 @@ private: 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; /// @@ -146,12 +154,14 @@ public: { drawMarkers2(pi, x, y); } /// bool extraBraces() const; + /// + void validate(LaTeXFeatures & features) const; private: Inset * clone() const; /// int dw(int height) const; /// - bool choose_; + Kind kind_; }; diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index ad06eeda59..2ba467d3f5 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1836,7 +1836,8 @@ MathCompletionList::MathCompletionList(Cursor const & cur) globals.push_back(from_ascii("\\stackrel")); globals.push_back(from_ascii("\\binom")); globals.push_back(from_ascii("\\choose")); - globals.push_back(from_ascii("\\choose")); + globals.push_back(from_ascii("\\brace")); + globals.push_back(from_ascii("\\brack")); globals.push_back(from_ascii("\\frac")); globals.push_back(from_ascii("\\over")); globals.push_back(from_ascii("\\nicefrac")); diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 2c67b32dc7..7c9debba72 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -352,8 +352,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") diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 266272e84e..1f7db010c1 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -1440,7 +1440,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();