Let's say I define


How do I make




2 Answers 2


From GeneralUtilities`PrintDefinitions @ Inactive one can gather that it is NumericFunction attribute which enables () in TraditionalForm, as opposed to [].

So if you don't mind we can set them. And one thing that is left is to change Lg to lowercase during typesetting:


Lg[n_] := Log[2, n];

SetAttributes[Lg, NumericFunction];
Lg /: MakeBoxes[Lg, TraditionalForm] := "lg"

Inactive[Lg][x] // TraditionalForm

enter image description here


In general I would definitely prefer @Kuba's solution, but in case you can't add the NumericFunction attribute for some reason and you still want (…) instead of […], or if you want more control in general, you can do something like the following:

Inactive /: MakeBoxes[Inactive[Lg][n_], TraditionalForm] := 
 RowBox@{"ln", "(", MakeBoxes[n, TraditionalForm], ")"}

Of course, this simple formatting rule does not show the "Inactive[…]" tooltip that is normally added (if you want it, just adapt the above rule)

Important: Be sure to evaluate this before anything else relating to Inactive, otherwise it won't work.

Why does it not work otherwise?

The issue is that Inactive expressions are formatted via upvalues (or apparently FormatValues to be more precise) of Inactive. This means that you cannot attach the rule to MakeBoxes or Format as you would normally, as these are applied too late in the process. And to make sure that your definition is evaluated before any of the other definitions, you have to make your definition before any of the others are loaded.


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.