diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index 7e89c8f3f3..c2718bb049 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -68,6 +68,12 @@ void MathBinomInset::draw(PainterInfo & pi, int x, int y) const } +bool MathBinomInset::extraBraces() const +{ + return choose_; +} + + void MathBinomInset::write(WriteStream & os) const { if (choose_) diff --git a/src/mathed/math_binominset.h b/src/mathed/math_binominset.h index 08a8985765..28a2bbadf8 100644 --- a/src/mathed/math_binominset.h +++ b/src/mathed/math_binominset.h @@ -28,6 +28,8 @@ public: void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; + /// + bool extraBraces() const; private: virtual std::auto_ptr doClone() const; /// diff --git a/src/mathed/math_dfracinset.C b/src/mathed/math_dfracinset.C index 3b0c76d280..164b3c705b 100644 --- a/src/mathed/math_dfracinset.C +++ b/src/mathed/math_dfracinset.C @@ -24,7 +24,7 @@ using std::auto_ptr; MathDfracInset::MathDfracInset() - : MathFracInset(false) + : MathFracInset() {} diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 9faf0e8090..b25e25d6a8 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -315,12 +315,14 @@ MathAtom createMathInset(string const & s) return MathAtom(new MathStackrelInset); if (s == "binom" || s == "choose") return MathAtom(new MathBinomInset(s == "choose")); - if (s == "over" || s == "frac") + if (s == "frac") return MathAtom(new MathFracInset); + if (s == "over") + return MathAtom(new MathFracInset(MathFracInset::OVER)); //if (s == "infer") // return MathAtom(new MathInferInset); if (s == "atop") - return MathAtom(new MathFracInset(true)); + return MathAtom(new MathFracInset(MathFracInset::ATOP)); if (s == "lefteqn") return MathAtom(new MathLefteqnInset); if (s == "boldsymbol") diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 829ddf5134..2fc4b39c6d 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -24,8 +24,8 @@ using std::max; using std::auto_ptr; -MathFracInset::MathFracInset(bool atop) - : atop_(atop) +MathFracInset::MathFracInset(Kind kind) + : kind_(kind) {} @@ -37,13 +37,13 @@ auto_ptr MathFracInset::doClone() const MathFracInset * MathFracInset::asFracInset() { - return atop_ ? 0 : this; + return kind_ == ATOP ? 0 : this; } MathFracInset const * MathFracInset::asFracInset() const { - return atop_ ? 0 : this; + return kind_ == ATOP ? 0 : this; } @@ -67,7 +67,7 @@ void MathFracInset::draw(PainterInfo & pi, int x, int y) const FracChanger dummy(pi.base); cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5); cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5); - if (!atop_) + if (kind_ == FRAC || kind_ == OVER) pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math); drawMarkers(pi, x, y); } @@ -89,23 +89,46 @@ void MathFracInset::drawT(TextPainter & pain, int x, int y) const int m = x + dim_.width() / 2; cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1); cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent()); - if (!atop_) + if (kind_ == FRAC || kind_ == OVER) pain.horizontalLine(x, y, dim_.width()); } void MathFracInset::write(WriteStream & os) const { - if (atop_) + switch (kind_) { + case ATOP: os << '{' << cell(0) << "\\atop " << cell(1) << '}'; - else // it's \\frac + break; + case OVER: + // \\over is only for compatibility, normalize this to \\frac + os << "\\frac{" << cell(0) << "}{" << cell(1) << '}'; + break; + case FRAC: MathNestInset::write(os); + break; + } } string MathFracInset::name() const { - return atop_ ? "atop" : "frac"; + switch (kind_) { + case FRAC: + return "frac"; + case OVER: + return "over"; + case ATOP: + return "atop"; + } + // shut up stupid compiler + return string(); +} + + +bool MathFracInset::extraBraces() const +{ + return kind_ == ATOP || kind_ == OVER; } diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 2707fe8cc0..4ed809662d 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -20,7 +20,14 @@ class MathFracInset : public MathFracbaseInset { public: /// - explicit MathFracInset(bool atop = false); + enum Kind { + FRAC, + OVER, + ATOP, + }; + + /// + explicit MathFracInset(Kind kind = FRAC); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -35,6 +42,8 @@ public: MathFracInset const * asFracInset() const; /// std::string name() const; + /// + bool extraBraces() const; /// void write(WriteStream & os) const; @@ -49,7 +58,7 @@ public: public: virtual std::auto_ptr doClone() const; /// - bool const atop_; + Kind const kind_; }; #endif diff --git a/src/mathed/math_tfracinset.C b/src/mathed/math_tfracinset.C index 9671363c2f..cd55d5f285 100644 --- a/src/mathed/math_tfracinset.C +++ b/src/mathed/math_tfracinset.C @@ -27,7 +27,7 @@ using std::auto_ptr; MathTfracInset::MathTfracInset() - : MathFracInset(false) + : MathFracInset() {} diff --git a/status.14x b/status.14x index d3abe8e802..7cb424488a 100644 --- a/status.14x +++ b/status.14x @@ -45,6 +45,9 @@ What's new - Make sure enough passes are made to update the table of contents when running latex (bug 2616). +- Don't add extra braces when reading documents containing \choose, \atop or + \over (bug 2481). + * User Interface: - Show an error box when failing to update the TeX Information dalog data.