]> git.lyx.org Git - features.git/blobdiff - src/mathed/math_write.C
first go at mathed file cleanup
[features.git] / src / mathed / math_write.C
index 233635402657db86006010b3bf9fd78a14ced960..97cfd6d5486b3bc56b3198c27bc032a1441c7862 100644 (file)
@@ -21,6 +21,7 @@
 #include "math_inset.h"
 #include "math_iter.h"
 #include "math_parser.h"
+#include "math_parinset.h"
 #include "support/lstrings.h"
 #include "debug.h"
 
@@ -31,293 +32,8 @@ extern char const * latex_mathenv[];
 extern char * latex_mathspace[];
 
 // quite a hack i know. Should be done with return values...
-static int number_of_newlines;
+int number_of_newlines = 0;
 
-char const * math_font_name[] = {
-   "mathrm",
-   "mathcal",
-   "mathbf",
-   "mathsf",
-   "mathtt",
-   "mathit",
-   "textrm"
-};
-
-
-void
-MathSpaceInset::Write(ostream & os, bool /* fragile */)
-{
-   if (space >= 0 && space < 6) {
-          os << '\\' << latex_mathspace[space] << ' ';
-   }
-}
-
-
-void
-MathDotsInset::Write(ostream & os, bool /* fragile */)
-{
-       os << '\\' << name << ' ';
-}
-
-
-void MathSqrtInset::Write(ostream & os, bool fragile)
-{
-       os << '\\' << name << '{';
-       MathParInset::Write(os, fragile); 
-       os << '}';
-}
-
-
-void MathDelimInset::Write(ostream & os, bool fragile)
-{
-    latexkeys * l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
-    latexkeys * r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
-    os << "\\left";
-    if (l) {
-           os << '\\' << l->name << ' ';
-    } else {
-        if (left == '{' || left == '}') {
-               os << '\\' << char(left) << ' ';
-        } else {
-               os << char(left) << ' ';
-        }
-    }
-   MathParInset::Write(os, fragile);
-   os << "\\right";
-   if (r) {
-          os << '\\' << r->name << ' ';
-   } else {
-       if (right == '{' || right == '}') {
-              os << '\\' << char(right) << ' ';
-      } else {
-             os << char(right) << ' ';
-      }
-   }
-}
-
-
-void MathDecorationInset::Write(ostream & os, bool fragile)
-{
-       latexkeys * l = lm_get_key_by_id(deco, LM_TK_WIDE);
-       if (fragile &&
-           (strcmp(l->name, "overbrace") == 0 ||
-            strcmp(l->name, "underbrace") == 0 ||
-            strcmp(l->name, "overleftarrow") == 0 ||
-            strcmp(l->name, "overrightarrow") == 0))
-               os << "\\protect";
-       os << '\\' << l->name << '{';
-       MathParInset::Write(os, fragile);  
-       os << '}';
-}
-
-
-void MathAccentInset::Write(ostream & os, bool fragile)
-{
-       latexkeys * l = lm_get_key_by_id(code, LM_TK_ACCENT);
-       os << '\\' << l->name;
-       if (code!= LM_not)
-               os << '{';
-       else
-               os << ' ';
-       
-       if (inset) {
-               inset->Write(os, fragile);
-       } else {
-               if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM) {
-                       os << '\\'
-                          << math_font_name[fn-LM_TC_RM]
-                          << '{';
-               }
-               if (MathIsSymbol(fn)) {
-                       latexkeys * l = lm_get_key_by_id(c, LM_TK_SYM);
-                       if (l) {
-                               os << '\\' << l->name << ' ';
-                       }
-               } else
-                       os << char(c);
-               
-               if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
-                       os << '}';
-       }
-       
-       if (code!= LM_not)
-               os << '}';
-}
-
-
-void MathBigopInset::Write(ostream & os, bool /* fragile */)
-{
-    bool limp = GetLimits();
-    
-    os << '\\' << name;
-    
-    if (limp && !(sym != LM_int && sym != LM_oint
-                 && (GetStyle() == LM_ST_DISPLAY)))
-           os << "\\limits ";
-    else 
-    if (!limp && (sym != LM_int && sym != LM_oint
-                 && (GetStyle() == LM_ST_DISPLAY)))
-           os << "\\nolimits ";
-    else 
-           os << ' ';
-}
-
-
-void MathFracInset::Write(ostream & os, bool fragile)
-{
-       os << '\\' << name << '{';
-       MathParInset::Write(os, fragile);
-       os << "}{";
-       den->Write(os, fragile);
-       os << '}';
-}
-
-
-void MathParInset::Write(ostream & os, bool fragile)
-{
-       if (!array) return;
-       int brace = 0;
-       latexkeys * l;
-       MathedIter data(array);
-       // hack
-       MathedRowSt const * crow = getRowSt();   
-       data.Reset();
-       
-       if (!Permit(LMPF_FIXED_SIZE)) { 
-               l = lm_get_key_by_id(size, LM_TK_STY);
-               if (l) {
-                       os << '\\' << l->name << ' ';
-               }
-       }
-       while (data.OK()) {
-               byte cx = data.GetChar();
-               if (cx >= ' ') {
-                       string str = data.GetString();
-                       
-                       if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
-                               os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
-                       }
-                       for (string::const_iterator s = str.begin();
-                            s != str.end(); ++s) {
-                               byte c = *s;
-                               if (MathIsSymbol(data.FCode())) {
-                                       l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
-                                                            LM_TK_BIGSYM : LM_TK_SYM);
-                                       if (l) {
-                                               os << '\\' << l->name << ' ';
-                                       } else {
-#warning this does not compile on gcc 2.97
-                                               //lyxerr << "Illegal symbol code[" << c
-                                               //   << " " << str.end() - s << " " << data.FCode() << "]";
-                                       }
-                               } else {
-                                       // Is there a standard logical XOR?
-                                       if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
-                                           (data.FCode() == LM_TC_SPECIAL))
-                                               os << '\\';
-                                       else {
-                                               if (c == '{') ++brace;
-                                               if (c == '}') --brace;
-                                       }
-                                       if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0) 
-                                               lyxerr <<"Math warning: Unexpected closing brace."
-                                                      << endl;
-                                       else           
-                                               os << char(c);
-                               }
-                       }
-                       if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
-                               os << '}';
-               } else     
-                       if (MathIsInset(cx)) {
-                               MathedInset * p = data.GetInset();
-                               if (cx == LM_TC_UP)
-                                       os << "^{";
-                               if (cx == LM_TC_DOWN)
-                                       os << "_{";
-                               p->Write(os, fragile);
-                               if (cx == LM_TC_UP || cx == LM_TC_DOWN)
-                                       os << '}';
-                               data.Next();
-                       } else
-                               switch (cx) {
-                               case LM_TC_TAB:
-                               {
-                                       os << " & ";
-                                       data.Next();
-                                       break;
-                               }
-                               case LM_TC_CR:
-                               {
-                                       if (crow) {
-                                               if (!crow->isNumbered()) {  
-                                                       os << "\\nonumber ";
-                                               }
-                                               if (!crow->getLabel().empty()) {
-                                                       os << "\\label{"
-                                                          << crow->getLabel()
-                                                          << "} ";
-                                               }
-                                               crow = crow->getNext();
-                                       }
-                                       if (fragile)
-                                               os << "\\protect";
-                                       os << "\\\\\n";
-                                       ++number_of_newlines;
-                                       data.Next();
-                                       break;
-                               }
-                               default:
-                                       lyxerr << "WMath Error: unrecognized code[" << cx << "]";
-                                       return;
-                               }     
-       }
-       
-       if (crow) {
-               if (!crow->isNumbered()) {
-                       os << "\\nonumber ";
-               }
-               if (!crow->getLabel().empty()) {
-                       os << "\\label{"
-                          << crow->getLabel()
-                          << "} ";
-               }
-       }
-
-       if (brace > 0)
-               os << string(brace, '}');
-}
-
-
-void MathMatrixInset::Write(ostream & os, bool fragile)
-{
-    if (GetType() == LM_OT_MATRIX){
-           if (fragile)
-                   os << "\\protect";
-           os << "\\begin{"
-              << name
-              << '}';
-       if (v_align == 't' || v_align == 'b') {
-               os << '['
-                  << char(v_align)
-                  << ']';
-       }
-       os << '{'
-          << h_align
-          << "}\n";
-       ++number_of_newlines;
-    }
-    MathParInset::Write(os, fragile);
-    if (GetType() == LM_OT_MATRIX){
-           os << "\n";
-           if (fragile)
-                   os << "\\protect";
-           os << "\\end{"
-              << name
-              << '}';
-       ++number_of_newlines;
-    }
-}
 
 void mathed_write(MathParInset * p, ostream & os, int * newlines,
                  bool fragile, string const & label)