# How to use MakeExpression for single characters

Here is code that I thought would make the front end parse f as BigFunction:

MakeExpression["f", StandardForm] := MakeExpression["BigFunction", StandardForm]


It works provided it is the only thing in the input:

f
(* BigFunction *)


But it doesn't work if it appears anywhere inside a larger expression:

f + 1
(* f + 1 *)    (* I want BigFunction + 1 *)

f[x]
(* f[x] *)     (* I want BigFunction[x] *)


How do I make single character expressions parse as longer names?

Note: Since I want the conversion to occur during parsing, I don't want to use Set:

f = BigFunction


MakeExpression["f", StandardForm] :=  MakeExpression["BigFunction", StandardForm]


you can use:

MakeExpression[RowBox[{x___, "f", y___}], StandardForm] :=
MakeExpression[RowBox[{x, "BigFunction", y}], StandardForm]


MakeExpression[h_[x___, "f", y___], StandardForm] :=
MakeExpression[h[x, "BigFunction", y], StandardForm]


and it should cover ***Box cases:

• It works. But I'm worried the catch-all pattern might be quite inefficient for larger inputs. Do you have any thoughts on this, or have any alternatives in mind? Also, do you know if Mathematica uses the same catch-all pattern to parse π -> Pi? Commented Oct 17, 2016 at 13:23
• @QuantumDot yep, noticed that inconvenience, I will try to figure it out ;) \$PreRead would be a quick fix but it is not what should be done.
– Kuba
Commented Oct 18, 2016 at 14:02
• @QuantumDot is my edit enough?
– Kuba
Commented Oct 18, 2016 at 14:23
• @QuantumDot I've talked with J.Harris at WTC about that, it seems that symbols like Pi are handled in a special way so those three rules seem inevitable.
– Kuba
Commented Nov 15, 2016 at 8:40
• I couldn't get the third rule to work unless I use: MakeExpression[RowBox[{h_, "[", RowBox[{x___, "f", y___}], "]"}], StandardForm] := MakeExpression[RowBox[{h, "[", RowBox[{x, "BigFunction", y}], "]"}], StandardForm]. Is that what you meant? Commented Jul 29, 2017 at 1:31