]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_matrixinset.C
use stream-like syntax for LaTeX output
[lyx.git] / src / mathed / math_matrixinset.C
index bada6e475666015528c9eaf71a8275bff9c72f9d..690dc0acad3fe3c4c1d9ca5a1e8018e0cf6a6834 100644 (file)
 
 namespace {
 
+       int getCols(MathInsetTypes type)
+       {
+               switch (type) {
+                       case LM_OT_EQNARRAY:
+                               return 3;
+                       case LM_OT_ALIGN:
+                       case LM_OT_ALIGNAT:
+                       case LM_OT_XALIGNAT:
+                       case LM_OT_XXALIGNAT:
+                               return 2;
+                       default:;
+               }
+               return 1;
+       }
 
-int getCols(MathInsetTypes type)
-{
-       switch (type) {
-               case LM_OT_EQNARRAY:
-                       return 3;
-               case LM_OT_ALIGN:
-               case LM_OT_ALIGNAT:
-               case LM_OT_XALIGNAT:
-               case LM_OT_XXALIGNAT:
-                       return 2;
-               default:;
+
+       // returns position of first relation operator in the array
+       // used for "intelligent splitting"
+       int firstRelOp(MathArray const & ar)
+       {
+               for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
+                       if ((*it)->isRelOp())
+                               return it - ar.begin();
+               return ar.size();
        }
-       return 1;
-}
 
 
-// returns position of first relation operator in the array
-// used for "intelligent splitting"
-int firstRelOp(MathArray const & array)
-{
-       for (MathArray::const_iterator it = array.begin(); it != array.end(); ++it)
-               if ((*it)->isRelOp())
-                       return it - array.begin();
-       return array.size();
-}
+       char const * star(bool numbered)
+       {
+               return numbered ? "" : "*";
+       }
+
+       MathInsetTypes typecode(string const & s)
+       {
+               if (s == "equation")  return LM_OT_EQUATION;
+               if (s == "display")   return LM_OT_EQUATION;
+               if (s == "eqnarray")  return LM_OT_EQNARRAY;
+               if (s == "align")     return LM_OT_ALIGN;
+               if (s == "alignat")   return LM_OT_ALIGNAT;
+               if (s == "xalignat")  return LM_OT_XALIGNAT;
+               if (s == "xxalignat") return LM_OT_XXALIGNAT;
+               if (s == "multline")  return LM_OT_MULTLINE;
+               if (s == "gather")    return LM_OT_GATHER;
+               return LM_OT_SIMPLE;
+       }       
 
 
-char const * star(bool numbered)
-{
-       return numbered ? "" : "*";
-}
+       string normalName(MathInsetTypes t)
+       {
+               switch (t) {
+                       case LM_OT_EQUATION:  return "equation";
+                       case LM_OT_EQNARRAY:  return "eqnarray";
+                       case LM_OT_ALIGN:     return "align";
+                       case LM_OT_ALIGNAT:   return "alignat";
+                       case LM_OT_XALIGNAT:  return "xalignat";
+                       case LM_OT_XXALIGNAT: return "xxalignat";
+                       case LM_OT_MULTLINE:  return "multline";
+                       case LM_OT_GATHER:    return "gather";
+                       case LM_OT_SIMPLE:    return "simple";
+                       default: break;
+               }
+               return "unknown";
+       }       
 
-}
+} // end anon namespace
 
 
 MathMatrixInset::MathMatrixInset()
@@ -109,9 +140,10 @@ int MathMatrixInset::defaultColSpace(col_type col)
 }
 
 
-void MathMatrixInset::metrics(MathStyles) const
+void MathMatrixInset::metrics(MathMetricsInfo const & st) const
 {
-       size_ = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
+       size_ = st;
+       size_.size = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
 
        // let the cells adjust themselves
        MathGridInset::metrics(size_);
@@ -156,17 +188,15 @@ void MathMatrixInset::draw(Painter & pain, int x, int y) const
 }
 
 
-void MathMatrixInset::write(std::ostream & os, bool fragile) const
+void MathMatrixInset::write(MathWriteInfo & os) const
 {
-  header_write(os);
+  header_write(os.os);
 
        bool n = numberedType();
 
        for (row_type row = 0; row < nrows(); ++row) {
-               for (col_type col = 0; col < ncols(); ++col) {
-                       cell(index(row, col)).write(os, fragile);
-                       os << eocString(col);
-               }
+               for (col_type col = 0; col < ncols(); ++col) 
+                       os << cell(index(row, col)) << eocString(col);
                if (n) {
                        if (!label_[row].empty())
                                os << "\\label{" << label_[row] << "}";
@@ -176,10 +206,19 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const
                os << eolString(row);
        }
 
-  footer_write(os);
+  footer_write(os.os);
 }
 
 
+void MathMatrixInset::writeNormal(std::ostream & os) const
+{
+       os << "[formula " << normalName(getType()) << " ";
+       MathGridInset::writeNormal(os);
+       os << "] ";
+}
+
+
+
 string MathMatrixInset::label(row_type row) const
 {
        return label_[row];
@@ -434,32 +473,6 @@ string MathMatrixInset::nicelabel(row_type row) const
 }
 
 
-namespace {
-       MathInsetTypes typecode(string const & s)
-       {
-               if (s == "equation")
-                       return LM_OT_EQUATION;
-               if (s == "display")
-                       return LM_OT_EQUATION;
-               if (s == "eqnarray")
-                       return LM_OT_EQNARRAY;
-               if (s == "align")
-                       return LM_OT_ALIGN;
-               if (s == "alignat")
-                       return LM_OT_ALIGN;
-               if (s == "xalignat")
-                       return LM_OT_XALIGNAT;
-               if (s == "xxalignat")
-                       return LM_OT_XXALIGNAT;
-               if (s == "multline")
-                       return LM_OT_MULTLINE;
-               if (s == "gather")
-                       return LM_OT_GATHER;
-               return LM_OT_SIMPLE;
-       }       
-}
-
-
 void MathMatrixInset::mutate(string const & newtype)
 {
        if (newtype == "dump") {