1
$\begingroup$

Using the Notation package, I have a custom notation defined for chemical reactions. A minimal example is below (I will explain the commented-out part in a moment):

Needs["Notation`"]
Notation[ParsedBoxWrapper[
         RowBox[{"a_", TagBox["\[LongRightArrow]", 
                       Identity, SyntaxForm -> "\[Equal]"
                       (*, Editable->False,Selectable->False*)
                             ], 
                 "b_"}]]
   \[DoubleLongLeftRightArrow]ParsedBoxWrapper[
         RowBox[{"LongRightArrow", "[", "a_", ",", "b_", "]"}]]]
Notation[ParsedBoxWrapper[
         RowBox[{"a_", OverscriptBox[TagBox["\[LongRightArrow]", Identity, 
                                            SyntaxForm -> "\[Equal]"
                                     (*,Editable->False,Selectable->False*)
                                           ], 
                                     "k_"], 
                 "b_"}]]
   \[DoubleLongLeftRightArrow]ParsedBoxWrapper[
         RowBox[{"LongRightArrow","[","a_",",","b_",",","k_","]"}]]]
AddInputAlias["rxn" -> ParsedBoxWrapper[
              TagBox["\[LongRightArrow]",Identity,SyntaxForm->"\[Equal]"
                     (*,Editable->False,Selectable->False*)
              ]]]

The first Notation entry defines a reaction with reactants and products. The second Notation entry defines a reaction with reactants and products, and a rate constant that is positioned over the arrow. The TagBox is needed in order to change the precedence of LongRightArrow so that the parser doesn't swap around reactants and products. You can enter an example reaction like this:

enter image description here

The problem is that on either side of the long right arrow there are two cursor positions, which I presume represent being inside the tagbox and outside the tagbox. Entering reactants or products within the tagbox, or going to the overscript box from within the tagbox breaks the Notation assignments, so I would like to eliminate those as possible cursor locations. See below:

enter image description here

I did something similar for a complex symbols package I have put together using the Editable->False, Selectible->False approach within a style definition, but here it doesn't seem to work (decomment the commented-out portions above to try). Further, if I replace the TagBox with a TemplateBox and apply the style I used previously, I still end up with two distinct regions the cursor can be outside the arrow.

Any suggestions? Thanks!

$\endgroup$
  • $\begingroup$ I find your animations make your code very difficult to read and understand. $\endgroup$ – m_goldberg May 17 at 0:22
  • $\begingroup$ I apologize. I will keep that in mind in the future. $\endgroup$ – Kevin Ausman May 17 at 0:44
2
$\begingroup$

I think you can just use a TemplateBox to fix this. Change:

TagBox["⟶",Identity,SyntaxForm->"\[Equal]"]

to:

TemplateBox[{}, "Reaction", DisplayFunction->("⟶"&), SyntaxForm->"\[Equal]"]

You can also use a TagBox. The problem you are encountering is that the options order gets canonicalized, and doesn't match the order you are expecting. Using:

TagBox["⟶", Identity, Editable->False, Selectable->False, SyntaxForm->"\[Equal]"]

solves that issue.

$\endgroup$
  • $\begingroup$ Your TemplateBox approach works beautifully! Quick clarifying question: Does the "Reaction" tag serve any real purpose here? On the canonicalized options order in TagBox issue... that is extremely subtle, and I doubt I would have hit upon it without you pointing it out. I was laboring under the misconception that the order of options was irrelevant. Is there a rationale behind this behavior? $\endgroup$ – Kevin Ausman May 17 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.