]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_scriptinset.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_scriptinset.C
index 305d22c86ad517fb9f2702a5be4e72934fe8269d..5c5aa5c7e3c79acc4379e31763da7e77b5df7bcb 100644 (file)
@@ -1,14 +1,13 @@
-#include <config.h>
-#include "debug.h"
-#include "support.h"
-#include "support/LOstream.h"
-#include "support/LAssert.h"
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "math_scriptinset.h"
+#include "math_support.h"
+#include "math_symbolinset.h"
+#include "math_mathmlstream.h"
+#include "support/LAssert.h"
+#include "debug.h"
 
 
 MathScriptInset::MathScriptInset()
@@ -27,7 +26,6 @@ MathScriptInset::MathScriptInset(bool up)
 }
 
 
-
 MathInset * MathScriptInset::clone() const
 {
        return new MathScriptInset(*this);
@@ -100,7 +98,7 @@ int MathScriptInset::dy1(MathInset const * nuc) const
                asc += na + 2;
        else 
                asc = std::max(asc, na);
-       asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I'));
+       asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
        return asc;
 }
 
@@ -108,37 +106,37 @@ int MathScriptInset::dy1(MathInset const * nuc) const
 int MathScriptInset::dx0(MathInset const * nuc) const
 {
        lyx::Assert(hasDown());
-       return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
+       return hasLimits(nuc) ? (width2(nuc) - down().width()) / 2 : nwid(nuc);
 }
 
 
 int MathScriptInset::dx1(MathInset const * nuc) const
 {
        lyx::Assert(hasUp());
-       return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
+       return hasLimits(nuc) ? (width2(nuc) - up().width()) / 2 : nwid(nuc);
 }
 
 
 int MathScriptInset::dxx(MathInset const * nuc) const
 {
        //lyx::Assert(nuc());
-       return hasLimits(nuc)  ?  (width(nuc) - nwid(nuc)) / 2  :  0;
+       return hasLimits(nuc)  ?  (width2(nuc) - nwid(nuc)) / 2  :  0;
 }
 
 
-int MathScriptInset::ascent(MathInset const * nuc) const
+int MathScriptInset::ascent2(MathInset const * nuc) const
 {
        return dy1(nuc) + (hasUp() ? up().ascent() : 0);
 }
 
 
-int MathScriptInset::descent(MathInset const * nuc) const
+int MathScriptInset::descent2(MathInset const * nuc) const
 {
        return dy0(nuc) + (hasDown() ? down().descent() : 0);
 }
 
 
-int MathScriptInset::width(MathInset const * nuc) const
+int MathScriptInset::width2(MathInset const * nuc) const
 {
        int wid = 0;
        if (hasLimits(nuc)) {
@@ -162,39 +160,39 @@ int MathScriptInset::nwid(MathInset const * nuc) const
 {
        return nuc ?
                nuc->width() :
-               mathed_char_width(LM_TC_TEX, LM_ST_TEXT, '.');
+               mathed_char_width(LM_TC_TEX, mi_, '.');
 }
 
 
 int MathScriptInset::nasc(MathInset const * nuc) const
 {
        return nuc ? nuc->ascent()
-               : mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I');
+               : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
 }
 
 
 int MathScriptInset::ndes(MathInset const * nuc) const
 {
        return nuc ? nuc->descent()
-               : mathed_char_descent(LM_TC_VAR, LM_ST_TEXT, 'I');
+               : mathed_char_descent(LM_TC_VAR, mi_, 'I');
 }
 
 
-void MathScriptInset::metrics(MathStyles st) const
+void MathScriptInset::metrics(MathMetricsInfo const & mi) const
 {      
-       metrics(0, st);
+       metrics(0, mi);
 }
 
 
-void MathScriptInset::metrics(MathInset const * nuc, MathStyles st) const
+void MathScriptInset::metrics(MathInset const * nuc,
+       MathMetricsInfo const & mi) const
 {      
-       MathNestInset::metrics(st);
+       MathNestInset::metrics(mi);
        if (nuc)
-               nuc->metrics(st);
-
-       ascent_  = ascent(nuc);
-       descent_ = descent(nuc);
-       width_   = width(nuc);
+               nuc->metrics(mi);
+       ascent_  = ascent2(nuc);
+       descent_ = descent2(nuc);
+       width_   = width2(nuc);
 }
 
 
@@ -208,58 +206,40 @@ void MathScriptInset::draw(Painter & pain, int x, int y) const
 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
        int x, int y) const
 {  
-       xo(x);
-       yo(y);
        if (nuc)
                nuc->draw(pain, x + dxx(nuc), y);
        else
-               drawStr(pain, LM_TC_TEX, LM_ST_TEXT, x + dxx(nuc), y, ".");
+               drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
+
        if (hasUp())
                up().draw(pain, x + dx1(nuc), y - dy1(nuc));
+
        if (hasDown())
                down().draw(pain, x + dx0(nuc), y + dy0(nuc));
 }
 
 
-void MathScriptInset::write(std::ostream & os, bool fragile) const
-{  
-       //lyxerr << "unexpected call to MathScriptInset::write()\n";
-       write(0, os, fragile);
-}
-
-
-void MathScriptInset::write(MathInset const * nuc, std::ostream & os,
-       bool fragile) const
+bool MathScriptInset::hasLimits(MathInset const * nuc) const
 {
-       if (nuc) {
-               nuc->write(os, fragile);
-               if (nuc->takesLimits()) {
-                       if (limits_ == -1)
-                               os << "\\nolimits ";
-                       if (limits_ == 1)
-                               os << "\\limits ";
-               }
-       }
-       else
-               os << "{}";
+       // obviuos cases
+       if (limits_ == 1)
+               return true;
+       if (limits_ == -1)
+               return false;
 
-       if (hasDown() && down().data_.size()) {
-               os << "_{";
-               down().data_.write(os, fragile);
-               os << "}";
-       }
+       // we can only display limits if the nucleus wants some 
+       if (!nuc)
+               return false;
+       if (!nuc->isScriptable())
+               return false;
+       
+       // per default \int has limits beside the \int even in displayed formulas
+       if (nuc->asSymbolInset())
+               if (nuc->asSymbolInset()->name().find("int") != string::npos)
+                       return false;
 
-       if (hasUp() && up().data_.size()) {
-               os << "^{";
-               up().data_.write(os, fragile);
-               os << "}";
-       }
-}
-
-
-bool MathScriptInset::hasLimits(MathInset const * nuc) const
-{
-       return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
+       // assume "real" limits for everything else
+       return true;
 }
 
 
@@ -294,3 +274,127 @@ bool MathScriptInset::hasDown() const
 {
        return script_[0];
 }
+
+
+bool MathScriptInset::idxRight(MathInset::idx_type &,
+                                MathInset::pos_type &) const
+{
+       return false;
+}
+
+
+bool MathScriptInset::idxLeft(MathInset::idx_type &,
+                               MathInset::pos_type &) const
+{
+       return false;
+}
+
+
+void MathScriptInset::write(WriteStream & os) const
+{  
+       //lyxerr << "unexpected call to MathScriptInset::write()\n";
+       write2(0, os);
+}
+
+
+void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
+{
+       if (nuc) {
+               os << nuc;
+               if (nuc->takesLimits()) {
+                       if (limits_ == -1)
+                               os << "\\nolimits ";
+                       if (limits_ == 1)
+                               os << "\\limits ";
+               }
+       } else
+                       if (os.firstitem())
+                               lyxerr << "suppressing {} \n";
+                       else
+                               os << "{}";
+
+       if (hasDown() && down().data_.size())
+               os << "_{" << down().data_ << '}';
+
+       if (hasUp() && up().data_.size())
+               os << "^{" << up().data_ << '}';
+}
+
+
+void MathScriptInset::normalize(NormalStream & os) const
+{  
+       //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
+       normalize2(0, os);
+}
+
+
+void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
+{
+       bool d = hasDown() && down().data_.size();
+       bool u = hasUp() && up().data_.size();
+
+       if (u) 
+               os << "[sup ";
+       if (d)
+               os << "[sub ";
+       
+       if (nuc)
+               os << nuc << ' ';
+       else
+               os << "[par]";
+
+       if (d)
+               os << down().data_ << ']';
+       if (u) 
+               os << up().data_ << ']';
+}
+
+
+void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
+{
+       if (nuc)
+               os << nuc;
+       if (hasDown() && down().data_.size())
+               os << '[' << down().data_ << ']';
+       if (hasUp() && up().data_.size())
+               os << "^(" << up().data_ << ')';
+}
+
+
+void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
+{
+       bool d = hasDown() && down().data_.size();
+       bool u = hasUp() && up().data_.size();
+
+       if (u && d)
+               os << MTag("msubsup");
+       else if (u)
+               os << MTag("msup");
+       else if (d)
+               os << MTag("msub");
+
+       if (nuc)
+               os << nuc;
+       else
+               os << "<mrow/>";
+
+       if (u && d)
+               os << down().data_ << up().data_ << ETag("msubsup");
+       else if (u)
+               os << up().data_ << ETag("msup");
+       else if (d)
+               os << down().data_ << ETag("msub");
+}
+
+
+void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
+{
+       if (nuc)
+               os << nuc;
+       if (hasDown() && down().data_.size())
+               os << '[' << down().data_ << ']';
+       if (hasUp() && up().data_.size())
+               os << "^(" << up().data_ << ')';
+}
+
+