support for \begin{tabular}...\end{tabular} within math.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6325 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-03-03 16:15:38 +00:00
parent 0e245cc5e5
commit ca4efc12c2
5 changed files with 150 additions and 0 deletions

View 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 \

View 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")

View 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));

View File

@ -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 << ')';
}

View File

@ -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