]> git.lyx.org Git - features.git/commitdiff
support for \substack
authorAndré Pönitz <poenitz@gmx.net>
Thu, 14 Feb 2002 14:52:23 +0000 (14:52 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 14 Feb 2002 14:52:23 +0000 (14:52 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3540 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/formula.C
src/mathed/math_arrayinset.C
src/mathed/math_arrayinset.h
src/mathed/math_cursor.C
src/mathed/math_factory.C
src/mathed/math_parser.C
src/mathed/math_substackinset.C [new file with mode: 0644]
src/mathed/math_substackinset.h [new file with mode: 0644]

index d08baff33aece6b4d83fa0f0073b321075c52206..d1491f253c77eb6d1e1d624f8cde308f7a21b3b8 100644 (file)
@@ -123,6 +123,8 @@ libmathed_la_SOURCES = \
        math_streamstr.h \
        math_stringinset.C \
        math_stringinset.h \
+       math_substackinset.C \
+       math_substackinset.h \
        math_support.C \
        math_support.h \
        math_symbolinset.C \
index 40fbf3d7ad5831b6ab80db9d23bd9fc857118a63..1fb6fdb7a06d1e6ce8e2a678cca5d9b7a0bdf686 100644 (file)
@@ -196,7 +196,7 @@ namespace {
                out = out.substr(6);
 
                // parse output as matrix or single number
-               MathAtom at(new MathArrayInset(out));
+               MathAtom at(new MathArrayInset("array", out));
                MathArrayInset const * mat = at.nucleus()->asArrayInset();
                MathArray res;
                if (mat->ncols() == 1 && mat->nrows() == 1)
index ab216d492f5a113f4040dac4befeba6cb15635ed..d0cd0094383bc354f5238c967aebaf26e39e26b5 100644 (file)
@@ -17,23 +17,25 @@ using std::istringstream;
 using std::getline;
 
 
-MathArrayInset::MathArrayInset(int m, int n)
-       : MathGridInset(m, n)
+MathArrayInset::MathArrayInset(string const & name, int m, int n)
+       : MathGridInset(m, n), name_(name)
 {}
 
 
-MathArrayInset::MathArrayInset(int m, int n, char valign, string const & halign)
-       : MathGridInset(m, n, valign, halign)
+MathArrayInset::MathArrayInset(string const & name, int m, int n,
+               char valign, string const & halign)
+       : MathGridInset(m, n, valign, halign), name_(name)
 {}
 
 
-MathArrayInset::MathArrayInset(char valign, string const & halign)
-       : MathGridInset(valign, halign)
+MathArrayInset::MathArrayInset(string const & name, char valign,
+               string const & halign)
+       : MathGridInset(valign, halign), name_(name)
 {}
 
 
-MathArrayInset::MathArrayInset(string const & str)
-       : MathGridInset(1, 1)
+MathArrayInset::MathArrayInset(string const & name, string const & str)
+       : MathGridInset(1, 1), name_(name)
 {
        vector< vector<string> > dat;
        istringstream is(str.c_str());
@@ -76,7 +78,7 @@ void MathArrayInset::write(WriteStream & os) const
 {
        if (os.fragile())
                os << "\\protect";
-       os << "\\begin{array}";
+       os << "\\begin{" << name_ << "}";
 
        if (v_align_ == 't' || v_align_ == 'b') 
                os << '[' << char(v_align_) << ']';
@@ -86,13 +88,13 @@ void MathArrayInset::write(WriteStream & os) const
 
        if (os.fragile())
                os << "\\protect";
-       os << "\\end{array}\n";
+       os << "\\end{" << name_ << "}\n";
 }
 
 
 void MathArrayInset::normalize(NormalStream & os) const
 {
-       os << "[array ";
+       os << "[" << name_ << " ";
        MathGridInset::normalize(os);
        os << "]";
 }
index d09dae7e8aa1f3c415d0961f65d22947208fe6e2..ce74bf261c64ff24b6fd38c36ca58cc360ab1f64 100644 (file)
 class MathArrayInset : public MathGridInset {
 public: 
        ///
-       MathArrayInset(int m, int n);
+       MathArrayInset(string const &, int m, int n);
        ///
-       MathArrayInset(int m, int n, char valign, string const & halign);
+       MathArrayInset(string const &, int m, int n,
+               char valign, string const & halign);
        ///
-       MathArrayInset(char valign, string const & halign);
+       MathArrayInset(string const &, char valign, string const & halign);
        /// convienience constructor from whitespace/newline seperated data
-       MathArrayInset(string const & str);
+       MathArrayInset(string const &, string const & str);
        ///
        MathInset * clone() const;
        ///
@@ -32,6 +33,10 @@ public:
        void normalize(NormalStream &) const;
        ///
        void maplize(MapleStream &) const;
+
+private:
+       ///
+       string name_;
 };
 
 #endif
index 111523ae2bc608b79c7ba09fca5aaaf459e5bd03..7de50259313ef67fcc97d9e8117cbae4fff8894d 100644 (file)
@@ -1265,7 +1265,7 @@ bool MathCursor::interpret(string const & s)
                m = std::max(1u, m);
                n = std::max(1u, n);
                v_align += 'c';
-               niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
+               niceInsert(MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
                return true;
        }
 
index c6332eed8d876a4e3d6c96ff542a5fc5b4d1887f..bd9c997a666a2f700f00bbdc7c583763482704ff 100644 (file)
@@ -1,6 +1,7 @@
 #include <config.h>
 
 #include "math_parser.h"
+#include "math_arrayinset.h"
 #include "math_amsarrayinset.h"
 #include "math_binominset.h"
 #include "math_boxinset.h"
@@ -23,6 +24,7 @@
 #include "math_specialcharinset.h"
 #include "math_sqrtinset.h"
 #include "math_stackrelinset.h"
+#include "math_substackinset.h"
 #include "math_symbolinset.h"
 #include "math_undersetinset.h"
 #include "math_unknowninset.h"
@@ -108,6 +110,12 @@ MathAtom createMathInset(string const & s)
        if (s == "cases")
                return MathAtom(new MathCasesInset);
 
+       if (s == "substack")
+               return MathAtom(new MathSubstackInset);
+
+       if (s == "subarray" || s == "array")
+               return MathAtom(new MathArrayInset(s, 1, 1));
+
        if (s == "pmatrix" || s == "bmatrix" || s == "vmatrix" || s == "Vmatrix") 
                return MathAtom(new MathAMSArrayInset(s));
 
index 92c33cf725ebd6c00124d25a52917cf69317cbb6..41de8015331d3913b18fecd83488a1e1b4b61a04 100644 (file)
@@ -1074,10 +1074,10 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
 
                else if (t.cs() == "begin") {
                        string const name = getArg('{', '}');   
-                       if (name == "array") {
+                       if (name == "array" || name == "subarray") {
                                string const valign = getArg('[', ']') + 'c';
                                string const halign = getArg('{', '}');
-                               array.push_back(MathAtom(new MathArrayInset(valign[0], halign)));
+                               array.push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
                                parse_lines(array.back(), false, false);
                        } else if (name == "split" || name == "cases") {
                                array.push_back(createMathInset(name));
@@ -1120,6 +1120,12 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
                        return;
                }
 
+               else if (t.cs() == "substack") {
+                       array.push_back(createMathInset(t.cs()));
+                       skipBegin();
+                       parse_lines2(array.back(), true);
+               }
+
                else if (t.cs() == "xymatrix") {
                        array.push_back(createMathInset(t.cs()));
                        skipBegin();
diff --git a/src/mathed/math_substackinset.C b/src/mathed/math_substackinset.C
new file mode 100644 (file)
index 0000000..43395d9
--- /dev/null
@@ -0,0 +1,53 @@
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_substackinset.h"
+#include "math_mathmlstream.h"
+#include "math_streamstr.h"
+
+
+MathSubstackInset::MathSubstackInset()
+       : MathGridInset(1, 1)
+{}
+
+
+MathInset * MathSubstackInset::clone() const
+{
+       return new MathSubstackInset(*this);
+}
+
+
+void MathSubstackInset::metrics(MathMetricsInfo const & st) const
+{
+       MathMetricsInfo mi = st;
+       if (mi.style == LM_ST_DISPLAY)
+               mi.style = LM_ST_TEXT;
+       MathGridInset::metrics(mi);
+}
+
+
+void MathSubstackInset::write(WriteStream & os) const
+{
+       os << "\\substack{";
+       MathGridInset::write(os);
+       os << "}\n";
+}
+
+
+void MathSubstackInset::normalize(NormalStream & os) const
+{
+       os << "[substack ";
+       MathGridInset::normalize(os);
+       os << "]";
+}
+
+
+void MathSubstackInset::maplize(MapleStream & os) const
+{
+       os << "substack(";
+       MathGridInset::maplize(os);
+       os << ")";
+}
diff --git a/src/mathed/math_substackinset.h b/src/mathed/math_substackinset.h
new file mode 100644 (file)
index 0000000..788a85e
--- /dev/null
@@ -0,0 +1,33 @@
+// -*- C++ -*-
+#ifndef MATH_SUBSTACK_H
+#define MATH_SUBSTACK_H
+
+#include "math_gridinset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+class MathSubstackInset : public MathGridInset {
+public: 
+       ///
+       MathSubstackInset();
+       ///
+       MathInset * clone() const;
+       ///
+       void metrics(MathMetricsInfo const & st) const;
+       ///
+       MathSubstackInset const * asSubstackInset() const { return this; }
+
+       ///
+       void normalize();
+       ///
+       void write(WriteStream & os) const;
+       ///
+       void normalize(NormalStream &) const;
+       ///
+       void maplize(MapleStream &) const;
+};
+
+#endif