]> git.lyx.org Git - features.git/commitdiff
support for AMS's \pmatrix and \bmatrix
authorAndré Pönitz <poenitz@gmx.net>
Wed, 13 Feb 2002 13:15:15 +0000 (13:15 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 13 Feb 2002 13:15:15 +0000 (13:15 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3530 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/formulabase.C
src/mathed/formulabase.h
src/mathed/math_amsarrayinset.C [new file with mode: 0644]
src/mathed/math_amsarrayinset.h [new file with mode: 0644]
src/mathed/math_parser.C
src/mathed/math_xdata.C
src/mathed/math_xdata.h

index 390f0ee883d9c078ae93e55349e62d662e3c5fa7..4849bff9f6ebbfd2cba68e0dc5d41c0849a6c6d8 100644 (file)
@@ -14,6 +14,8 @@ libmathed_la_SOURCES = \
        formula.h \
        formulamacro.C \
        formulamacro.h \
+       math_amsarrayinset.C \
+       math_amsarrayinset.h \
        math_arrayinset.C \
        math_arrayinset.h \
        math_atom.C \
index c5ef86ec7020333d2b12c19820e84ba3df528712..a1077977c392b476b6ddd421ce1feb0fa9f9c98a 100644 (file)
@@ -401,6 +401,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
 
        case LFUN_RIGHT:
                result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
+               //lyxerr << "calling scroll 20\n";
+               //scroll(bv, 20);
                updateLocal(bv, false);
                // write something to the minibuffer
                //bv->owner()->message(mathcursor->info());
index f2cac7066f79e81bb87c33d543a8fe65bf6b21fa..7e5b8f1813d43860a87b1ef24149019e1ccbd3f2 100644 (file)
@@ -30,7 +30,7 @@ class Buffer;
 class BufferView;
 class MathAtom;
 
-///
+/// An abstract base class for all math related LyX insets
 class InsetFormulaBase : public UpdatableInset {
 public:
        ///
diff --git a/src/mathed/math_amsarrayinset.C b/src/mathed/math_amsarrayinset.C
new file mode 100644 (file)
index 0000000..4fb7011
--- /dev/null
@@ -0,0 +1,87 @@
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_amsarrayinset.h"
+#include "math_mathmlstream.h"
+#include "math_support.h"
+#include "math_streamstr.h"
+#include "math_support.h"
+#include "Lsstream.h"
+
+
+MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
+       : MathGridInset(m, n), name_(name)
+{}
+
+
+MathAMSArrayInset::MathAMSArrayInset(string const & name)
+       : MathGridInset(1, 1), name_(name)
+{}
+
+
+MathInset * MathAMSArrayInset::clone() const
+{
+       return new MathAMSArrayInset(*this);
+}
+
+
+char const * MathAMSArrayInset::name_left() const
+{
+       if (name_ == "bmatrix")
+               return "[";
+       return "(";
+}
+
+
+char const * MathAMSArrayInset::name_right() const
+{
+       if (name_ == "bmatrix")
+               return "]";
+       return ")";
+}
+
+
+void MathAMSArrayInset::metrics(MathMetricsInfo const & st) const
+{
+       MathMetricsInfo mi = st;
+       if (mi.style == LM_ST_DISPLAY)
+               mi.style = LM_ST_TEXT;
+       MathGridInset::metrics(mi);
+       width_ += 12;
+}
+
+
+void MathAMSArrayInset::draw(Painter & pain, int x, int y) const
+{ 
+       MathGridInset::draw(pain, x + 6, y);
+       int yy = y - ascent_;
+       mathed_draw_deco(pain, x + 1, yy, 5, height(), name_left());
+       mathed_draw_deco(pain, x + width_ - 6, yy, 5, height(), name_right());
+}
+
+
+void MathAMSArrayInset::write(WriteStream & os) const
+{
+       os << "\\begin{" << name_ << "}";
+       MathGridInset::write(os);
+       os << "\\end{" << name_ << "}\n";
+}
+
+
+void MathAMSArrayInset::normalize(NormalStream & os) const
+{
+       os << "[" << name_ << " ";
+       MathGridInset::normalize(os);
+       os << "]";
+}
+
+
+void MathAMSArrayInset::maplize(MapleStream & os) const
+{
+       os << name_ << "(";
+       MathGridInset::maplize(os);
+       os << ")";
+}
diff --git a/src/mathed/math_amsarrayinset.h b/src/mathed/math_amsarrayinset.h
new file mode 100644 (file)
index 0000000..861f51d
--- /dev/null
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+#ifndef MATH_AMSARRAYINSET_H
+#define MATH_AMSARRAYINSET_H
+
+#include "math_gridinset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+class MathAMSArrayInset : public MathGridInset {
+public: 
+       ///
+       MathAMSArrayInset(string const & name_, int m, int n);
+       ///
+       MathAMSArrayInset(string const & name_);
+       ///
+       MathInset * clone() const;
+       ///
+       void metrics(MathMetricsInfo const & st) const;
+       ///
+       void draw(Painter & pain, int x, int y) const;
+       ///
+       MathAMSArrayInset * asAMSArrayInset() { return this; }
+
+       ///
+       void write(WriteStream & os) const;
+       ///
+       void normalize(NormalStream &) const;
+       ///
+       void maplize(MapleStream &) const;
+
+private:
+       ///
+       char const * name_left() const;
+       ///
+       char const * name_right() const;
+
+       ///
+       string name_;
+};
+
+#endif
index b6baa3cf223485bd469d07915effa39feebb84e9..7faa4a7c88f55a138161a79e0a7e496bd40d2a84 100644 (file)
@@ -52,6 +52,7 @@ point to write some macros:
 #include "math_parser.h"
 #include "math_inset.h"
 #include "math_arrayinset.h"
+#include "math_amsarrayinset.h"
 #include "math_braceinset.h"
 #include "math_casesinset.h"
 #include "math_charinset.h"
@@ -268,7 +269,7 @@ private:
        ///
        bool parse_lines(MathAtom & t, bool numbered, bool outmost);
        /// parses {... & ... \\ ... & ... }
-       bool parse_lines2(MathAtom & t);
+       bool parse_lines2(MathAtom & t, bool braced);
        /// dump contents to screen
        void dump() const;
 
@@ -655,7 +656,7 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
 }
 
 
-bool Parser::parse_lines2(MathAtom & t)
+bool Parser::parse_lines2(MathAtom & t, bool braced)
 {      
        MathGridInset * p = t->asGridInset();
        if (!p) {
@@ -663,8 +664,6 @@ bool Parser::parse_lines2(MathAtom & t)
                return false;
        }
 
-       skipBegin();
-
        for (int row = 0; true; ++row) {
                // reading a row
                for (MathInset::col_type col = 0; true; ++col) {
@@ -694,12 +693,20 @@ bool Parser::parse_lines2(MathAtom & t)
                        getToken();
                }
 
-               // we are finished if the next token is an '}'
-               if (nextToken().cat() == catEnd) {
-                       // skip the end-token
-                       getToken();
-                       // leave the 'read a line'-loop
-                       break;
+               // we are finished if the next token is the one we expected
+               // skip the end-token
+               // leave the 'read a line'-loop
+               if (braced) {
+                       if (nextToken().cat() == catEnd) {
+                               getToken();
+                               break;
+                       }
+               } else {
+                       if (nextToken().cs() == "end") {
+                               getToken();
+                               getArg('{','}');
+                               break;
+                       }
                }
 
                // otherwise, we have to start a new row
@@ -1081,6 +1088,9 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
                        } else if (name == "cases") {
                                array.push_back(MathAtom(new MathCasesInset));
                                parse_lines(array.back(), false, false);
+                       } else if (name == "pmatrix" || name == "bmatrix") {
+                               array.push_back(MathAtom(new MathAMSArrayInset(name)));
+                               parse_lines2(array.back(), false);
                        } else 
                                lyxerr << "unknow math inset begin '" << name << "'\n"; 
                }
@@ -1117,7 +1127,8 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
 
                else if (t.cs() == "xymatrix") {
                        array.push_back(createMathInset(t.cs()));
-                       parse_lines2(array.back());
+                       skipBegin();
+                       parse_lines2(array.back(), true);
                }
 
 #if 0
index 9c2d059f13059a2d373aada738c1538ad813e5fc..8f4ba899bd87235b20bf1d0b1d8952a9d4d36a19 100644 (file)
@@ -177,3 +177,23 @@ void MathXArray::findPos(MathPosFinder & f) const
        }
 }
 */
+
+void MathXArray::center(int & x, int & y) const
+{
+       x = xo_ + width_ / 2;
+       y = yo_ + (descent_ - ascent_) / 2;
+}
+
+
+void MathXArray::towards(int & x, int & y) const
+{
+       int cx = 0;
+       int cy = 0;
+       center(cx, cy);
+
+       double r = 1.0;
+       int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
+
+       x = cx + int(r * (x - cx));
+       y = cy + int(r * (y - cy));
+}
index a14573299001c71b3524df9958d5a86c365768c6..ee5b1d73a9ed7e83124b37c2bc241fd27c2bece9 100644 (file)
@@ -61,6 +61,10 @@ public:
        void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
        /// find best position to do things
        //void findPos(PosFinder &) const;
+       /// gives center coordinates
+       void center(int & x, int & y) const;
+       /// adjust (x,y) to point on boundary on a straight line from the center
+       void towards(int & x, int & y) const;
 
        /// begin iterator of the underlying MathArray
        const_iterator begin() const { return data_.begin(); }