+{
+ //lyxerr << "unexpected call to MathScriptInset::draw()\n";
+ draw(0, pain, x, y);
+}
+
+
+void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
+ int x, int y) const
+{
+ if (nuc)
+ nuc->draw(pain, x + dxx(nuc), y);
+ else
+ 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(MathWriteInfo & os) const
+{
+ //lyxerr << "unexpected call to MathScriptInset::write()\n";
+ write(0, os);
+}
+
+
+void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const
+{
+ if (nuc) {
+ nuc->write(os);
+ if (nuc->takesLimits()) {
+ if (limits_ == -1)
+ os << "\\nolimits ";
+ if (limits_ == 1)
+ os << "\\limits ";
+ }
+ }
+ else
+ os << "{}";
+
+ if (hasDown() && down().data_.size())
+ os << "_{" << down().data_ << '}';
+
+ if (hasUp() && up().data_.size())
+ os << "^{" << up().data_ << '}';
+}
+
+
+void MathScriptInset::writeNormal(ostream & os) const
+{
+ //lyxerr << "unexpected call to MathScriptInset::writeNormal()\n";
+ writeNormal(0, os);
+}
+
+
+void MathScriptInset::writeNormal(MathInset const * nuc, ostream & os) const
+{
+ bool d = hasDown() && down().data_.size();
+ bool u = hasUp() && up().data_.size();
+
+ ostringstream osb;
+ if (nuc)
+ nuc->writeNormal(osb);
+ else
+ osb << "[par]";
+ string base = osb.str();
+
+ if (u && d) {
+ os << "[sup [sub " << osb.str() << " ";
+ down().data_.writeNormal(os);
+ os << "] ";
+ up().data_.writeNormal(os);
+ os << ']';
+ } else if (u) {
+ os << "[sup " << osb.str() << " ";
+ up().data_.writeNormal(os);
+ os << ']';
+ } else if (d) {
+ os << "[sub " << osb.str() << " ";
+ down().data_.writeNormal(os);
+ os << ']';
+ }
+}
+
+
+bool MathScriptInset::hasLimits(MathInset const * nuc) const
+{
+ return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
+}
+
+
+void MathScriptInset::removeEmptyScripts()
+{
+ for (int i = 0; i <= 1; ++i)
+ if (script_[i] && !cell(i).size())
+ script_[i] = false;
+}
+
+
+void MathScriptInset::removeScript(bool up)
+{
+ cell(up).clear();
+ script_[up] = false;
+}
+
+
+bool MathScriptInset::has(bool up) const
+{
+ return script_[up];
+}
+
+
+bool MathScriptInset::hasUp() const