How to customize traditional form for inactive functions?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Let's say I define
Lg[n_]:=Log[2,n].
How do I make
Inactive[Lg][x]//TraditionalForm
output
lg(x)
formatting hold traditional-form
add a comment |Â
up vote
4
down vote
favorite
Let's say I define
Lg[n_]:=Log[2,n].
How do I make
Inactive[Lg][x]//TraditionalForm
output
lg(x)
formatting hold traditional-form
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Let's say I define
Lg[n_]:=Log[2,n].
How do I make
Inactive[Lg][x]//TraditionalForm
output
lg(x)
formatting hold traditional-form
Let's say I define
Lg[n_]:=Log[2,n].
How do I make
Inactive[Lg][x]//TraditionalForm
output
lg(x)
formatting hold traditional-form
edited Aug 16 at 12:19


xzczd
23.8k364224
23.8k364224
asked Aug 16 at 10:48
ablmf
1714
1714
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
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:
ClearAll[Lg];
Lg[n_] := Log[2, n];
SetAttributes[Lg, NumericFunction];
Lg /: MakeBoxes[Lg, TraditionalForm] := "lg"
Inactive[Lg][x] // TraditionalForm
add a comment |Â
up vote
5
down vote
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:
Unprotect@Inactive
Inactive /: MakeBoxes[Inactive[Lg][n_], TraditionalForm] :=
RowBox@"ln", "(", MakeBoxes[n, TraditionalForm], ")"
Protect@Inactive
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.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
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:
ClearAll[Lg];
Lg[n_] := Log[2, n];
SetAttributes[Lg, NumericFunction];
Lg /: MakeBoxes[Lg, TraditionalForm] := "lg"
Inactive[Lg][x] // TraditionalForm
add a comment |Â
up vote
4
down vote
accepted
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:
ClearAll[Lg];
Lg[n_] := Log[2, n];
SetAttributes[Lg, NumericFunction];
Lg /: MakeBoxes[Lg, TraditionalForm] := "lg"
Inactive[Lg][x] // TraditionalForm
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
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:
ClearAll[Lg];
Lg[n_] := Log[2, n];
SetAttributes[Lg, NumericFunction];
Lg /: MakeBoxes[Lg, TraditionalForm] := "lg"
Inactive[Lg][x] // TraditionalForm
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:
ClearAll[Lg];
Lg[n_] := Log[2, n];
SetAttributes[Lg, NumericFunction];
Lg /: MakeBoxes[Lg, TraditionalForm] := "lg"
Inactive[Lg][x] // TraditionalForm
answered Aug 16 at 12:47


Kuba♦
99.3k11194491
99.3k11194491
add a comment |Â
add a comment |Â
up vote
5
down vote
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:
Unprotect@Inactive
Inactive /: MakeBoxes[Inactive[Lg][n_], TraditionalForm] :=
RowBox@"ln", "(", MakeBoxes[n, TraditionalForm], ")"
Protect@Inactive
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.
add a comment |Â
up vote
5
down vote
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:
Unprotect@Inactive
Inactive /: MakeBoxes[Inactive[Lg][n_], TraditionalForm] :=
RowBox@"ln", "(", MakeBoxes[n, TraditionalForm], ")"
Protect@Inactive
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.
add a comment |Â
up vote
5
down vote
up vote
5
down vote
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:
Unprotect@Inactive
Inactive /: MakeBoxes[Inactive[Lg][n_], TraditionalForm] :=
RowBox@"ln", "(", MakeBoxes[n, TraditionalForm], ")"
Protect@Inactive
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.
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:
Unprotect@Inactive
Inactive /: MakeBoxes[Inactive[Lg][n_], TraditionalForm] :=
RowBox@"ln", "(", MakeBoxes[n, TraditionalForm], ")"
Protect@Inactive
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.
answered Aug 16 at 13:17


Lukas Lang
5,1531525
5,1531525
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180107%2fhow-to-customize-traditional-form-for-inactive-functions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password