MathGroup Archive 2012

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

Search the Archive

Re: compact notation for NonCommutativeMultiply that supports cut and paste

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127657] Re: compact notation for NonCommutativeMultiply that supports cut and paste
  • From: "djmpark" <djmpark at comcast.net>
  • Date: Sun, 12 Aug 2012 01:49:37 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <8525141.75636.1344674234471.JavaMail.root@m06>

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.

Unprotect[NonCommutativeMultiply];
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 comcast.net 
http://home.comcast.net/~djmpark/index.html 


From: tobiashagge at gmail.com [mailto:tobiashagge at gmail.com] 


Hello,

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.

Unprotect[NonCommutativeMultiply];
InfixNotation[ParsedBoxWrapper["\[Null]"], NonCommutativeMultiply];
NonCommutativeMultiply /:
  MakeBoxes[NonCommutativeMultiply[x__], StandardForm] :=
  RowBox[Riffle[(MakeBoxes[#, StandardForm]) & /@ {x},
    ConstantArray[
     "\[InvisibleSpace]\[Null]\[InvisibleSpace]",
     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
case.

Any help or helpful advice is appreciated.

Best,
Tobias




  • 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