some support for det and abs for math-extern

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2970 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-11-07 10:21:51 +00:00
parent 6e3fcdf812
commit 0f23028f4b
9 changed files with 57 additions and 3 deletions

View File

@ -335,3 +335,9 @@ MathArray::iterator MathArray::end()
}
bool MathArray::isMatrix() const
{
return size() == 1 && begin()->nucleus() && begin()->nucleus()->isMatrix();
}

View File

@ -128,6 +128,9 @@ public:
/// interface to MathML
string mathmlize() const;
///
bool isMatrix() const;
private:
/// Buffer
buffer_type bf_;

View File

@ -93,6 +93,13 @@ void MathDelimInset::draw(Painter & pain, int x, int y) const
}
bool MathDelimInset::isMatrix() const
{
return left_ == "(" && right_ == ")" && cell(0).size() == 1 &&
cell(0).begin()->nucleus() && cell(0).begin()->nucleus()->asArrayInset();
}
string MathDelimInset::octavize() const
{
if (left_ == "|" && right_ == "|")
@ -103,7 +110,12 @@ string MathDelimInset::octavize() const
string MathDelimInset::maplize() const
{
if (left_ == "|" && right_ == "|")
return "abs(" + cell(0).octavize() + ")";
return left_ + cell(0).octavize() + right_;
if (left_ == "|" && right_ == "|") {
if (cell(0).isMatrix())
return "linalg[det](" + cell(0).maplize() + ")";
else
return "abs(" + cell(0).maplize() + ")";
}
return left_ + cell(0).maplize() + right_;
}

View File

@ -28,6 +28,8 @@ public:
///
void metrics(MathMetricsInfo const & st) const;
///
bool isMatrix() const;
///
string octavize() const;
///
string maplize() const;

View File

@ -605,3 +605,22 @@ string MathGridInset::octavize() const
return res;
}
string MathGridInset::maplize() const
{
string res = "array([";
for (row_type row = 0; row < nrows(); ++row) {
if (row)
res += ',';
res += '[';
for (col_type col = 0; col < ncols(); ++col) {
if (col)
res += ',';
res += cell(index(row, col)).maplize();
}
res += ']';
}
res += "])";
return res;
}

View File

@ -151,6 +151,8 @@ public:
///
string octavize() const;
///
string maplize() const;
protected:
/// returns proper 'end of line' code for LaTeX

View File

@ -234,6 +234,8 @@ public:
virtual bool isRelOp() const { return false; }
///
virtual bool isMacro() const { return false; }
/// is this a matrix or matrix expression?
virtual bool isMatrix() const { return false; }
///
virtual char getChar() const { return 0; }

View File

@ -55,3 +55,9 @@ void MathSqrtInset::writeNormal(std::ostream & os) const
cell(0).writeNormal(os);
os << "]";
}
string MathSqrtInset::maplize() const
{
return "sqrt(" + cell(0).maplize() + ')';
}

View File

@ -25,5 +25,7 @@ public:
void writeNormal(std::ostream &) const;
///
void metrics(MathMetricsInfo const & st) const;
///
string maplize() const;
};
#endif