Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11319

Re: compact notation for NonCommutativeMultiply that supports cut and paste

From "djmpark" <djmpark@comcast.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: compact notation for NonCommutativeMultiply that supports cut and paste
Date 2012-08-12 06:14 +0000
Message-ID <k07hjo$cu8$1@smc.vnet.net> (permalink)
References <8525141.75636.1344674234471.JavaMail.root@m06>
Organization Time-Warner Telecom

Show all headers | View raw


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@comcast.net 
http://home.comcast.net/~djmpark/index.html 


From: tobiashagge@gmail.com [mailto:tobiashagge@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

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: compact notation for NonCommutativeMultiply that supports cut and paste "djmpark" <djmpark@comcast.net> - 2012-08-12 06:14 +0000
  Re: compact notation for NonCommutativeMultiply that supports cut and paste Tobias Hagge <tobiashagge@gmail.com> - 2012-08-17 08:18 +0000

csiph-web