From: André Pönitz Date: Mon, 13 Aug 2001 15:26:41 +0000 (+0000) Subject: support for TeX's \choose X-Git-Tag: 1.6.10~20841 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d586e9e8564753e3998d23bdaad6effda338a009;p=lyx.git support for TeX's \choose fix for return void git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2504 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 75d9423c36..9d35995d11 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -7,8 +7,10 @@ math_cursor.C: math_hash.C: simplifications + * math_binom.[Ch]: new files for "native" \binom/\choose inset + * math_parser.C: - math_cursor.C: reading support for TeX style \over + math_cursor.C: reading support for TeX style \over and \choose 2001-08-10 André Pönitz diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 7ba7b4df3e..2fa5c1e570 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -24,6 +24,8 @@ libmathed_la_SOURCES = \ math_arrayinset.h \ math_bigopinset.C \ math_bigopinset.h \ + math_binominset.C \ + math_binominset.h \ math_charinset.C \ math_charinset.h \ math_cursor.C \ diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C new file mode 100644 index 0000000000..c9d0edd735 --- /dev/null +++ b/src/mathed/math_binominset.C @@ -0,0 +1,74 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_binominset.h" +#include "math_parser.h" +#include "support.h" +#include "support/LOstream.h" + + +MathBinomInset::MathBinomInset() +{} + + +MathInset * MathBinomInset::clone() const +{ + return new MathBinomInset(*this); +} + + +int MathBinomInset::dw() const +{ + int w = height()/5; + if (w > 15) + w = 15; + if (w < 6) + w = 6; + return w; +} + + +void MathBinomInset::metrics(MathStyles st) const +{ + size_ = smallerStyleFrac(st); + xcell(0).metrics(size_); + xcell(1).metrics(size_); + ascent_ = xcell(0).height() + 4 + 5; + descent_ = xcell(1).height() + 4 - 5; + width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4; +} + + +void MathBinomInset::draw(Painter & pain, int x, int y) const +{ + xo(x); + yo(y); + int m = x + width() / 2; + xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5); + xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5); + mathed_draw_deco(pain, x, y - ascent_, + dw(), height(), in_word_set("(")); + mathed_draw_deco(pain, x + width() - dw(), y - ascent_, + dw(), height(), in_word_set(")")); +} + + +void MathBinomInset::write(std::ostream & os, bool fragile) const +{ + os << '{'; + cell(0).write(os, fragile); + os << " \\choose "; + cell(1).write(os, fragile); + os << '}'; +} + + +void MathBinomInset::writeNormal(std::ostream & os) const +{ + os << "[binom "; + cell(0).writeNormal(os); + os << " "; + cell(1).writeNormal(os); + os << "] "; +} diff --git a/src/mathed/math_binominset.h b/src/mathed/math_binominset.h new file mode 100644 index 0000000000..2bb97451dd --- /dev/null +++ b/src/mathed/math_binominset.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +#ifndef MATH_BINOMINSET_H +#define MATH_DINOMINSET_H + +#include "math_fracbase.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Binom like objects + \author André Pönitz + */ +class MathBinomInset : public MathFracbaseInset { +public: + /// + MathBinomInset(); + /// + MathInset * clone() const; + /// + void write(std::ostream &, bool fragile) const; + /// + void writeNormal(std::ostream &) const; + /// + void metrics(MathStyles st) const; + /// + void draw(Painter &, int x, int y) const; +private: + /// + int dw() const; +}; + +#endif diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 48640a855e..90d0eeb4eb 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -35,7 +35,6 @@ #include "math_charinset.h" #include "math_decorationinset.h" #include "math_deliminset.h" -#include "math_fracinset.h" #include "math_funcinset.h" #include "math_macro.h" #include "math_macrotable.h" @@ -1283,9 +1282,9 @@ void MathCursor::interpret(string const & s) return; } - if (s == "\\over") { + if (s == "\\over" || s == "\\choose") { MathArray ar = array(); - MathFracInset * p = new MathFracInset; + MathInset * p = createMathInset(in_word_set(s.substr(1))); p->cell(0).swap(array()); pos() = 0; niceInsert(p); @@ -1305,8 +1304,10 @@ void MathCursor::interpret(string const & s) return; } - if (s.size() > 1) - return niceInsert(new MathFuncInset(s.substr(1))); + if (s.size() > 1) { + niceInsert(new MathFuncInset(s.substr(1))); + return; + } // we got just a single char now diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index ae776ade0e..57e160b241 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -2,6 +2,7 @@ #include "math_parser.h" #include "math_bigopinset.h" +#include "math_binominset.h" #include "math_decorationinset.h" #include "math_dotsinset.h" #include "math_funcinset.h" @@ -31,6 +32,10 @@ MathInset * createMathInset(latexkeys const * l) return new MathSymbolInset(l); case LM_TK_STACK: return new MathStackrelInset; + case LM_TK_BINOM: + case LM_TK_CHOOSE: + return new MathBinomInset; + case LM_TK_OVER: case LM_TK_FRAC: return new MathFracInset; case LM_TK_SQRT: diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 3fe70743b3..3fe5ca23ab 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -83,6 +83,7 @@ latexkeys wordlist[] = {"biguplus", LM_TK_NOGLYPHB, 0, LMB_NONE}, {"bigvee", LM_TK_NOGLYPHB, 0, LMB_NONE}, {"bigwedge", LM_TK_NOGLYPHB, 0, LMB_NONE}, + {"binom", LM_TK_BINOM, 0, LMB_NONE}, {"bmod", LM_TK_FUNC, 0, LMB_NONE}, {"bot", LM_TK_SYM, LM_bot, LMB_NONE}, {"bowtie", LM_TK_NOGLYPH, 0, LMB_RELATION}, @@ -94,6 +95,7 @@ latexkeys wordlist[] = {"cdots", LM_TK_DOTS, LM_cdots, LMB_NONE}, {"check", LM_TK_DECORATION, LM_check, LMB_NONE}, {"chi", LM_TK_SYM, LM_chi, LMB_NONE}, + {"choose", LM_TK_CHOOSE, 0, LMB_NONE}, {"circ", LM_TK_NOGLYPH, 0, LMB_OPERATOR}, {"clubsuit", LM_TK_SYM, LM_clubsuit, LMB_NONE}, {"cong", LM_TK_SYM, LM_cong, LMB_RELATION}, diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 4706c764a0..4612e7c58e 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -97,5 +97,5 @@ void MathMacroTable::builtinMacros() createTemplate("to", 0, "\\rightarrow"); //createTemplate("lint", 4, "\\int_#1^#2#3 d#4"); //createTemplate("silentmult", 0, "\\cdot"); - createTemplate("binom", 2, "\\left(\\frac#1#2\\right)"); + //createTemplate("binom", 2, "\\left(\\frac#1#2\\right)"); } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index bd6de769d9..d59afab45e 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -30,7 +30,6 @@ #include "math_charinset.h" #include "math_deliminset.h" #include "math_factory.h" -#include "math_fracinset.h" #include "math_funcinset.h" #include "math_macro.h" #include "math_macrotable.h" @@ -815,9 +814,11 @@ void Parser::parse_into(MathArray & array, unsigned flags) curr_label_ = lexArg('{', true); break; + case LM_TK_CHOOSE: case LM_TK_OVER: { - MathFracInset * p = new MathFracInset; + limits = 0; + MathInset * p = createMathInset(lval_); p->cell(0).swap(array); array.push_back(p); parse_into(p->cell(1), FLAG_BLOCK); diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 5a34b89e72..fa5e770f8a 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -45,10 +45,12 @@ enum MathTokenEnum /// LM_TK_SYM, /// - LM_TK_OVER, - /// LM_TK_CHOOSE, /// + LM_TK_BINOM, + /// + LM_TK_OVER, + /// LM_TK_FRAC, /// LM_TK_SQRT,