Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11319 > unrolled thread
| Started by | "djmpark" <djmpark@comcast.net> |
|---|---|
| First post | 2012-08-12 06:14 +0000 |
| Last post | 2012-08-17 08:18 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | "djmpark" <djmpark@comcast.net> |
|---|---|
| Date | 2012-08-12 06:14 +0000 |
| Subject | Re: compact notation for NonCommutativeMultiply that supports cut and paste |
| Message-ID | <k07hjo$cu8$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | Tobias Hagge <tobiashagge@gmail.com> |
|---|---|
| Date | 2012-08-17 08:18 +0000 |
| Message-ID | <k0kup3$6e3$1@smc.vnet.net> |
| In reply to | #11319 |
David, thank you for your interesting solution. It does not allow copy/pasting of just part of a noncommutative product, which is a feature for some applications, but not quite what I need. After some experimentation I was able to find two ways to accomplish more precisely what I was looking for, which I'm posting below.
Contrary to what I wrote (sorry), what I really want is SMALL (rather than no) spaces between the symbols, just like Times. I ran into these problems:
1) Executing this:
<< Notation`
InfixNotation[ParsedBoxWrapper["foo"], NonCommutativeMultiply]
NonCommutativeMultiply[a, b, c]
and then copy/pasting the output gives "afoobfoo c".
2) Evaluating this:
<< Notation`
Unprotect[NonCommutativeMultiply];
InfixNotation[ParsedBoxWrapper["\[Null]"], NonCommutativeMultiply];
NonCommutativeMultiply /:
MakeBoxes[NonCommutativeMultiply[x__], StandardForm] :=
RowBox[Riffle[(MakeBoxes[#, StandardForm]) & /@ {x},
ConstantArray[
"\[InvisibleSpace]\[Null]\[InvisibleSpace]",
Length[{x}] - 1]]];
NonCommutativeMultiply[a,b,c]
and then copy/pasting gives input which evaluates correctly, however the spacing of output before copy/pasting still does not match the spacing after.
For whatever reason, the following code does not produce the problematic whitespace. It gives a StandardForm output for NonCommutativeMultiply which looks like times, but copy/pastes to a form which evaluates as NonCommutativeMultiply.
Unprotect[NonCommutativeMultiply];
InfixNotation[ParsedBoxWrapper["\[Null]"], NonCommutativeMultiply];
NonCommutativeMultiply /:
MakeBoxes[NonCommutativeMultiply[x__], StandardForm] :=
RowBox[Flatten[
Riffle[(MakeBoxes[#, StandardForm]) & /@ {x},
ConstantArray[{"\[VeryThinSpace]", "\[Null]",
"\[VeryThinSpace]"}, Length[{x}] - 1]]
, 1]
];
\[VeryThinSpace] can be replaced with \[InvisibleSpace] if no spacing between factors is desired. I tried replacing \[Null] with "|" (to get something like your notation), but unfortunately, replacing \[VeryThinSpace] with \[NegativeVeryThinSpace] causes the bad whitespace to reoccur, so this code won't give a notation like yours which is as compact.
A second solution is:
InfixNotation[ParsedBoxWrapper["\[InvisibleApplication]"], NonCommutativeMultiply]
It is simpler but has two slight disadvantages:
1) Invisible function application no longer works.
2) When copy/pasting part of a long product, there is no visible indication whether the end of the selection is a symbol or the noncommutative operator.
Best,
Tobias
On Sunday, August 12, 2012 1:14:16 AM UTC-5, djmpark wrote:
> 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
>
>
>
>
> From: tobiashagge
>
>
> 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];
>
>
>
>
>
> 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web