The problem you are facing is that the FullForm
of x/2
changes in the assessment, combined with HoldAllComplete
attribute of MakeBoxes
:
Hold(a/2)//FullForm
(* Hold(Times(a,Power(2,-1))) *)
a/2//FullForm
(* Times(Rational(1,2),a) *)
Note how $ a cdot2 ^ {- 1} $ changes made to $ a cdot frac $ 12 when he is allowed to evaluate. As mentioned above, this leads to problems due to the HoldAllComplete
attribute of MakeBoxes
: You define a rule for the form that you enter, which means that it will not be applied to the evaluated form:
MakeBoxes(Sin(Subscript(α, i) / 2), StandardForm) =
MakeBoxes(Subscript(s, Subscript(Overscript(α, _), 2)), StandardForm)
Sin(Subscript((Alpha), i)/2)
$ sin ( frac alpha2) $
HoldForm(Sin(Subscript((Alpha), i)/2))
$ s _ { bar { alpha} _2} $
To resolve this problem, you must define a formatting rule for the evaluated form:
MakeBoxes(Sin(Rational(1, 2) Subscript(α, i)), StandardForm) =
MakeBoxes(Subscript(s, Subscript(Overscript(α, _), 2)), StandardForm)
Sin(Subscript((Alpha), i)/2)
$ s _ { bar { alpha} _2} $
You can also inject the evaluated form into MakeBoxes
:
With(
{evaluated = Sin(Subscript(α, i) / 2)},
MakeBoxes(evaluated, StandardForm) =
MakeBoxes(Subscript(s, Subscript(Overscript(α, _), 2)), StandardForm)
)
Sin(Subscript((Alpha), i)/2)
$ s _ { bar { alpha} _2} $
Note that the use Evaluate
would not work because HoldAllComplete
prevents any form of evaluation, including Evaluate
and up-values.