Related to this question,
Why does this InterpretationBox
construct work when x
, y
are numbers but not undefined symbols or more complex expressions?
foo /: MakeBoxes[c : foo[x_, y_], form : (StandardForm | TraditionalForm)] := With[{boxes = SubscriptBox[x, y]}, InterpretationBox[boxes, c]]
EDIT
Originally intended to state the full problem but then simplified it. kglr's answer does not work as intended, so here is the complication:
Would like foo[r,m]
to display in subscript form, but when provided with a SubValue
, it should evaluate to the rhs:
foo[r_,m_][h_]:= m h + r
END EDIT
Works:
foo[2,3]
Subscript[2, 3]
Plugging in x
inserts $CellContext
:
foo[2, x]
Subscript[2, $CellContext`x]
or fails with List
:
foo[{1, 2}, 3]
An unknown box name (List) was sent as the BoxForm for the expression. Check the format rules for the expression.
foo
should have no effect on the evaluation offoo
. You probably have a lingering definition offoo
that is causing issues. $\endgroup$foo[r_,m_][h_]:= m h + r
and kglr'sMakeBoxes
def,foo[2,3][4]
displays the subscript form but does not evaluatefoo
to rhs. $\endgroup$ClearAll[foo]
command as well? $\endgroup$