2

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?

teedr
  • 455
  • 4
  • 6

2 Answers2

5

You could use InString for that:

ToExpression[InString[1], StandardForm, Hold]

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

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
3
Cells[CellLabel -> "In[1]:="] // First // NotebookRead // 
  First // MakeExpression

gives

HoldComplete[xyPoints = {{1, 2}, {2, 5}, {3, 10}}; 
 ListLinePlot[xyPoints]]
Rolf Mertig
  • 17,172
  • 1
  • 45
  • 76