2
$\begingroup$

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", "\"Private`zztop$3\"", "a"}]

(zztop??).

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

Thank you.

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

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.

$\endgroup$
  • $\begingroup$ Kuba, thank you. I have summarized this at the parallel discussion at Wolfram, here. $\endgroup$ – Aharon Naiman Mar 16 '18 at 13:54
  • $\begingroup$ 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[]. $\endgroup$ – Aharon Naiman Mar 17 '18 at 18:35

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.