2

When using Solve for example, I find myself having to use it in conjunction with other types of functions, like Flatten or Simplify, like:

Flatten[Simplify[Solve[x^2 + 3 x == 2, x]]]

Since I am a complete beginner in building macros in Mathematica, I was trying to see if it were possible to create a macro, where you would type say fss, and it automatically converts it into Flatten[Simplify[Solve[]]], where if possible the cursor is placed right inside the Solve automatically.

I tried to do something like:

InputAutoReplacements -> {"fss" -> Flatten[Simplify[Solve[]]]};

Unfortunately, this did not work...

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Patrick.B
  • 1,399
  • 5
  • 11

1 Answers1

5

With an input auto replacement like "fss", you need to have some way of telling Mathematica that "fss" is a complete token. That is, "fss" only gets replaced when the next character is not a letter. The usual input auto replacements typically get replaced when you type a letter, e.g., a->b only becomes $a\to b$ after you type the letter "b".

So, to make the input auto replacement behave the way you probably want, you could do the following:

CurrentValue[EvaluationNotebook[], {InputAutoReplacements, "fss"}] := RowBox[{
    "Flatten", "[", RowBox[{"Simplify", "[", RowBox[{"Solve", "\[SelectionPlaceholder]", "]"}], "]"}], "]"
}]

Then, typing "fss[" will perform the desired replacement, since "[" is not a letter. The "[" character will persist, which is why it is not included in the replacement code.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355