How to customize traditional form for inactive functions?

The name of the pictureThe name of the pictureThe name of the pictureClash 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)






share|improve this question


























    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)






    share|improve this question
























      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)






      share|improve this question














      Let's say I define



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


      How do I make



      Inactive[Lg][x]//TraditionalForm


      output



      lg(x)








      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 16 at 12:19









      xzczd

      23.8k364224




      23.8k364224










      asked Aug 16 at 10:48









      ablmf

      1714




      1714




















          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


          enter image description here






          share|improve this answer



























            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.






            share|improve this answer




















              Your Answer




              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "387"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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






























              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


              enter image description here






              share|improve this answer
























                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


                enter image description here






                share|improve this answer






















                  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


                  enter image description here






                  share|improve this answer












                  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


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 16 at 12:47









                  Kuba♦

                  99.3k11194491




                  99.3k11194491




















                      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.






                      share|improve this answer
























                        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.






                        share|improve this answer






















                          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.






                          share|improve this answer












                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 16 at 13:17









                          Lukas Lang

                          5,1531525




                          5,1531525



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery