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$
3
  • $\begingroup$ Why do you want to use ToExpression? $\endgroup$
    – Carl Woll
    Mar 8, 2018 at 15:44
  • $\begingroup$ This whole thing gets fed back into CellGroup[ExpressionCell[ ... ]]. Do you have a different approach? $\endgroup$ Mar 9, 2018 at 14:03
  • $\begingroup$ cross posted on community.wolfram.com $\endgroup$
    – Kuba
    Mar 15, 2018 at 7:17

1 Answer 1

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$
2
  • $\begingroup$ Kuba, thank you. I have summarized this at the parallel discussion at Wolfram, here. $\endgroup$ Mar 16, 2018 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$ Mar 17, 2018 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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