# Get the unevaluated expression from a numbered cell

If a cell exists as below:

In[1] := (xyPoints = {{1,2},{2,5},{3,10}}; ListLinePlot[xyPoints])


Is it possible to get at the expression rather than the plot shown in Out[1]. In other words, can I somehow get the held CompoundExpression in In[1] rather than the evaluated plot?

• DownValues[In][[2]] Commented Aug 13, 2013 at 22:07
• Awesome. Looks like I can use something like: DownValues[In][[1]] /. RuleDelayed[x_, y_] :> HoldComplete[y] Commented Aug 13, 2013 at 22:17
• Interestingly, this does not work if there is a newline after the semicolon. Commented Aug 13, 2013 at 22:38
• You could also use Information[In] or ToExpression[InString[1], StandardForm, Hold] Commented Aug 14, 2013 at 2:12
• Commented Aug 8, 2019 at 22:49

## 2 Answers

You could use InString for that:

ToExpression[InString[1], StandardForm, Hold]


Hold[xyPoints = {{1, 2}, {2, 5}, {3, 10}}; ListLinePlot[xyPoints]]

• Great. Do you know if there a way to get all the lines in a cell? If a compound expression is spread over multiple lines, each line seems to correspond to a different In[x] number. Commented Aug 14, 2013 at 17:51
• @teedr You could try to experiment with DownValues[InString] for that. Commented Aug 14, 2013 at 21:41
• In addition to the problem with multiple lines, this answer will not retain all the 2D input formatting that your original cell might have had. That means you cannot use this answer to recover exactly what you had in an input cell that you, say, accidentally deleted. To recover everything, use Carl Woll's answer to a related question. Commented Aug 8, 2019 at 22:47
Cells[CellLabel -> "In[1]:="] // First // NotebookRead //
First // MakeExpression


gives

HoldComplete[xyPoints = {{1, 2}, {2, 5}, {3, 10}};
ListLinePlot[xyPoints]]