Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
DownValues[In][[2]] – Rolf Mertig Aug 13 '13 at 22:07
Awesome. Looks like I can use something like: DownValues[In][[1]] /. RuleDelayed[x_, y_] :> HoldComplete[y] – teedr Aug 13 '13 at 22:17
Interestingly, this does not work if there is a newline after the semicolon. – teedr Aug 13 '13 at 22:38
You could also use Information[In] or ToExpression[InString[1], StandardForm, Hold] – Alexey Popkov Aug 14 '13 at 2:12
up vote 5 down vote accepted

You could use InString for that:

ToExpression[InString[1], StandardForm, Hold]

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

share|improve this answer
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. – teedr Aug 14 '13 at 17:51
@teedr You could try to experiment with DownValues[InString] for that. – Alexey Popkov Aug 14 '13 at 21:41
Cells[CellLabel -> "In[1]:="] // First // NotebookRead // 
  First // MakeExpression


HoldComplete[xyPoints = {{1, 2}, {2, 5}, {3, 10}}; 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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