Detect appropriate delimiter for matrices.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32549 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-12-16 17:01:09 +00:00
parent 05336422a4
commit 05f1f323de
4 changed files with 34 additions and 21 deletions

View File

@ -46,12 +46,12 @@ public:
void validate(LaTeXFeatures & features) const;
///
InsetCode lyxCode() const { return MATH_AMSARRAY_CODE; }
private:
virtual Inset * clone() const;
///
char const * name_left() const;
///
char const * name_right() const;
private:
virtual Inset * clone() const;
///
docstring name_;
};

View File

@ -17,8 +17,9 @@
namespace lyx {
InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p)
: InsetMathGrid(p)
InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p,
docstring const & left, docstring const & right)
: InsetMathGrid(p), left_(left), right_(right)
{}
@ -88,15 +89,10 @@ void InsetMathMatrix::mathematica(MathematicaStream & os) const
}
// FIXME XHTML
// We need more information here, so we can output the correct
// delimiters, which will not always be "[". To do this, we need
// to make some changes to InsetMathMatrix, adding a member to
// record the type of delimiter, and then make the extractMatrices
// routine in MathExtern give us this information.
void InsetMathMatrix::mathmlize(MathStream & os) const
{
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>[</mo>";
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< left_ << "</mo>";
os << MTag("mtable");
for (row_type row = 0; row < nrows(); ++row) {
os << MTag("mtr");
@ -105,7 +101,8 @@ void InsetMathMatrix::mathmlize(MathStream & os) const
os << ETag("mtr");
}
os << ETag("mtable");
os << "<mo form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>]</mo>";
os << "<mo form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< right_ << "</mo>";
}

View File

@ -13,6 +13,7 @@
#define MATH_MATRIXINSET_H
#include "InsetMathGrid.h"
#include "support/strfwd.h"
namespace lyx {
@ -23,9 +24,8 @@ namespace lyx {
class InsetMathMatrix : public InsetMathGrid {
public:
///
explicit InsetMathMatrix(InsetMathGrid const &);
///
explicit InsetMathMatrix(Buffer * buf, docstring const & str);
explicit InsetMathMatrix(InsetMathGrid const &,
docstring const & left, docstring const & right);
/// identifies MatrixInsets
InsetMathMatrix const * asMatrixInset() const { return this; }
@ -48,6 +48,10 @@ public:
private:
virtual Inset * clone() const;
///
docstring left_;
///
docstring right_;
};

View File

@ -16,6 +16,7 @@
#include "MathExtern.h"
#include "InsetMathAMSArray.h"
#include "InsetMathArray.h"
#include "InsetMathChar.h"
#include "InsetMathDelim.h"
@ -193,20 +194,31 @@ void extractMatrices(MathData & ar)
//lyxerr << "\nMatrices from: " << ar << endl;
// first pass for explicitly delimited stuff
for (size_t i = 0; i < ar.size(); ++i) {
if (!ar[i]->asDelimInset())
InsetMathDelim const * const inset = ar[i]->asDelimInset();
if (!inset)
continue;
MathData const & arr = ar[i]->asDelimInset()->cell(0);
MathData const & arr = inset->cell(0);
if (arr.size() != 1)
continue;
if (!arr.front()->asGridInset())
continue;
ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset())));
ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset()),
inset->left_, inset->right_));
}
// second pass for AMS "pmatrix" etc
for (size_t i = 0; i < ar.size(); ++i)
if (ar[i]->asAMSArrayInset())
ar[i] = MathAtom(new InsetMathMatrix(*(ar[i]->asGridInset())));
for (size_t i = 0; i < ar.size(); ++i) {
InsetMathAMSArray const * const inset = ar[i]->asAMSArrayInset();
if (inset) {
string left = inset->name_left();
if (left == "Vert")
left = "[";
string right = inset->name_right();
if (right == "Vert")
right = "]";
ar[i] = MathAtom(new InsetMathMatrix(*inset, from_ascii(left), from_ascii(right)));
}
}
//lyxerr << "\nMatrices to: " << ar << endl;
}