Print integer number fraction as string of numerator and denominator












3












$begingroup$


I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = {0, 2, 3, 0, 4};
y = {4, 5, 12, 10, 1};

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values {0/4, 2/5, 3/12, 0/1, 4/1} and not the results.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    11 hours ago






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1}
    $endgroup$
    – lio
    11 hours ago


















3












$begingroup$


I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = {0, 2, 3, 0, 4};
y = {4, 5, 12, 10, 1};

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values {0/4, 2/5, 3/12, 0/1, 4/1} and not the results.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    11 hours ago






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1}
    $endgroup$
    – lio
    11 hours ago
















3












3








3





$begingroup$


I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = {0, 2, 3, 0, 4};
y = {4, 5, 12, 10, 1};

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values {0/4, 2/5, 3/12, 0/1, 4/1} and not the results.










share|improve this question











$endgroup$




I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = {0, 2, 3, 0, 4};
y = {4, 5, 12, 10, 1};

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values {0/4, 2/5, 3/12, 0/1, 4/1} and not the results.







string-manipulation style number-form






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 hours ago







lio

















asked 12 hours ago









liolio

1,083217




1,083217








  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    11 hours ago






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1}
    $endgroup$
    – lio
    11 hours ago
















  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    11 hours ago






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    11 hours ago










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1}
    $endgroup$
    – lio
    11 hours ago










1




1




$begingroup$
One quick way is to replace 0 with "0".
$endgroup$
– b.gatessucks
11 hours ago




$begingroup$
One quick way is to replace 0 with "0".
$endgroup$
– b.gatessucks
11 hours ago




2




2




$begingroup$
What is allowed to be simplified? E.g. you don't complain about 3/12.
$endgroup$
– Kuba
11 hours ago




$begingroup$
What is allowed to be simplified? E.g. you don't complain about 3/12.
$endgroup$
– Kuba
11 hours ago












$begingroup$
Closely related: mathematica.stackexchange.com/q/71938/5478
$endgroup$
– Kuba
11 hours ago




$begingroup$
Closely related: mathematica.stackexchange.com/q/71938/5478
$endgroup$
– Kuba
11 hours ago












$begingroup$
@Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1}
$endgroup$
– lio
11 hours ago






$begingroup$
@Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1}
$endgroup$
– lio
11 hours ago












2 Answers
2






active

oldest

votes


















5












$begingroup$

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
(HoldForm /@ x / HoldForm /@ y)


enter image description here



Also



Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
Inactivate[Divide[x, y]], {-1}] // Activate



same picture




and



style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
(style /@ x )/(style /@ y)



same picture




Update: You can use



MapThread[Style[Row[{##}, "/"], FontFamily -> "Calibri", 20, Red] &, {x, y}]


or



Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
MapThread[Row[{##}, "/"] &, {x, y}]


to get



enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
    $endgroup$
    – lio
    11 hours ago












  • $begingroup$
    @lio, please see the update.
    $endgroup$
    – kglr
    11 hours ago










  • $begingroup$
    Thank you so much ...
    $endgroup$
    – lio
    11 hours ago












  • $begingroup$
    @lio, my pleasure.
    $endgroup$
    – kglr
    11 hours ago



















1












$begingroup$

You could create a wrapper that formats as desired:



MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
StandardForm
]


Then:



x = {0, 2, 3, 0, 4};
y = {4, 5, 12, 10, 1};

MapThread[HoldRational, {x, y}]


enter image description here






share|improve this answer









$endgroup$













    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',
    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%2f191743%2fprint-integer-number-fraction-as-string-of-numerator-and-denominator%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5












    $begingroup$

    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], {-1}] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[{##}, "/"], FontFamily -> "Calibri", 20, Red] &, {x, y}]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[{##}, "/"] &, {x, y}]


    to get



    enter image description here






    share|improve this answer











    $endgroup$













    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      11 hours ago










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      11 hours ago
















    5












    $begingroup$

    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], {-1}] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[{##}, "/"], FontFamily -> "Calibri", 20, Red] &, {x, y}]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[{##}, "/"] &, {x, y}]


    to get



    enter image description here






    share|improve this answer











    $endgroup$













    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      11 hours ago










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      11 hours ago














    5












    5








    5





    $begingroup$

    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], {-1}] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[{##}, "/"], FontFamily -> "Calibri", 20, Red] &, {x, y}]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[{##}, "/"] &, {x, y}]


    to get



    enter image description here






    share|improve this answer











    $endgroup$



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], {-1}] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[{##}, "/"], FontFamily -> "Calibri", 20, Red] &, {x, y}]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[{##}, "/"] &, {x, y}]


    to get



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 11 hours ago

























    answered 11 hours ago









    kglrkglr

    184k10202420




    184k10202420












    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      11 hours ago










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      11 hours ago


















    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      11 hours ago










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      11 hours ago












    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      11 hours ago
















    $begingroup$
    This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
    $endgroup$
    – lio
    11 hours ago






    $begingroup$
    This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
    $endgroup$
    – lio
    11 hours ago














    $begingroup$
    @lio, please see the update.
    $endgroup$
    – kglr
    11 hours ago




    $begingroup$
    @lio, please see the update.
    $endgroup$
    – kglr
    11 hours ago












    $begingroup$
    Thank you so much ...
    $endgroup$
    – lio
    11 hours ago






    $begingroup$
    Thank you so much ...
    $endgroup$
    – lio
    11 hours ago














    $begingroup$
    @lio, my pleasure.
    $endgroup$
    – kglr
    11 hours ago




    $begingroup$
    @lio, my pleasure.
    $endgroup$
    – kglr
    11 hours ago











    1












    $begingroup$

    You could create a wrapper that formats as desired:



    MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
    Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
    StandardForm
    ]


    Then:



    x = {0, 2, 3, 0, 4};
    y = {4, 5, 12, 10, 1};

    MapThread[HoldRational, {x, y}]


    enter image description here






    share|improve this answer









    $endgroup$


















      1












      $begingroup$

      You could create a wrapper that formats as desired:



      MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
      Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
      StandardForm
      ]


      Then:



      x = {0, 2, 3, 0, 4};
      y = {4, 5, 12, 10, 1};

      MapThread[HoldRational, {x, y}]


      enter image description here






      share|improve this answer









      $endgroup$
















        1












        1








        1





        $begingroup$

        You could create a wrapper that formats as desired:



        MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
        Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
        StandardForm
        ]


        Then:



        x = {0, 2, 3, 0, 4};
        y = {4, 5, 12, 10, 1};

        MapThread[HoldRational, {x, y}]


        enter image description here






        share|improve this answer









        $endgroup$



        You could create a wrapper that formats as desired:



        MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
        Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
        StandardForm
        ]


        Then:



        x = {0, 2, 3, 0, 4};
        y = {4, 5, 12, 10, 1};

        MapThread[HoldRational, {x, y}]


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 5 hours ago









        Carl WollCarl Woll

        68.1k389176




        68.1k389176






























            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%2f191743%2fprint-integer-number-fraction-as-string-of-numerator-and-denominator%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

            Hivernacle

            Fluorita

            Hulsita