]> git.lyx.org Git - lyx.git/commitdiff
New support for \begin{...}...\end{...} style environments
authorAndré Pönitz <poenitz@gmx.net>
Tue, 9 Jul 2002 09:46:31 +0000 (09:46 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 9 Jul 2002 09:46:31 +0000 (09:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4563 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/math_envinset.C [new file with mode: 0644]
src/mathed/math_envinset.h [new file with mode: 0644]
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_parser.C
src/mathed/math_spaceinset.C

index 643d13f94af171f9f78dbe78adf41d4437d62276..226e948ae8ace6f1a7d047662b696ecc9d7099f8 100644 (file)
@@ -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 (file)
index 0000000..47936fb
--- /dev/null
@@ -0,0 +1,54 @@
+#include <config.h>
+
+#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 (file)
index 0000000..e19faf2
--- /dev/null
@@ -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
index 2cec6fa4d460dd92bb86f3f8336167909923f4f3..2358c582d319d3af7205815cd74e0a2e8de0021b 100644 (file)
@@ -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)
index e20cd31c9a4c861b3d228acae64f18546935e11f..e9b578f0b3182956bb8d692ba4a978829aec0ed6 100644 (file)
@@ -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
index c26e6b6d8c36859fcb507ba65c1e25843cb00928..f015f8c8ba3942b089768d731e7e835cd8bc2717 100644 (file)
@@ -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") {
index 641549513e56b9d37dce6477ab0faa69c6b14dd4..85cde72adbbccc78241eef308e5fb7ee756be893 100644 (file)
@@ -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];