+// define a function for tests
+typedef bool TestItemFunc(MathInset *);
+
+// define a function for replacing subexpressions
+typedef MathInset * ReplaceArgumentFunc(const MathArray & ar);
+
+
+
+// try to extract a super/subscript
+// modify iterator position to point behind the thing
+bool extractScript(MathArray & ar,
+ MathArray::iterator & pos, MathArray::iterator last)
+{
+ // nothing to get here
+ if (pos == last)
+ return false;
+
+ // is this a scriptinset?
+ if (!(*pos)->asScriptInset())
+ return false;
+
+ // it is a scriptinset, use it.
+ ar.push_back(*pos);
+ ++pos;
+ return true;
+}
+
+
+// try to extract an "argument" to some function.
+// returns position behind the argument
+MathArray::iterator extractArgument(MathArray & ar,
+ MathArray::iterator pos, MathArray::iterator last, string const & = "")
+{
+ // nothing to get here
+ if (pos == last)
+ return pos;
+
+ // something deliminited _is_ an argument
+ if ((*pos)->asDelimInset()) {
+ ar.push_back(*pos);
+ return pos + 1;
+ }
+
+ // always take the first thing, no matter what it is
+ ar.push_back(*pos);
+
+ // go ahead if possible
+ ++pos;
+ if (pos == last)
+ return pos;
+
+ // if the next item is a subscript, it most certainly belongs to the
+ // thing we have
+ extractScript(ar, pos, last);
+ if (pos == last)
+ return pos;
+
+ // but it might be more than that.
+ // FIXME: not implemented
+ //for (MathArray::iterator it = pos + 1; it != last; ++it) {
+ // // always take the first thing, no matter
+ // if (it == pos) {
+ // ar.push_back(*it);
+ // continue;
+ // }
+ //}
+ return pos;
+}
+
+