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


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


2 Answers 2


You can try using Format along with Inactive

First, need to Unprotect NonCommutativeMultiply:

Format[NonCommutativeMultiply[x__], TraditionalForm] := Inactive[Times][x]

This will look like:

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


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


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

  • 1
    $\begingroup$ Very nice. I managed to consolidate your answer into a one-liner: Format[NonCommutativeMultiply[x__], TraditionalForm] := HoldForm@Times[x] (after unprotecting) $\endgroup$
    – QuantumDot
    Aug 11, 2015 at 17:05
  • $\begingroup$ Of course, I need to quit forgetting about the usefulness of HoldForm. $\endgroup$
    – chuy
    Aug 11, 2015 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):

MakeBoxes[NonCommutativeMultiply[a__], TraditionalForm] ^:= TemplateBox[
    Thread @ Unevaluated @ Parenthesize[{a},TraditionalForm,Times,None],
    DisplayFunction -> (RowBox[{SlotSequence[1]}]&),
    Tooltip -> "**"

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

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


Copying the above output and evaluating:

enter image description here

a ** (b + c) ** d

gives the usual StandardForm output for NonCommutativeMultiply.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.