4
$\begingroup$

I am trying to define a function that has similar behavior as Indexed. Here is the code

Format[me : f[a_, i__]] := Interpretation[Subscript[a, i], me];
f[a_ + b_, i__] := f[a, i] + f[b, i];

For example, f[a + b, 1] will give

a1+b1

as expected. However, if I try ?f to view the code, I will run into the RecursionLimit error. The question is how to appropriately define the format to avoid this error, while still give the desired subscript formatting behavior?

$\endgroup$
3
  • $\begingroup$ Related but not AFAICT a solution in this case: stackoverflow.com/q/4112299/618728 $\endgroup$
    – Mr.Wizard
    Commented Dec 26, 2016 at 3:31
  • $\begingroup$ I don't have more time to look at this (it's Christmas!) but I am suspicious of a bug in Information here. I'll try to figure this out later if it's not solved by then. $\endgroup$
    – Mr.Wizard
    Commented Dec 26, 2016 at 3:36
  • $\begingroup$ You can view the code with Definition @ f $\endgroup$
    – m_goldberg
    Commented Dec 26, 2016 at 6:24

1 Answer 1

5
$\begingroup$

I would use:

f /: MakeBoxes[f[a_, i__], form:StandardForm] := With[
    {s = MakeBoxes[Subscript[a, i], form]},
    InterpretationBox[s, f[a, i]]
]

instead.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.