HoldForm: Display exactly as entered?











up vote
7
down vote

favorite
2












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









New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    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?
    – Kuba
    Nov 15 at 11:33










  • Strongly related: (1), (2).
    – Alexey Popkov
    Nov 15 at 11:35















up vote
7
down vote

favorite
2












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









New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    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?
    – Kuba
    Nov 15 at 11:33










  • Strongly related: (1), (2).
    – Alexey Popkov
    Nov 15 at 11:35













up vote
7
down vote

favorite
2









up vote
7
down vote

favorite
2






2





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









New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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









New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 15 at 11:32









Alexey Popkov

38k4104260




38k4104260






New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 15 at 11:02









kdb

1413




1413




New contributor




kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






kdb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    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?
    – Kuba
    Nov 15 at 11:33










  • Strongly related: (1), (2).
    – Alexey Popkov
    Nov 15 at 11:35














  • 1




    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?
    – Kuba
    Nov 15 at 11:33










  • Strongly related: (1), (2).
    – Alexey Popkov
    Nov 15 at 11:35








1




1




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?
– Kuba
Nov 15 at 11:33




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?
– Kuba
Nov 15 at 11:33












Strongly related: (1), (2).
– Alexey Popkov
Nov 15 at 11:35




Strongly related: (1), (2).
– Alexey Popkov
Nov 15 at 11:35










3 Answers
3






active

oldest

votes

















up vote
3
down vote













How about:



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


Mathematica graphics






share|improve this answer























  • 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.
    – Kuba
    Nov 15 at 11:17












  • @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? )
    – xzczd
    Nov 15 at 11:28












  • 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.
    – kdb
    Nov 15 at 15:06










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


















up vote
3
down vote













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






























    up vote
    3
    down vote













    Another possibility is to use InString:



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


    screenshot






    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: 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
      });


      }
      });






      kdb is a new contributor. Be nice, and check out our Code of Conduct.










       

      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








      up vote
      3
      down vote













      How about:



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


      Mathematica graphics






      share|improve this answer























      • 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.
        – Kuba
        Nov 15 at 11:17












      • @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? )
        – xzczd
        Nov 15 at 11:28












      • 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.
        – kdb
        Nov 15 at 15:06










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















      up vote
      3
      down vote













      How about:



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


      Mathematica graphics






      share|improve this answer























      • 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.
        – Kuba
        Nov 15 at 11:17












      • @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? )
        – xzczd
        Nov 15 at 11:28












      • 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.
        – kdb
        Nov 15 at 15:06










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













      up vote
      3
      down vote










      up vote
      3
      down vote









      How about:



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


      Mathematica graphics






      share|improve this answer














      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 at 11:21

























      answered Nov 15 at 11:13









      xzczd

      25.5k468243




      25.5k468243












      • 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.
        – Kuba
        Nov 15 at 11:17












      • @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? )
        – xzczd
        Nov 15 at 11:28












      • 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.
        – kdb
        Nov 15 at 15:06










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


















      • 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.
        – Kuba
        Nov 15 at 11:17












      • @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? )
        – xzczd
        Nov 15 at 11:28












      • 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.
        – kdb
        Nov 15 at 15:06










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
















      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.
      – Kuba
      Nov 15 at 11:17






      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.
      – Kuba
      Nov 15 at 11:17














      @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? )
      – xzczd
      Nov 15 at 11:28






      @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? )
      – xzczd
      Nov 15 at 11:28














      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.
      – kdb
      Nov 15 at 15:06




      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.
      – kdb
      Nov 15 at 15:06












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




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










      up vote
      3
      down vote













      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



























        up vote
        3
        down vote













        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

























          up vote
          3
          down vote










          up vote
          3
          down vote









          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














          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 at 11:48

























          answered Nov 15 at 11:42









          Kuba

          102k12199509




          102k12199509






















              up vote
              3
              down vote













              Another possibility is to use InString:



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


              screenshot






              share|improve this answer

























                up vote
                3
                down vote













                Another possibility is to use InString:



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


                screenshot






                share|improve this answer























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  Another possibility is to use InString:



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


                  screenshot






                  share|improve this answer












                  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 at 13:20









                  Alexey Popkov

                  38k4104260




                  38k4104260






















                      kdb is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      kdb is a new contributor. Be nice, and check out our Code of Conduct.













                      kdb is a new contributor. Be nice, and check out our Code of Conduct.












                      kdb is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      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







                      Popular posts from this blog

                      mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                      How to change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?