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.
fooshould have no effect on the evaluation offoo. You probably have a lingering definition offoothat is causing issues. – Carl Woll Aug 21 '19 at 19:12foo[r_,m_][h_]:= m h + rand kglr'sMakeBoxesdef,foo[2,3][4]displays the subscript form but does not evaluatefooto rhs. – alancalvitti Aug 21 '19 at 19:25ClearAll[foo]command as well? – Carl Woll Aug 21 '19 at 19:50