mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-10 18:58:10 +00:00
support for AMS's \pmatrix and \bmatrix
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3530 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
919b745fa6
commit
e70e507d01
@ -14,6 +14,8 @@ libmathed_la_SOURCES = \
|
||||
formula.h \
|
||||
formulamacro.C \
|
||||
formulamacro.h \
|
||||
math_amsarrayinset.C \
|
||||
math_amsarrayinset.h \
|
||||
math_arrayinset.C \
|
||||
math_arrayinset.h \
|
||||
math_atom.C \
|
||||
|
@ -401,6 +401,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
||||
|
||||
case LFUN_RIGHT:
|
||||
result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
|
||||
//lyxerr << "calling scroll 20\n";
|
||||
//scroll(bv, 20);
|
||||
updateLocal(bv, false);
|
||||
// write something to the minibuffer
|
||||
//bv->owner()->message(mathcursor->info());
|
||||
|
@ -30,7 +30,7 @@ class Buffer;
|
||||
class BufferView;
|
||||
class MathAtom;
|
||||
|
||||
///
|
||||
/// An abstract base class for all math related LyX insets
|
||||
class InsetFormulaBase : public UpdatableInset {
|
||||
public:
|
||||
///
|
||||
|
87
src/mathed/math_amsarrayinset.C
Normal file
87
src/mathed/math_amsarrayinset.C
Normal file
@ -0,0 +1,87 @@
|
||||
#include <config.h>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "math_amsarrayinset.h"
|
||||
#include "math_mathmlstream.h"
|
||||
#include "math_support.h"
|
||||
#include "math_streamstr.h"
|
||||
#include "math_support.h"
|
||||
#include "Lsstream.h"
|
||||
|
||||
|
||||
MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
|
||||
: MathGridInset(m, n), name_(name)
|
||||
{}
|
||||
|
||||
|
||||
MathAMSArrayInset::MathAMSArrayInset(string const & name)
|
||||
: MathGridInset(1, 1), name_(name)
|
||||
{}
|
||||
|
||||
|
||||
MathInset * MathAMSArrayInset::clone() const
|
||||
{
|
||||
return new MathAMSArrayInset(*this);
|
||||
}
|
||||
|
||||
|
||||
char const * MathAMSArrayInset::name_left() const
|
||||
{
|
||||
if (name_ == "bmatrix")
|
||||
return "[";
|
||||
return "(";
|
||||
}
|
||||
|
||||
|
||||
char const * MathAMSArrayInset::name_right() const
|
||||
{
|
||||
if (name_ == "bmatrix")
|
||||
return "]";
|
||||
return ")";
|
||||
}
|
||||
|
||||
|
||||
void MathAMSArrayInset::metrics(MathMetricsInfo const & st) const
|
||||
{
|
||||
MathMetricsInfo mi = st;
|
||||
if (mi.style == LM_ST_DISPLAY)
|
||||
mi.style = LM_ST_TEXT;
|
||||
MathGridInset::metrics(mi);
|
||||
width_ += 12;
|
||||
}
|
||||
|
||||
|
||||
void MathAMSArrayInset::draw(Painter & pain, int x, int y) const
|
||||
{
|
||||
MathGridInset::draw(pain, x + 6, y);
|
||||
int yy = y - ascent_;
|
||||
mathed_draw_deco(pain, x + 1, yy, 5, height(), name_left());
|
||||
mathed_draw_deco(pain, x + width_ - 6, yy, 5, height(), name_right());
|
||||
}
|
||||
|
||||
|
||||
void MathAMSArrayInset::write(WriteStream & os) const
|
||||
{
|
||||
os << "\\begin{" << name_ << "}";
|
||||
MathGridInset::write(os);
|
||||
os << "\\end{" << name_ << "}\n";
|
||||
}
|
||||
|
||||
|
||||
void MathAMSArrayInset::normalize(NormalStream & os) const
|
||||
{
|
||||
os << "[" << name_ << " ";
|
||||
MathGridInset::normalize(os);
|
||||
os << "]";
|
||||
}
|
||||
|
||||
|
||||
void MathAMSArrayInset::maplize(MapleStream & os) const
|
||||
{
|
||||
os << name_ << "(";
|
||||
MathGridInset::maplize(os);
|
||||
os << ")";
|
||||
}
|
44
src/mathed/math_amsarrayinset.h
Normal file
44
src/mathed/math_amsarrayinset.h
Normal file
@ -0,0 +1,44 @@
|
||||
// -*- C++ -*-
|
||||
#ifndef MATH_AMSARRAYINSET_H
|
||||
#define MATH_AMSARRAYINSET_H
|
||||
|
||||
#include "math_gridinset.h"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
|
||||
class MathAMSArrayInset : public MathGridInset {
|
||||
public:
|
||||
///
|
||||
MathAMSArrayInset(string const & name_, int m, int n);
|
||||
///
|
||||
MathAMSArrayInset(string const & name_);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
///
|
||||
void draw(Painter & pain, int x, int y) const;
|
||||
///
|
||||
MathAMSArrayInset * asAMSArrayInset() { return this; }
|
||||
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
void normalize(NormalStream &) const;
|
||||
///
|
||||
void maplize(MapleStream &) const;
|
||||
|
||||
private:
|
||||
///
|
||||
char const * name_left() const;
|
||||
///
|
||||
char const * name_right() const;
|
||||
|
||||
///
|
||||
string name_;
|
||||
};
|
||||
|
||||
#endif
|
@ -52,6 +52,7 @@ point to write some macros:
|
||||
#include "math_parser.h"
|
||||
#include "math_inset.h"
|
||||
#include "math_arrayinset.h"
|
||||
#include "math_amsarrayinset.h"
|
||||
#include "math_braceinset.h"
|
||||
#include "math_casesinset.h"
|
||||
#include "math_charinset.h"
|
||||
@ -268,7 +269,7 @@ private:
|
||||
///
|
||||
bool parse_lines(MathAtom & t, bool numbered, bool outmost);
|
||||
/// parses {... & ... \\ ... & ... }
|
||||
bool parse_lines2(MathAtom & t);
|
||||
bool parse_lines2(MathAtom & t, bool braced);
|
||||
/// dump contents to screen
|
||||
void dump() const;
|
||||
|
||||
@ -655,7 +656,7 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
|
||||
}
|
||||
|
||||
|
||||
bool Parser::parse_lines2(MathAtom & t)
|
||||
bool Parser::parse_lines2(MathAtom & t, bool braced)
|
||||
{
|
||||
MathGridInset * p = t->asGridInset();
|
||||
if (!p) {
|
||||
@ -663,8 +664,6 @@ bool Parser::parse_lines2(MathAtom & t)
|
||||
return false;
|
||||
}
|
||||
|
||||
skipBegin();
|
||||
|
||||
for (int row = 0; true; ++row) {
|
||||
// reading a row
|
||||
for (MathInset::col_type col = 0; true; ++col) {
|
||||
@ -694,12 +693,20 @@ bool Parser::parse_lines2(MathAtom & t)
|
||||
getToken();
|
||||
}
|
||||
|
||||
// we are finished if the next token is an '}'
|
||||
if (nextToken().cat() == catEnd) {
|
||||
// skip the end-token
|
||||
getToken();
|
||||
// leave the 'read a line'-loop
|
||||
break;
|
||||
// we are finished if the next token is the one we expected
|
||||
// skip the end-token
|
||||
// leave the 'read a line'-loop
|
||||
if (braced) {
|
||||
if (nextToken().cat() == catEnd) {
|
||||
getToken();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (nextToken().cs() == "end") {
|
||||
getToken();
|
||||
getArg('{','}');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, we have to start a new row
|
||||
@ -1081,6 +1088,9 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
|
||||
} else if (name == "cases") {
|
||||
array.push_back(MathAtom(new MathCasesInset));
|
||||
parse_lines(array.back(), false, false);
|
||||
} else if (name == "pmatrix" || name == "bmatrix") {
|
||||
array.push_back(MathAtom(new MathAMSArrayInset(name)));
|
||||
parse_lines2(array.back(), false);
|
||||
} else
|
||||
lyxerr << "unknow math inset begin '" << name << "'\n";
|
||||
}
|
||||
@ -1117,7 +1127,8 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code)
|
||||
|
||||
else if (t.cs() == "xymatrix") {
|
||||
array.push_back(createMathInset(t.cs()));
|
||||
parse_lines2(array.back());
|
||||
skipBegin();
|
||||
parse_lines2(array.back(), true);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -177,3 +177,23 @@ void MathXArray::findPos(MathPosFinder & f) const
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void MathXArray::center(int & x, int & y) const
|
||||
{
|
||||
x = xo_ + width_ / 2;
|
||||
y = yo_ + (descent_ - ascent_) / 2;
|
||||
}
|
||||
|
||||
|
||||
void MathXArray::towards(int & x, int & y) const
|
||||
{
|
||||
int cx = 0;
|
||||
int cy = 0;
|
||||
center(cx, cy);
|
||||
|
||||
double r = 1.0;
|
||||
int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
|
||||
|
||||
x = cx + int(r * (x - cx));
|
||||
y = cy + int(r * (y - cy));
|
||||
}
|
||||
|
@ -61,6 +61,10 @@ public:
|
||||
void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
|
||||
/// find best position to do things
|
||||
//void findPos(PosFinder &) const;
|
||||
/// gives center coordinates
|
||||
void center(int & x, int & y) const;
|
||||
/// adjust (x,y) to point on boundary on a straight line from the center
|
||||
void towards(int & x, int & y) const;
|
||||
|
||||
/// begin iterator of the underlying MathArray
|
||||
const_iterator begin() const { return data_.begin(); }
|
||||
|
Loading…
Reference in New Issue
Block a user