From: André Pönitz Date: Tue, 9 Jul 2002 09:46:31 +0000 (+0000) Subject: New support for \begin{...}...\end{...} style environments X-Git-Tag: 1.6.10~18938 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=884923f714ebf1bf0ec969f3d95c673a1356784e;p=features.git New support for \begin{...}...\end{...} style environments git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4563 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 643d13f94a..226e948ae8 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -49,6 +49,8 @@ libmathed_la_SOURCES = \ math_diminset.h \ math_dotsinset.C \ math_dotsinset.h \ + math_envinset.C \ + math_envinset.h \ math_extern.C \ math_extern.h \ math_exfuncinset.C \ diff --git a/src/mathed/math_envinset.C b/src/mathed/math_envinset.C new file mode 100644 index 0000000000..47936fb277 --- /dev/null +++ b/src/mathed/math_envinset.C @@ -0,0 +1,54 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_envinset.h" +#include "math_mathmlstream.h" +#include "math_streamstr.h" + + +MathEnvInset::MathEnvInset(string const & name) + : MathNestInset(1), name_(name) +{} + + +MathInset * MathEnvInset::clone() const +{ + return new MathEnvInset(*this); +} + + +void MathEnvInset::metrics(MathMetricsInfo & mi) const +{ + xcell(0).metrics(mi); + ascent_ = xcell(0).ascent() + 1; + descent_ = xcell(0).descent() + 1; + width_ = xcell(0).width() + 2; +} + + +void MathEnvInset::draw(MathPainterInfo & pi, int x, int y) const +{ + xcell(0).draw(pi, x + 1, y); + drawMarkers2(pi, x, y); +} + + +void MathEnvInset::write(WriteStream & os) const +{ + os << "\\begin{" << name_ << '}' << cell(0) << "\\end{" << name_ << '}'; +} + + +void MathEnvInset::normalize(NormalStream & os) const +{ + os << "[env " << name_ << " " << cell(0) << ']'; +} + + +void MathEnvInset::infoize(std::ostream & os) const +{ + os << "Env: " << name_; +} diff --git a/src/mathed/math_envinset.h b/src/mathed/math_envinset.h new file mode 100644 index 0000000000..e19faf2e80 --- /dev/null +++ b/src/mathed/math_envinset.h @@ -0,0 +1,38 @@ +// -*- C++ -*- +#ifndef MATH_ENVINSET_H +#define MATH_ENVINSET_H + +#include "math_nestinset.h" +#include "math_metricsinfo.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Environtments á la \begin{something}...\end{something} + \author André Pönitz +*/ + +class MathEnvInset : public MathNestInset { +public: + /// + MathEnvInset(string const & name_); + /// + MathInset * clone() const; + /// + void draw(MathPainterInfo &, int x, int y) const; + /// + void write(WriteStream & os) const; + /// write normalized content + void normalize(NormalStream & ns) const; + /// + void metrics(MathMetricsInfo & mi) const; + /// + void infoize(std::ostream & os) const; + +private: + /// name of that environment + string name_; +}; + +#endif diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 2cec6fa4d4..2358c582d3 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -173,6 +173,20 @@ void MathNestInset::drawMarkers(MathPainterInfo & pi, int x, int y) const } +void MathNestInset::drawMarkers2(MathPainterInfo & pi, int x, int y) const +{ + if (!editing()) + return; + drawMarkers(pi, x, y); + int t = x + width() - 1; + int a = y - ascent(); + pi.pain.line(x, a + 3, x, a, LColor::mathframe); + pi.pain.line(t, a + 3, t, a, LColor::mathframe); + pi.pain.line(x, a, x + 3, a, LColor::mathframe); + pi.pain.line(t - 2, a, t, a, LColor::mathframe); +} + + void MathNestInset::validate(LaTeXFeatures & features) const { for (idx_type i = 0; i < nargs(); ++i) diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index e20cd31c9a..e9b578f0b3 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -24,8 +24,10 @@ public: void metrics(MathMetricsInfo const & mi) const; /// draw background if locked void draw(MathPainterInfo & pi, int x, int y) const; - /// draw angular markers + /// draw two angular markers void drawMarkers(MathPainterInfo & pi, int x, int y) const; + /// draw four angular markers + void drawMarkers2(MathPainterInfo & pi, int x, int y) const; /// appends itself with macro arguments substituted void substitute(MathMacro const & macro); /// identifies NestInsets diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index c26e6b6d8c..f015f8c8ba 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -43,6 +43,7 @@ following hack as starting point to write some macros: #include "math_boxinset.h" #include "math_charinset.h" #include "math_deliminset.h" +#include "math_envinset.h" #include "math_extern.h" #include "math_factory.h" #include "math_kerninset.h" @@ -529,6 +530,7 @@ bool Parser::parse_macro(string & name) } else if (nextToken().cs() == "newcommand") { + // skip the 'newcommand' getToken(); if (getToken().cat() != catBegin) { @@ -539,7 +541,7 @@ bool Parser::parse_macro(string & name) name = getToken().cs(); if (getToken().cat() != catEnd) { - error("'}' expected\n"); + error("'}' in \\newcommand expected\n"); return false; } @@ -963,17 +965,19 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, parse_into2(cell->back(), FLAG_END, true, !stared(name)); } - else { - latexkeys const * l = in_word_set(name); - if (l) { - if (l->inset == "matrix") { - cell->push_back(createMathInset(name)); - parse_into2(cell->back(), FLAG_END, mathmode, false); - } - } else { - lyxerr << "unknow math inset begin '" << name << "'\n"; + else if (latexkeys const * l = in_word_set(name)) { + if (l->inset == "matrix") { + cell->push_back(createMathInset(name)); + parse_into2(cell->back(), FLAG_END, mathmode, false); } } + + else { + // lyxerr << "unknow math inset begin '" << name << "'\n"; + // create generic environment inset + cell->push_back(MathAtom(new MathEnvInset(name))); + parse_into(cell->back()->cell(0), FLAG_END, mathmode); + } } else if (t.cs() == "kern") { diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 641549513e..85cde72adb 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -61,7 +61,7 @@ void MathSpaceInset::draw(MathPainterInfo & pain, int x, int y) const // Sadly, HP-UX CC can't handle that kind of initialization. // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}}; - if (space_ > 6) + if (space_ >= 6) return; int xp[4];