]> git.lyx.org Git - features.git/commitdiff
support for TeX's \choose
authorAndré Pönitz <poenitz@gmx.net>
Mon, 13 Aug 2001 15:26:41 +0000 (15:26 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 13 Aug 2001 15:26:41 +0000 (15:26 +0000)
fix for return void

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2504 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/math_binominset.C [new file with mode: 0644]
src/mathed/math_binominset.h [new file with mode: 0644]
src/mathed/math_cursor.C
src/mathed/math_factory.C
src/mathed/math_hash.C
src/mathed/math_macrotable.C
src/mathed/math_parser.C
src/mathed/math_parser.h

index 75d9423c368c985d2117cf1a49a7e097d85e760e..9d35995d11d187cf62af69f44340f9321b803a6a 100644 (file)
@@ -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  <poenitz@gmx.net>
 
index 7ba7b4df3e62122adf46d9de32015cd7acc5cf16..2fa5c1e570ac5ae143c9dd50731467846445df38 100644 (file)
@@ -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 (file)
index 0000000..c9d0edd
--- /dev/null
@@ -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 (file)
index 0000000..2bb9745
--- /dev/null
@@ -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
index 48640a855e91e9989ae6b2bd7313051620ad0bf0..90d0eeb4ebec8b2ed4672404b52afbd081f53ecf 100644 (file)
@@ -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
index ae776ade0e8d10122d6c1ff1947a98800de560c9..57e160b241cfdcd9f2f59ca588166b41053f54c7 100644 (file)
@@ -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:
index 3fe70743b3b0705ac10b6f851f1c4b0ced1fea37..3fe5ca23ab4b5b39815a7c0f2a29ccd7bbbde704 100644 (file)
@@ -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},
index 4706c764a0c068dd34575286120ef48c979f32b0..4612e7c58ed9ba4a89ffb7d117fee2342cf97cda 100644 (file)
@@ -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)");
 }
index bd6de769d993d3c58a2eb337a8143a63a7f8081f..d59afab45e0e2b615e69df96593b353df1cb80c5 100644 (file)
@@ -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);
index 5a34b89e72647d0017b08f3384a5a993afd560ce..fa5e770f8af261f27231d72b9cdf7365900315ee 100644 (file)
@@ -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,