Is it possible to retrieve a previous un-evaluated, un-normalized input?
Edit: See here for a better answer.
Just a slight modification of Mechanical snail's answer here, (I need a more creative username...) to make the output match the input exactly.
In[1]:= {{2}, {3}} // MatrixForm
In[2]:= ToExpression[InString[1], StandardForm, Defer] // DisplayForm
Which you can copy/paste, or just append //CopyToClipboard
to the command above and you can just paste it and use it. This will work with other automatically parsed expressions like 2+3
as well.
I don't think it is possible by reading the In
, since the information is stored in a list of HoldPattern
expression, and your input is not preserved. But if you did not delete the input cell, it is possible to obtain your input by doing this:
CellPrint@
Cell[Cases[NotebookRead@Cells[],
Cell[x_, _, _, CellLabel -> "In[42]:="] -> x][[1]], "Input"]
You can get exactly your input in a new cell.
Another idea is to CellPrint
the InString
output:
reprintInput[n_] := CellPrint @ Cell[
BoxData[ToExpression@InString[n]],
"Input"
]
For your example:
$Line=41;
{{2}, {3}} //MatrixForm
Then, reprintInput
produces an exact copy of the original input cell:
reprintInput[42]
{{2}, {3}} // MatrixForm
If you just want to store an unevaluated version of the input somewhere, you could use something like:
input = ToExpression[ToExpression@InString[42], StandardForm, Hold];
input //InputForm
Hold[MatrixForm[{{2}, {3}}]]
This is similar to @JasonB.'s answer, but there is no need to use copy/paste.