]> git.lyx.org Git - features.git/commitdiff
support for \begin{tabular}...\end{tabular} within math.
authorAndré Pönitz <poenitz@gmx.net>
Mon, 3 Mar 2003 16:15:38 +0000 (16:15 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 3 Mar 2003 16:15:38 +0000 (16:15 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6325 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/math_factory.C
src/mathed/math_parser.C
src/mathed/math_tabularinset.C [new file with mode: 0644]
src/mathed/math_tabularinset.h [new file with mode: 0644]

index 442bb7d020386a540bab3c60ab239bd8a993df59..c2a116b54297a2611a450e1b7ba843de82d45d54 100644 (file)
@@ -142,6 +142,8 @@ libmathed_la_SOURCES = \
        math_support.h \
        math_symbolinset.C \
        math_symbolinset.h \
+       math_tabularinset.C \
+       math_tabularinset.h \
        math_textinset.C \
        math_textinset.h \
        math_unknowninset.C \
index 3bf2999eaaf7443e9eabcdb38bbce9b834612f5b..7ad66b051d980d0f933a32bef1537cecd49f8241 100644 (file)
@@ -31,6 +31,7 @@
 #include "math_stackrelinset.h"
 #include "math_substackinset.h"
 #include "math_symbolinset.h"
+#include "math_tabularinset.h"
 #include "math_undersetinset.h"
 #include "math_unknowninset.h"
 #include "math_xarrowinset.h"
@@ -275,6 +276,8 @@ MathAtom createMathInset(string const & s)
                return MathAtom(new MathSqrtInset);
        if (s == "root")
                return MathAtom(new MathRootInset);
+       if (s == "tabular")
+               return MathAtom(new MathTabularInset(s, 1, 1));
        if (s == "stackrel")
                return MathAtom(new MathStackrelInset);
        if (s == "binom" || s == "choose")
index d05e4f3aaa2f90e1d3ba40079536c23c74837fc2..d4bb600b627f314bd7ab3b7f1411902a210d0b86 100644 (file)
@@ -56,6 +56,7 @@ following hack as starting point to write some macros:
 #include "math_sqrtinset.h"
 #include "math_stringinset.h"
 #include "math_support.h"
+#include "math_tabularinset.h"
 #include "math_xyarrowinset.h"
 
 //#include "insets/insetref.h"
@@ -996,6 +997,13 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                parse2(cell->back(), FLAG_END, mode, false);
                        }
 
+                       if (name == "tabular") {
+                               string const valign = parse_verbatim_option() + 'c';
+                               string const halign = parse_verbatim_item();
+                               cell->push_back(MathAtom(new MathTabularInset(name, valign[0], halign)));
+                               parse2(cell->back(), FLAG_END, mode, false);
+                       }
+
                        else if (name == "split" || name == "cases" ||
                                         name == "gathered" || name == "aligned") {
                                cell->push_back(createMathInset(name));
diff --git a/src/mathed/math_tabularinset.C b/src/mathed/math_tabularinset.C
new file mode 100644 (file)
index 0000000..2fd1b69
--- /dev/null
@@ -0,0 +1,89 @@
+#include <config.h>
+
+
+#include "math_tabularinset.h"
+#include "math_parser.h"
+#include "math_mathmlstream.h"
+#include "math_metricsinfo.h"
+#include "math_streamstr.h"
+#include "Lsstream.h"
+
+#include <iterator>
+
+using std::vector;
+using std::istringstream;
+using std::getline;
+using std::istream_iterator;
+
+
+MathTabularInset::MathTabularInset(string const & name, int m, int n)
+       : MathGridInset(m, n), name_(name)
+{}
+
+
+MathTabularInset::MathTabularInset(string const & name, int m, int n,
+               char valign, string const & halign)
+       : MathGridInset(m, n, valign, halign), name_(name)
+{}
+
+
+MathTabularInset::MathTabularInset(string const & name, char valign,
+               string const & halign)
+       : MathGridInset(valign, halign), name_(name)
+{}
+
+
+MathInset * MathTabularInset::clone() const
+{
+       return new MathTabularInset(*this);
+}
+
+
+void MathTabularInset::metrics(MathMetricsInfo & mi) const
+{
+       MathFontSetChanger dummy(mi.base, "textnormal");
+       MathGridInset::metrics(mi);
+}
+
+
+void MathTabularInset::draw(MathPainterInfo & pi, int x, int y) const
+{
+       MathFontSetChanger dummy(pi.base, "textnormal");
+       MathGridInset::draw(pi, x, y);
+}
+
+
+void MathTabularInset::write(WriteStream & os) const
+{
+       if (os.fragile())
+               os << "\\protect";
+       os << "\\begin{" << name_ << '}';
+
+       if (v_align_ == 't' || v_align_ == 'b')
+               os << '[' << char(v_align_) << ']';
+       os << '{' << halign() << "}\n";
+
+       MathGridInset::write(os);
+
+       if (os.fragile())
+               os << "\\protect";
+       os << "\\end{" << name_ << '}';
+       // adding a \n here is bad if the tabular is the last item
+       // in an \eqnarray...
+}
+
+
+void MathTabularInset::normalize(NormalStream & os) const
+{
+       os << '[' << name_ << ' ';
+       MathGridInset::normalize(os);
+       os << ']';
+}
+
+
+void MathTabularInset::maple(MapleStream & os) const
+{
+       os << "array(";
+       MathGridInset::maple(os);
+       os << ')';
+}
diff --git a/src/mathed/math_tabularinset.h b/src/mathed/math_tabularinset.h
new file mode 100644 (file)
index 0000000..7e1bfe9
--- /dev/null
@@ -0,0 +1,48 @@
+// -*- C++ -*-
+#ifndef MATH_TABULARINSET_H
+#define MATH_TABULARINSET_H
+
+#include "math_gridinset.h"
+
+
+/**
+ * Inset for things like \begin{tabular}...\end{tabular}
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+class MathTabularInset : public MathGridInset {
+public:
+       ///
+       MathTabularInset(string const &, int m, int n);
+       ///
+       MathTabularInset(string const &, int m, int n,
+               char valign, string const & halign);
+       ///
+       MathTabularInset(string const &, char valign, string const & halign);
+       ///
+       MathInset * clone() const;
+       ///
+       void metrics(MathMetricsInfo & mi) const;
+       ///
+       void draw(MathPainterInfo & pi, int x, int y) const;
+       ///
+       MathTabularInset * asTabularInset() { return this; }
+       ///
+       MathTabularInset const * asTabularInset() const { return this; }
+
+       ///
+       void write(WriteStream & os) const;
+       ///
+       void normalize(NormalStream &) const;
+       ///
+       void maple(MapleStream &) const;
+
+private:
+       ///
+       string name_;
+};
+
+#endif