MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: compact notation for NonCommutativeMultiply that supports cut and paste

I think you are saying that you don't like the x**y**z space taking infix
operator of NonComutativeMultiple and want something more compact because of
long multiplication sequences. I think it is a bit confusing to have no
infix separator (Is every argument guaranteed to be a single character
symbol?). The following uses a Vertical line and negative spaces to make a
pretty compact form.

NonCommutativeMultiply /: 
 MakeBoxes[NonCommutativeMultiply[x__ /; Length[{x}] > 1], 
  form : (StandardForm | TraditionalForm)] :=
 Module[{displayFunc, interpretationFunc, work1, work2, work3, 
   n = Length[{x}], f},
  work1 = 
   Riffle[Table[Slot[i], {i, n}], 
    RowBox[{"\[NegativeThinSpace]", "\[NegativeMediumSpace]", "|", 
      "\[NegativeMediumSpace]", "\[NegativeThinSpace]"}]];
  work2 = RowBox@work1;
  displayFunc = (Evaluate@work2) &;
  work3 = Riffle[Table[Slot[i], {i, n}], ","];
  interpretationFunc = 
   f[(RowBox[{"NonCommutativeMultiply", "[", Sequence @@ work3, 
        "]"}])] /. f -> Function;
  TemplateBox[MakeBoxes[#, form] & /@ {x}, "NonCommutativeMultiply", 
   DisplayFunction -> displayFunc, 
   InterpretationFunction -> interpretationFunc]

NonCommutativeMultiply[a, b, T, dd, F]
% // FullForm
% // InputForm

TemplateBox is an undocumented, but rather nifty construction, that I got
from WRI support some time ago. It can be copied and pasted. You can edit
the variables but not other parts of the expression. Someone from WRI might
give a neater formulation of this. 

David Park
djmpark at 

From: tobiashagge at [mailto:tobiashagge at] 


I am doing some group theory computations that have output of the form

:= NonCommutativeMultiply[very-long-sequence-of-letters]

I want the StandardForm output to display as a string of symbols without
spaces, just like the output of Times. I want to be able to copy and paste
that output into an input line and have it be correctly interpreted.
Finally, I want "a b" to evaluate as Times[a,b].

I decided to define the null character as an operator, piecing together bits
of code from the internet.

InfixNotation[ParsedBoxWrapper["\[Null]"], NonCommutativeMultiply];
NonCommutativeMultiply /:
  MakeBoxes[NonCommutativeMultiply[x__], StandardForm] :=
  RowBox[Riffle[(MakeBoxes[#, StandardForm]) & /@ {x},
     Length[{x}] - 1]]];

I'm having two issues:
1) The special characters are not visible in the notebook, which makes the
code a bit hard to read.
2) Letters appear spaced apart in the output. If you copy and paste the
output, the spacing disappears (so pushing the letters together in the
output using negative space will make copy/paste awkward).

Using AlignmentMarker instead of Null fixes the spacing issue. However, for
reasons I do not understand, the InfixNotation command does not work in this

Any help or helpful advice is appreciated.


  • Prev by Date: Re: VectorPlot3D
  • Next by Date: Series Simplification - how to truncate the result ?
  • Previous by thread: compact notation for NonCommutativeMultiply that supports cut and paste
  • Next by thread: Re: compact notation for NonCommutativeMultiply that supports cut and paste