mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
New support for \begin{...}...\end{...} style environments
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4563 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
76cef13759
commit
884923f714
@ -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 \
|
||||
|
54
src/mathed/math_envinset.C
Normal file
54
src/mathed/math_envinset.C
Normal file
@ -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_;
|
||||
}
|
38
src/mathed/math_envinset.h
Normal file
38
src/mathed/math_envinset.h
Normal file
@ -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
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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") {
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user