+
+void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
+{
+ if (bv->available()) {
+// Feature "Read math inset from selection" disabled.
+// // use selection if available..
+// string sel;
+// if (action == LFUN_MATH_IMPORT_SELECTION)
+// sel = "";
+// else
+// sel = bv->getLyXText()->selectionAsString(bv->buffer());
+
+ InsetFormula * f;
+// if (sel.empty()) {
+ f = new InsetFormula;
+ openNewInset(bv, f);
+ // don't do that also for LFUN_MATH_MODE unless you want end up with
+ // always changing to mathrm when opening an inlined inset
+ // -- I really hate "LyXfunc overloading"...
+ if (display)
+ f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
+ f->localDispatch(bv, LFUN_INSERT_MATH, arg);
+// } else {
+// f = new InsetFormula(sel);
+// bv->getLyXText()->cutSelection(bv);
+// openNewInset(bv, f);
+// }
+ }
+ bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
+}
+
+void mathDispatchMathDisplay(BufferView * bv, string const & arg)
+{
+ mathDispatchCreation(bv, arg, true);
+}
+
+void mathDispatchMathMode(BufferView * bv, string const & arg)
+{
+ mathDispatchCreation(bv, arg, false);
+}
+
+void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
+{
+ mathDispatchCreation(bv, arg, true);
+}
+
+void mathDispatchMathMacro(BufferView * bv, string const & arg)
+{
+ if (bv->available()) {
+ string s(arg);
+ if (s.empty())
+ bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
+ else {
+ string const s1 = token(s, ' ', 1);
+ int const na = s1.empty() ? 0 : lyx::atoi(s1);
+ openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
+ }
+ }
+}
+
+void mathDispatchMathDelim(BufferView * bv, string const & arg)
+{
+ if (bv->available()) {
+ if (openNewInset(bv, new InsetFormula))
+ bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
+ }
+}
+
+
+void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
+{
+ if (bv->available()) {
+ if (openNewInset(bv, new InsetFormula))
+ bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
+ }
+}
+
+void mathDispatchInsertMath(BufferView * bv, string const & arg)
+{
+ if (bv->available()) {
+ if (arg.size() && arg[0] == '\\') {
+ InsetFormula * f = new InsetFormula(arg);
+ openNewInset(bv, f);
+ } else {
+ return mathDispatchMathDisplay(bv, arg);
+ }
+ }
+}
+