0

I entered the following code into the Input cell. And the code expressed as RowBox was obtained using the Show Expression menu.

enter image description here

I want to get a Plain Text in the form of InputForm again from this code.

expr = Cell[BoxData[RowBox[{"Plot", "[", 
RowBox[{RowBox[{RowBox[{"Sin", "[", SuperscriptBox["x", "2"], "]"}], "+", 
SqrtBox[FractionBox["x", "2"]]}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "3"}], 
"}"}]}], "]"}]], "Input"]

How do I write code to get Plain Text in InputForm format? The text I want to get is as follows.

In[1]:= text = ... Code using 'expr' ...
Out[1]= Plot[Sin[x^2] + Sqrt[x/2], {x, 0, 3}]

I will continue my next work using the results obtained like this (=text).

user64494
  • 26,149
  • 4
  • 27
  • 56
Milk
  • 1,688
  • 10
  • 9
  • 1
    Does this fit your needs 1411? So First[FrontEndExecute[FrontEnd\ExportPacket[First@NotebookRead[PreviousCell[]], "PlainText"]]]` – Kuba Nov 13 '23 at 07:36
  • In fact, the problem I am finally trying to solve is as follows.

    https://mathematica.stackexchange.com/questions/292526/

    – Milk Nov 13 '23 at 07:43
  • Oh, thank you. I see a clue to the solution! I think I can solve the rest!! – Milk Nov 13 '23 at 07:57
  • Eliminating the Cell/BoxData wrappers, you can use ToExpression, e.g., ToExpression[expr[[1,1]], StandardForm, Defer] – Carl Woll Nov 13 '23 at 22:14

0 Answers0