I'm used to pressing Ctrl+Shift+I (or N if I want a shorter form) to reformat my input cells in a nicer way after editing them, e.g., to remove unnecessary parentheses, add or remove spaces as needed, etc.
The issue comes when I define a custom output format for some expression. For example, let's say that I'm working with indexed variables of the form a[i, j]. It's easier to use, for example because I can just match patterns with things like _a. However, it is visually more pleasing to view such a variable as Subscript[a, i, j] in the output of a computation, because (among other things) that's what I actually write on my piece of paper when doing the math myself.
I know how to define an output format that takes care of the visual aspect:
Format[a[i_, j_]] := Subscript[a, i, j] a[1, 2] + a[2, 3] (* will display as expected *) However, if I then use Ctrl+Shift+I on a cell that contains a[1,2], the expression will turn into Subscript[a, 1, 2], with no turning back.
Some options I'm aware of:
- Use the
Notationpackage. But it seems heavy weight, and if I want to avoid breaking Ctrl+Shift+N, I need to define two-way notation, which could be undesirable. - Define a
formatfunction likeformat[expr_] := expr /. a[i_, j_] :> Subscript[a, i, j]and then set$Post = format. But then, this runs every single time I get an output, and I'm afraid theReplaceAllwill get slow on large expressions, or if I start having more custom notation.
Any ideas?


