From: André Pönitz Date: Thu, 14 Feb 2002 14:52:23 +0000 (+0000) Subject: support for \substack X-Git-Tag: 1.6.10~19855 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5e6481b76e54aabd22077684333dfc7938098e1e;p=features.git support for \substack git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3540 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index d08baff33a..d1491f253c 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 40fbf3d7ad..1fb6fdb7a0 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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) diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index ab216d492f..d0cd009438 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -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 > 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 << "]"; } diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index d09dae7e8a..ce74bf261c 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -12,13 +12,14 @@ 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 diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 111523ae2b..7de5025931 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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; } diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index c6332eed8d..bd9c997a66 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -1,6 +1,7 @@ #include #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)); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 92c33cf725..41de801533 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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 index 0000000000..43395d9937 --- /dev/null +++ b/src/mathed/math_substackinset.C @@ -0,0 +1,53 @@ +#include + +#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 index 0000000000..788a85edd0 --- /dev/null +++ b/src/mathed/math_substackinset.h @@ -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