HoldForm: Display exactly as entered?

Multi tool use
Multi tool use









9












$begingroup$


Sometimes, Mathematica's internal representation of expressions can give somewhat surprising results. Specifically, I noticed this when I tried to preserve products of fractions for display.



E.g. the following example as in "HoldForm does not Hold Form for fractions sometimes":



enter image description here



i.e. it isn't easily possible to preserve the output fractions as they are written. This is actually surprising though, because Mathematica internally preserves the "product of two fractions" form:



In[1]:= HoldForm[1/x 1/y] // InputForm
Out[1]= HoldForm[(1/x)*(1/y)]

In[2]:= HoldForm[1/x 1/y] // FullForm
Out[2]= HoldForm[Times[Times[1,Power[x,-1]],Times[1,Power[y,-1]]]]


Is there some way to get Mathematica to display such forms as actual product of fractions in any of the formatted output forms, without manually adding holdform constructs?










share|improve this question











$endgroup$







  • 1




    $begingroup$
    As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway?
    $endgroup$
    – Kuba
    Nov 15 '18 at 11:33










  • $begingroup$
    Strongly related: (1), (2).
    $endgroup$
    – Alexey Popkov
    Nov 15 '18 at 11:35















9












$begingroup$


Sometimes, Mathematica's internal representation of expressions can give somewhat surprising results. Specifically, I noticed this when I tried to preserve products of fractions for display.



E.g. the following example as in "HoldForm does not Hold Form for fractions sometimes":



enter image description here



i.e. it isn't easily possible to preserve the output fractions as they are written. This is actually surprising though, because Mathematica internally preserves the "product of two fractions" form:



In[1]:= HoldForm[1/x 1/y] // InputForm
Out[1]= HoldForm[(1/x)*(1/y)]

In[2]:= HoldForm[1/x 1/y] // FullForm
Out[2]= HoldForm[Times[Times[1,Power[x,-1]],Times[1,Power[y,-1]]]]


Is there some way to get Mathematica to display such forms as actual product of fractions in any of the formatted output forms, without manually adding holdform constructs?










share|improve this question











$endgroup$







  • 1




    $begingroup$
    As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway?
    $endgroup$
    – Kuba
    Nov 15 '18 at 11:33










  • $begingroup$
    Strongly related: (1), (2).
    $endgroup$
    – Alexey Popkov
    Nov 15 '18 at 11:35













9












9








9


3



$begingroup$


Sometimes, Mathematica's internal representation of expressions can give somewhat surprising results. Specifically, I noticed this when I tried to preserve products of fractions for display.



E.g. the following example as in "HoldForm does not Hold Form for fractions sometimes":



enter image description here



i.e. it isn't easily possible to preserve the output fractions as they are written. This is actually surprising though, because Mathematica internally preserves the "product of two fractions" form:



In[1]:= HoldForm[1/x 1/y] // InputForm
Out[1]= HoldForm[(1/x)*(1/y)]

In[2]:= HoldForm[1/x 1/y] // FullForm
Out[2]= HoldForm[Times[Times[1,Power[x,-1]],Times[1,Power[y,-1]]]]


Is there some way to get Mathematica to display such forms as actual product of fractions in any of the formatted output forms, without manually adding holdform constructs?










share|improve this question











$endgroup$




Sometimes, Mathematica's internal representation of expressions can give somewhat surprising results. Specifically, I noticed this when I tried to preserve products of fractions for display.



E.g. the following example as in "HoldForm does not Hold Form for fractions sometimes":



enter image description here



i.e. it isn't easily possible to preserve the output fractions as they are written. This is actually surprising though, because Mathematica internally preserves the "product of two fractions" form:



In[1]:= HoldForm[1/x 1/y] // InputForm
Out[1]= HoldForm[(1/x)*(1/y)]

In[2]:= HoldForm[1/x 1/y] // FullForm
Out[2]= HoldForm[Times[Times[1,Power[x,-1]],Times[1,Power[y,-1]]]]


Is there some way to get Mathematica to display such forms as actual product of fractions in any of the formatted output forms, without manually adding holdform constructs?







evaluation output-formatting hold display






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 11:32









Alexey Popkov

38.7k4108265




38.7k4108265










asked Nov 15 '18 at 11:02









kdbkdb

1513




1513







  • 1




    $begingroup$
    As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway?
    $endgroup$
    – Kuba
    Nov 15 '18 at 11:33










  • $begingroup$
    Strongly related: (1), (2).
    $endgroup$
    – Alexey Popkov
    Nov 15 '18 at 11:35












  • 1




    $begingroup$
    As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway?
    $endgroup$
    – Kuba
    Nov 15 '18 at 11:33










  • $begingroup$
    Strongly related: (1), (2).
    $endgroup$
    – Alexey Popkov
    Nov 15 '18 at 11:35







1




1




$begingroup$
As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway?
$endgroup$
– Kuba
Nov 15 '18 at 11:33




$begingroup$
As to the final question, why not just convert input cell to the output once you are done with the input that should not be modified anyway?
$endgroup$
– Kuba
Nov 15 '18 at 11:33












$begingroup$
Strongly related: (1), (2).
$endgroup$
– Alexey Popkov
Nov 15 '18 at 11:35




$begingroup$
Strongly related: (1), (2).
$endgroup$
– Alexey Popkov
Nov 15 '18 at 11:35










3 Answers
3






active

oldest

votes


















3












$begingroup$

How about:



MakeBoxes[Times[a_, b_], StandardForm] := RowBox[MakeBoxes@a, MakeBoxes@b]
1/x 1/y 1/z


Mathematica graphics






share|improve this answer











$endgroup$












  • $begingroup$
    Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
    $endgroup$
    – Kuba
    Nov 15 '18 at 11:17











  • $begingroup$
    @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
    $endgroup$
    – xzczd
    Nov 15 '18 at 11:28











  • $begingroup$
    Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
    $endgroup$
    – kdb
    Nov 15 '18 at 15:06










  • $begingroup$
    @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
    $endgroup$
    – xzczd
    Nov 15 '18 at 15:37


















3












$begingroup$

IMO, the only way to be sure is to interfere as soon as possible:



$PreRead = Function[boxes
, boxes /.
RowBox["RawInput", "[", hf_, "]"] :>
RowBox["RawBoxes", "[", ToBoxes[hf], "]"]
];


enter image description here






share|improve this answer











$endgroup$




















    3












    $begingroup$

    Another possibility is to use InString:



    1/x 1/y
    ToExpression[InString[-1], StandardForm, RawBoxes]


    screenshot






    share|improve this answer









    $endgroup$













      Your Answer








      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      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%2f186025%2fholdform-display-exactly-as-entered%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3












      $begingroup$

      How about:



      MakeBoxes[Times[a_, b_], StandardForm] := RowBox[MakeBoxes@a, MakeBoxes@b]
      1/x 1/y 1/z


      Mathematica graphics






      share|improve this answer











      $endgroup$












      • $begingroup$
        Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
        $endgroup$
        – Kuba
        Nov 15 '18 at 11:17











      • $begingroup$
        @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
        $endgroup$
        – xzczd
        Nov 15 '18 at 11:28











      • $begingroup$
        Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
        $endgroup$
        – kdb
        Nov 15 '18 at 15:06










      • $begingroup$
        @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
        $endgroup$
        – xzczd
        Nov 15 '18 at 15:37















      3












      $begingroup$

      How about:



      MakeBoxes[Times[a_, b_], StandardForm] := RowBox[MakeBoxes@a, MakeBoxes@b]
      1/x 1/y 1/z


      Mathematica graphics






      share|improve this answer











      $endgroup$












      • $begingroup$
        Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
        $endgroup$
        – Kuba
        Nov 15 '18 at 11:17











      • $begingroup$
        @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
        $endgroup$
        – xzczd
        Nov 15 '18 at 11:28











      • $begingroup$
        Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
        $endgroup$
        – kdb
        Nov 15 '18 at 15:06










      • $begingroup$
        @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
        $endgroup$
        – xzczd
        Nov 15 '18 at 15:37













      3












      3








      3





      $begingroup$

      How about:



      MakeBoxes[Times[a_, b_], StandardForm] := RowBox[MakeBoxes@a, MakeBoxes@b]
      1/x 1/y 1/z


      Mathematica graphics






      share|improve this answer











      $endgroup$



      How about:



      MakeBoxes[Times[a_, b_], StandardForm] := RowBox[MakeBoxes@a, MakeBoxes@b]
      1/x 1/y 1/z


      Mathematica graphics







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 15 '18 at 11:21

























      answered Nov 15 '18 at 11:13









      xzczdxzczd

      27.6k574257




      27.6k574257











      • $begingroup$
        Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
        $endgroup$
        – Kuba
        Nov 15 '18 at 11:17











      • $begingroup$
        @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
        $endgroup$
        – xzczd
        Nov 15 '18 at 11:28











      • $begingroup$
        Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
        $endgroup$
        – kdb
        Nov 15 '18 at 15:06










      • $begingroup$
        @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
        $endgroup$
        – xzczd
        Nov 15 '18 at 15:37
















      • $begingroup$
        Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
        $endgroup$
        – Kuba
        Nov 15 '18 at 11:17











      • $begingroup$
        @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
        $endgroup$
        – xzczd
        Nov 15 '18 at 11:28











      • $begingroup$
        Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
        $endgroup$
        – kdb
        Nov 15 '18 at 15:06










      • $begingroup$
        @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
        $endgroup$
        – xzczd
        Nov 15 '18 at 15:37















      $begingroup$
      Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
      $endgroup$
      – Kuba
      Nov 15 '18 at 11:17





      $begingroup$
      Btw, one could argue that 1/x should be kept in that exact form too, that is no fraction box in input, no fraction box in output.
      $endgroup$
      – Kuba
      Nov 15 '18 at 11:17













      $begingroup$
      @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
      $endgroup$
      – xzczd
      Nov 15 '18 at 11:28





      $begingroup$
      @kuba Oh I forgot about that, now I've turned to MakeBoxes in all places, thanks for pointing out. As to "no fraction box in input, no fraction box in output" part, I think OP's goal is just obtaining an output consistent with the FullForm of the expression, so I'd like to stop here. (I admit that's a harder and interesting question though. Perhaps a new question like "Can I make the display of expression changeless at all?" should be asked? )
      $endgroup$
      – xzczd
      Nov 15 '18 at 11:28













      $begingroup$
      Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
      $endgroup$
      – kdb
      Nov 15 '18 at 15:06




      $begingroup$
      Useful for my usecase, as it controls exactly what is displayed how. I suppose nothing more catch-all than this is doable. @xzczd I'd also prefer if it were possible to keep "1/x" vs the 2-dimensional form separate, but I don't think that this distinction is even kept in the internal representation.
      $endgroup$
      – kdb
      Nov 15 '18 at 15:06












      $begingroup$
      @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
      $endgroup$
      – xzczd
      Nov 15 '18 at 15:37




      $begingroup$
      @kdb Yeah, if $1/x$ and $frac1x$ needs to be distincted, I'm afraid something as shown in Kuba's answer is necessary. I hope I'm wrong.
      $endgroup$
      – xzczd
      Nov 15 '18 at 15:37











      3












      $begingroup$

      IMO, the only way to be sure is to interfere as soon as possible:



      $PreRead = Function[boxes
      , boxes /.
      RowBox["RawInput", "[", hf_, "]"] :>
      RowBox["RawBoxes", "[", ToBoxes[hf], "]"]
      ];


      enter image description here






      share|improve this answer











      $endgroup$

















        3












        $begingroup$

        IMO, the only way to be sure is to interfere as soon as possible:



        $PreRead = Function[boxes
        , boxes /.
        RowBox["RawInput", "[", hf_, "]"] :>
        RowBox["RawBoxes", "[", ToBoxes[hf], "]"]
        ];


        enter image description here






        share|improve this answer











        $endgroup$















          3












          3








          3





          $begingroup$

          IMO, the only way to be sure is to interfere as soon as possible:



          $PreRead = Function[boxes
          , boxes /.
          RowBox["RawInput", "[", hf_, "]"] :>
          RowBox["RawBoxes", "[", ToBoxes[hf], "]"]
          ];


          enter image description here






          share|improve this answer











          $endgroup$



          IMO, the only way to be sure is to interfere as soon as possible:



          $PreRead = Function[boxes
          , boxes /.
          RowBox["RawInput", "[", hf_, "]"] :>
          RowBox["RawBoxes", "[", ToBoxes[hf], "]"]
          ];


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 11:48

























          answered Nov 15 '18 at 11:42









          KubaKuba

          107k12211534




          107k12211534





















              3












              $begingroup$

              Another possibility is to use InString:



              1/x 1/y
              ToExpression[InString[-1], StandardForm, RawBoxes]


              screenshot






              share|improve this answer









              $endgroup$

















                3












                $begingroup$

                Another possibility is to use InString:



                1/x 1/y
                ToExpression[InString[-1], StandardForm, RawBoxes]


                screenshot






                share|improve this answer









                $endgroup$















                  3












                  3








                  3





                  $begingroup$

                  Another possibility is to use InString:



                  1/x 1/y
                  ToExpression[InString[-1], StandardForm, RawBoxes]


                  screenshot






                  share|improve this answer









                  $endgroup$



                  Another possibility is to use InString:



                  1/x 1/y
                  ToExpression[InString[-1], StandardForm, RawBoxes]


                  screenshot







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 13:20









                  Alexey PopkovAlexey Popkov

                  38.7k4108265




                  38.7k4108265



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186025%2fholdform-display-exactly-as-entered%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      aD YUbhwTkbZ8NCuE,gsrs E889 6 yfi0tX,MApkpadWsgkfq0wvN O O1Ly,CYiH8wauQ Uu 7wKbK AoL shMDlQQPFk6MmiR
                      hNG5N,KQy0,p,qhlKG,PpfW1r2E JakeNmVI 1h5,aT2XB7LZ5kU4v lU2

                      Popular posts from this blog

                      Use pre created SQLite database for Android project in kotlin

                      Ruanda

                      Ondo