# ToExpression and RowBox — orderings

With:

ToExpression[RowBox[{"c", ToBoxes[Plot[Sin[x], {x, -2, 2}]], "a"}]]


I get the three elements of the array, but with "a" and then "c" at the beginning. I would like to retain the order as I have input it.

I found that:

ToExpression[RowBox[{"c", "b", "a"}]]


reverses the order, but:

ToExpression[RowBox[{"$$", "c", "b", "a", "$$"}]]


retains the input order (and removes spaces in between).

However, applying this to my original snippet:

ToExpression[
RowBox[{"$$", "c", ToBoxes[Plot[Sin[x], {x, -2, 2}]], "a", "$$"}]]


it comes back with:

RowBox[{"c", "\"Privatezztop\$3\"", "a"}]


(zztop??).

Please help me understand the restrictions here, as well as possible work-arounds.

Thank you.

• Why do you want to use ToExpression? – Carl Woll Mar 8 '18 at 15:44
• This whole thing gets fed back into CellGroup[ExpressionCell[ ... ]]. Do you have a different approach? – Aharon Naiman Mar 9 '18 at 14:03
• cross posted on community.wolfram.com – Kuba Mar 15 '18 at 7:17

## 1 Answer

You can prevent evaluation/reordering using methods in a linked community topic but since we have an additional feedback here:

This whole thing gets fed back into CellGroup[ExpressionCell[ ... ]]. Do you have a different approach?

I suggest to keep it low level:

Cell @ CellGroupData[{
Cell @ BoxData @ RowBox[{"c", ToBoxes[Plot[Sin[x], {x, -2, 2}]], "a"}]
}]


Now you can NotebookWrite/CellPrint or compose a Notebook with this Cell.

• Kuba, thank you. I have summarized this at the parallel discussion at Wolfram, here. – Aharon Naiman Mar 16 '18 at 13:54
• One last thing (which I will also include in the parallel discussion at Wolfram). Apparently one needs to keep things "low-level" with CellGroupData[], but also, for the groupings to work, it needs to be fed back into NotebookWrite[] and not CellPrint[]`. – Aharon Naiman Mar 17 '18 at 18:35