diff --git a/src/mathed/array.C b/src/mathed/array.C index 507aa2cc2f..5331bf2588 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -335,3 +335,9 @@ MathArray::iterator MathArray::end() } +bool MathArray::isMatrix() const +{ + return size() == 1 && begin()->nucleus() && begin()->nucleus()->isMatrix(); +} + + diff --git a/src/mathed/array.h b/src/mathed/array.h index 52dc1528f8..24c9e4fd0b 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -128,6 +128,9 @@ public: /// interface to MathML string mathmlize() const; + /// + bool isMatrix() const; + private: /// Buffer buffer_type bf_; diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 7c5c736b90..767a60f7ec 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -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_; } + diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index 24a3ab2255..0ffe24d3c7 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -28,6 +28,8 @@ public: /// void metrics(MathMetricsInfo const & st) const; /// + bool isMatrix() const; + /// string octavize() const; /// string maplize() const; diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 5b31df9cbd..17823c7973 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -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; +} + diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 60027ec568..af3f69e68d 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -151,6 +151,8 @@ public: /// string octavize() const; + /// + string maplize() const; protected: /// returns proper 'end of line' code for LaTeX diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 59335a3331..5c81b6cc63 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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; } diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 9c6b4b3ed3..0b3e2c72db 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -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() + ')'; +} diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index 78e3ecedce..8f21fe99d8 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -25,5 +25,7 @@ public: void writeNormal(std::ostream &) const; /// void metrics(MathMetricsInfo const & st) const; + /// + string maplize() const; }; #endif