- mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
- else
- mathDispatch(cur, cmd, false);
+ docstring sel = cur.selectionAsString(false);
+ MathMacroTemplate * macro = new MathMacroTemplate(cur.buffer());
+ // create a macro template if we see "\\newcommand" somewhere, and
+ // an ordinary formula otherwise
+ if (!sel.empty()
+ && (sel.find(from_ascii("\\newcommand")) != string::npos
+ || sel.find(from_ascii("\\newlyxcommand")) != string::npos
+ || sel.find(from_ascii("\\def")) != string::npos)
+ && macro->fromString(sel)) {
+ cur.recordUndo();
+ replaceSelection(cur);
+ cur.insert(macro);
+ } else {
+ // no meaningful macro template was found
+ delete macro;
+ mathDispatch(cur,FuncRequest(LFUN_MATH_MODE));
+ }
+ } else
+ // The argument is meaningful
+ // We replace cmd with LFUN_MATH_INSERT because LFUN_MATH_MODE
+ // has a different meaning in math mode
+ mathDispatch(cur, FuncRequest(LFUN_MATH_INSERT,cmd.argument()));