# Print integer number fraction as string of numerator and denominator

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:

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

• One quick way is to replace 0 with "0". – b.gates.you.know.what Feb 18 '19 at 10:30
• What is allowed to be simplified? E.g. you don't complain about 3/12. – Kuba Feb 18 '19 at 10:34
• Closely related: mathematica.stackexchange.com/q/71938/5478 – Kuba Feb 18 '19 at 10:35
• @Kuba: I would like to see the fraction values and not the results -> {0/4, 2/5, 3/12, 0/1, 4/1} – lio Feb 18 '19 at 10:36

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


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] & /@


to get

• 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. – lio Feb 18 '19 at 10:55
• @lio, please see the update. – kglr Feb 18 '19 at 11:14
• Thank you so much ... – lio Feb 18 '19 at 11:27
• @lio, my pleasure. – kglr Feb 18 '19 at 11:27

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