# ToExpression interpreting typeset strings

Restatement of question, including code.

numList = {"3 ", "(2)^2 ", "foo", "bar"};
Manipulate[nums = Extract[numList, {{1}, {i}}];
Grid[{{"Perform the following calculation."}, {"input=" <>
StringJoin[nums]}, {"ans=" <>
ToString[ToExpression[StringJoin[nums]]]}}], {i, Range[2, 4]}]


Paste code into Mathematica. Replace foo with 2, control-6 (to get a superscript), 2. Replace bar with open paren, 2, close paren, control-6, 2. Execute, and then click on the ButtonBar. When i is 2 or 3, it works fine. If you click on i=4, you get a syntax error.

These should all be legal ways of doing 3 times 2^2.

• "carrot" = caret? – AccidentalFourierTransform Oct 2 '19 at 23:58
• What exactly fails? – Kuba Oct 3 '19 at 6:06
• Is there are particular reason why you want to input your expressions as strings? – Lukas Lang Oct 4 '19 at 8:01
• If you look at FullForm[numList] you'll in the last string that "(2)" is not the base of the superscript. This string does what you wanted: "\!$$\*SuperscriptBox[\((2)$$, $$2$$]\)" -- not sure how enter it tho' – Michael E2 Oct 5 '19 at 0:03
• Hm. I finally emailed Wolfram support, and they say this is a bug, and they'll work on it. – rhomboidRhipper Oct 23 '19 at 16:14

ToExpression@StringReplace[
StringTrim@ToString@"(1\!$$\*SuperscriptBox[\()$$, $$2$$]\)",