MathGroup Archive 2006

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

Search the Archive

parenthesis in reactions...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66707] parenthesis in reactions...
  • From: "Chris Chiasson" <chris at chiasson.name>
  • Date: Sat, 27 May 2006 03:52:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

(side note: Google New won't let me reply to my post with the same
subject from a little over a month ago, so I quoted it below)

Here is the solution:

Instructions:
Remove the Format statement for Molecule in the previous post. Add a
cell with the code below (use Ctrl+Shift+E). Now execute the reaction
statement from the previous post; there should be no parenthesis in
front of the first molecule this time.

Notes:
I derived this idea from section 1.7.3.2 of NotationSource.nb. I
noticed that when makeHeldRowBoxOfBoxes created a RowBox, no
parenthesis were added even when I had a multiplier on the Molecule.
The only problem was that my elements had commas between them. When I
changed the separator, the parenthesis returned. I already knew about
the SyntaxForm option of TagBox, but I had been trying to use
SyntaxForm->"*". Eventually, I put things together, using an
\[InvisibleSpace] for the separator, and SyntaxForm->",". This works
well. I have also tried to create an InfixNotation version, but to no
avail. If you know how to create an InfixForm version, I'd like to
hear it (using Block on NotationMakeExpression can be useful in this
regard).


Don't forget to load the Notation packge:
Utilities`Notation`AutoLoadNotationPalette = False;
<< Utilities`Notation`

Code:

Cell[BoxData[
    RowBox[{"Notation", "[",
      RowBox[{
        RowBox[{
          TagBox[
            TagBox[
              RowBox[{"TagBox", "[",
                RowBox[{
                  RowBox[{"RowBox", "[",
                    RowBox[{
                      RowBox[{
                        RowBox[{"Drop", "[",
                          RowBox[{"#", ",",
                            RowBox[{"-", "1"}]}], "]"}], "&"}], "@",
                      RowBox[{"Flatten", "@",
                        RowBox[{"Thread", "@",
                          RowBox[{"{",
                            RowBox[{
                              RowBox[{
                                RowBox[{"Function", "[",
                                  RowBox[{
                                    RowBox[{"{", "term", "}"}], ",",
                                    RowBox[{"MakeBoxes", "[",
                                      RowBox[{"term", ",",
"StandardForm"}], "]"}], ",",
                                    RowBox[{"{", "HoldAll", "}"}]}],
"]"}], "/@",
                                RowBox[{"Unevaluated", "@",
                                  RowBox[{"{", "blank__", "}"}]}]}],
",", "\"\<\[InvisibleSpace]\>\""}], "}"}]}]}]}], "]"}], ",",
"MoleculeTag", ",",
                  RowBox[{"SyntaxForm", "->", "\"\<,\>\""}]}], "]"}],
              NotationMadeBoxesTag,
              TagStyle->"NotationMadeBoxesWrapperStyle"],
            NotationBoxTag,
            TagStyle->"NotationTemplateStyle"], " ",
"\[DoubleLongLeftArrow]", " ",
          TagBox[
            RowBox[{"Molecule", "[", "blank__", "]"}],
            NotationBoxTag,
            TagStyle->"NotationTemplateStyle"]}], ",",
        RowBox[{"WorkingForm", "\[Rule]", "StandardForm"}]}], "]"}]], "Input"]


Old post quotation:
What is the proper way to eliminate the (output) parenthesis generated
around the first molecule as it is multiplied by the number two? I
could change the data structure if need be.

ElementSubscript[1|1.]:="";
ElementSubscript[x_]:=x;
ElementSuperscript[0|0.]:="";
ElementSuperscriptMod[1|1.]:="";
ElementSuperscriptMod[x_]:=x;
ElementSuperscript[x_?NumericQ]:=
    RowBox[{ToBoxes@ElementSuperscriptMod@Abs@x,"+"}]/;x>0;
ElementSuperscript[x_?NumericQ]:=
    RowBox[{ToBoxes@ElementSuperscriptMod@Abs@x,"-"}]/;x<0;
ElementSuperscript[x_]:=x;
ElementFormat[symblist:{{_Symbol,_Symbol}..}]:=
    Module[{x},
      ReleaseHold[
        Function[
            Hold[SetDelayed[Format[#1[x_,y_]],
                DisplayForm[
                  Subsuperscript[#2,ElementSubscript[x],
                    ElementSuperscript[y]]]]]]@@@symblist]];
Format[Molecule[blah:_Symbol[_,_]..]]:=DisplayForm[RowBox[ToBoxes/@{blah}]]
elementnotations={{Hydrogen,H},{Chlorine,Cl},{Zinc,Zn}};
ElementFormat[elementnotations];

rxns[1]={2 Molecule[Hydrogen[1,0],
          Chlorine[1,0]]\[Rule]2 Molecule[Hydrogen[1,1]]+2 Molecule[
            Chlorine[1,-1]],
    Zinc[1,0]+2 Hydrogen[1,1]+2 Chlorine[1,-1]\[Rule]
      Zinc[1,2]+2 Chlorine[1,-1]+Hydrogen[2,0],
    Zinc[1,2]+2 Chlorine[1,-1]+Hydrogen[2,0]\[Rule]
      Molecule[Zinc[1,0],Chlorine[2,0]]+Hydrogen[2,0]}

-- 
http://chris.chiasson.name/


  • Prev by Date: Re: Interval[{a,b}]-Interval[{a,b}] = 0?
  • Next by Date: Re: How to make results from Integrate and NIntegrate agree
  • Previous by thread: RE: Different text style for labels and ticks
  • Next by thread: ridiculous avi export