5
$\begingroup$

StandardForm of E is \[ExponentialE], can we modify it to something else?

I thought I could use MakeBoxes and InterpretationBox like the following:

MakeBoxes[E, StandardForm] := 
 InterpretationBox[StyleBox[ "ℰ", FontColor -> #], E] &@Orange

enter image description here

But as we can see, it doesn't work as expected. The method does work for simpler case, though:

MakeBoxes[a, StandardForm] := 
 InterpretationBox[StyleBox[ "α", FontColor -> #], a] &@Orange

enter image description here

What's wrong with my attempt? What's the correct way to modify StandardForm of E?

$\endgroup$

1 Answer 1

4
$\begingroup$

Simply due to definition priority mechanism.

Each of these three works:

GeneralUtilities`BlockProtected[E,
  E /: MakeBoxes[E, StandardForm] := 
    InterpretationBox[StyleBox["ℰ", FontColor -> #], E] &@Orange;
]
E
GeneralUtilities`BlockProtected[E,
  E/:MakeBoxes[E, _]=.;
];
MakeBoxes[E, StandardForm] := 
  InterpretationBox[StyleBox["ℰ", FontColor -> #], E] &@Orange
E
GeneralUtilities`BlockProtected[E,
  Format[E, StandardForm] := 
    Interpretation[Style[ "ℰ", FontColor -> Orange], E]
]
E

We can see that a Format definition precedes a MakeBoxes definition (this is documented), and the one bound to E precedes the one bound to MakeBoxes


To revert the changes:

GeneralUtilities`BlockProtected[E,
  MakeBoxes[E, StandardForm]=.;
  E/:MakeBoxes[E, StandardForm]=.;
  Format[E, StandardForm]=.;
  E/:MakeBoxes[E, _]:="\[ExponentialE]"
] //Quiet
$\endgroup$
5
  • $\begingroup$ Interesting, so there's a hidden upvalue for E. Then I'd like to point out that, the Format solution is inferior compared with the MakeBox solutions, just try converting the E with Ctrl+Shift+N, or editing the output, you'll know what I mean. $\endgroup$
    – xzczd
    Commented May 31, 2022 at 15:25
  • $\begingroup$ @xzczd 1. I think it's not hidden, which you can see it in FormatValues@E; $\endgroup$
    – rnotlnglgq
    Commented Jun 1, 2022 at 7:29
  • $\begingroup$ 2. That's true, that causes an infinite recursion. $\endgroup$
    – rnotlnglgq
    Commented Jun 1, 2022 at 7:31
  • $\begingroup$ Oh I forgot about FormatValues! But FormatValues is not documented, and usually the format value can be checked with ?? (here's an example) but it's not the case for E, so I'd still argue this is hidden :) . $\endgroup$
    – xzczd
    Commented Jun 1, 2022 at 7:52
  • $\begingroup$ @xzczd Which is to blame is Internal`InformationDefinitions . As I use GeneralUtilities`PrintDefinitions more, it won't hide from me. $\endgroup$
    – rnotlnglgq
    Commented Jun 1, 2022 at 11:04

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.