# How to write a TraditionalForm for non-commutatively multiplied objects

I would like to write a TraditionalForm output for a string of non-commutatively multiplied objects.

I don't really like the default output of the built-in symbol NonCommutativeMultiply, because it inserts $*\!*$ between each pair of symbols.

NonCommutativeMultiply[a, c + d, c] // TraditionalForm


$a*\!*\,(c+d)*\!*\,c$

If I would like to format OperatorProduct[a,(c+d),c] // TraditionalForm like $a\,(c+d)\,c$, how would I go about doing that?

You can try using Format along with Inactive

First, need to Unprotect NonCommutativeMultiply:

Unprotect[NonCommutativeMultiply];


This will look like:

NonCommutativeMultiply[a, c + d, c] // TraditionalForm


$a*(c+d)*c$

which is not quite right yet. For the finishing touches we get some help from Mr. Wizard

MakeBoxes[p : Inactive[h_][args___], form_] :=
MakeBoxes[Interpretation[HoldForm@h[args], p], form]


Now the result is

NonCommutativeMultiply[a, c + d, c] // TraditionalForm


$a(b+d)c$

as desired. Beware of course that if you try to interpret this an input it will not be noncommutative.

• Very nice. I managed to consolidate your answer into a one-liner: Format[NonCommutativeMultiply[x__], TraditionalForm] := HoldForm@Times[x] (after unprotecting) Aug 11 '15 at 17:05
• Of course, I need to quit forgetting about the usefulness of HoldForm.
– chuy
Aug 11 '15 at 17:36

I would use a TemplateBox to do this (I also included a tooltip to be able to distinguish it from normal multiplication):

Unprotect[NonCommutativeMultiply];
"NonCommutativeMultiply",
DisplayFunction -> (RowBox[{SlotSequence[1]}]&),
Tooltip -> "**"
]
Protect[NonCommutativeMultiply];


Using a TemplateBox means the output is copy/pastable. For instance:

NonCommutativeMultiply[a, b + c, d] // TraditionalForm


Copying the above output and evaluating:

a ** (b + c) ** d

gives the usual StandardForm output for NonCommutativeMultiply.