Short version of question: Suppose I have an expression:
expression = a+3b;
When I divide by 2, I get:
expression/2
It is important for my application, however, to have this result displayed as:
If it helps at all, in context the quantities a and b are being displayed using a custom Notation from the Notation package and using a custom style that has been added to the stylesheet which already contains a custom DisplayFunction, so a solution that involves modifying either of those would be perfectly fine.
I recognize that this question is similar to this one. It is distinct, however, in that my situation is needing formatting done to the result of a calculation.
Application: My symbols are chemical formulas and the coefficients are stoichiometric coefficients, and standard notation in chemistry says that the coefficients are separately in front of the formulas.
Full Problem in Context: There are a number of pieces that have come together to create the full problem, but I think my minimal example above captures the essence. For context, however, here is what I am really working with.
First, I define string-based labels for my chemical species using my custom notations and styles through a function AssignSpecies, and then create a palette that allows me to enter those symbols easily.
Then I enter a couple of chemical reactions using those symbols and a custom-modified operator based on LongRightArrow (same precedence as ==).
I have set up some algebra rules for LongRightArrow to allow reactions to be added, subtracted, and multiplied and divided by a constant. So for example:
I have a function that will remove species on both sides of the reaction:
Very often, though, we want to have the reaction expressed such that one particular species (in this example, the main product) has a coefficient of 1. And this will lead to fractional coefficients in many cases. For example:
The H2(g) product is the problem here. For the notation to be as chemistry-standard as possible, I need that species to have a 3/2 coefficient in front of the species.
Edited to Add: Answering @CarlWoll's question about the FullForm of this result:
LongRightArrow[Plus[complexsymbol13, complexsymbol14,
Times[11, complexsymbol15], Times[2, complexsymbol18]],
Plus[Times[Rational[3, 2], complexsymbol17], complexsymbol19]]
Second Edit: Some further information:
AssignSpecies calls AssignLabels, which looks like this:
AssignLabels[list_]:=Block[{symbollist={},tmpsymbol},
Do[AppendTo[symbollist,tmpsymbol=constructnextsymbol];
AssociateTo[runningsymbollist,tmpsymbol->list[[i]]];
Notation[DoubleLongLeftRightArrow[
ParsedBoxWrapper@TemplateBox[{"\""<>list[[i]]<>"\""},"complexSymbols",
Editable->False,Selectable->False],
ParsedBoxWrapper@SymbolName[tmpsymbol]]],
{i,Length[list]}];
symbollist]
constructnextsymbol creates a symbol with the next index value. Other than the nature of the "complexSymbols" tag, everything else should be self-explanatory above. The complexSymbols style is:
Cell[StyleData["complexSymbols"],StyleMenuListing->None,
TagBoxOptions->{SyntaxForm->"symbol"},ShowStringCharacters->False,
ShowAutoStyles->False,ZeroWidthTimes->True,FontWeight->Plain,
FontFamily->"Times", TemplateBoxOptions->
{DisplayFunction->(RowBox[{#}]&),SyntaxForm->"symbol"}]
LongRightArrow
? (E.g. throughMakeBoxes
orFormat
.) $\endgroup$