# Change the output for Timesfunction

When I have an input like:

1/2*k


The output is:

How to change the output of Timesfunction to see this result:

Another option is to put all rational number using Deferfunction automatically.

• TraditionalForm[Defer[1/2 ] k ]?
– kglr
Commented Jan 29, 2019 at 17:32
• I would to like to change the function Times. Commented Jan 29, 2019 at 17:36
• how about Infix[1/2 k, "\[InvisibleTimes]"]?
– kglr
Commented Jan 29, 2019 at 18:06
• The problem is, every time I want to write a Rational number I will have to put Infix..... I want a way to program just in one line for every Rational number that I write from now on. Commented Jan 29, 2019 at 18:11
• You want to look at the Notation package. You certainly do not want to change the workings of Times---it's very deep down and all sorts of things depend on it working correctly. Commented Jan 29, 2019 at 18:31

You can just override the formatting of Times:

MakeBoxes[Times[r_Rational, s_], StandardForm] := RowBox[{MakeBoxes[r], MakeBoxes[s]}]
MakeBoxes[Times[r_Rational, s__], StandardForm] := RowBox[{MakeBoxes[r], MakeBoxes[Times[s]]}]


Then:

k/2


• Should the first FormatValue be RowBox[{MakeBoxes[r], Parenthesize[s, StandardForm, Times]}]? Commented Jan 29, 2019 at 22:10
• @ChipHurst Yes, that would be a good idea, so that 1/2 (a+b) formats correctly. Commented Jan 30, 2019 at 0:42
• The problem is when I have a symbol in the denominator. For example, for 1/α*k the output will be k/α because for Mathematica 1/α is not a Rational number. How to change for the output be 1/α k. Commented Jan 30, 2019 at 22:45

You just want to change notation, not the way Times actually works.

You can try using a separator, as @kglr suggests in the comments.

<<Notation
Notation[ParsedBoxWrapper[
RowBox[{"a_", "\[InvisibleTimes]", "b_"}]]
\[DoubleLongLeftRightArrow] ParsedBoxWrapper[
RowBox[{"Times", "[", RowBox[{"a_", ",", "b_"}], "]"}]]]


After evaluating the above, when I type

k/2


I see

(1/2) k


But when I type k/3/d I see (1/3)((1/d)k). So maybe more finesse is needed...

• Update: you must <<Notation first. Commented Jan 29, 2019 at 18:55
• According to stackoverflow.com/questions/4635701/… you may want to set Notation`AutoLoadNotationPalette=False at the beginning, when you're done fiddling with notation. Commented Jan 29, 2019 at 20:25