Automatically evaluating related cells

I have the cells:

In[1]:= l = 2 + 2;

In[2]:= l >= 5

After evaluating them:

Out[2]:= False

Is there a way to evaluate all related cells, so if I change In[1] to l = 2 + 5, Out[2] would become True without evaluating the whole notebook?



2 Answers


Perhaps something along these lines could help?

$PrePrint= # /.
Except[Null] :> With[{line = $Line}, DynamicSetting@Dynamic@In[line]] /.
DownValues[In] &;

After running this, everything you evaluate is automatically wrapped in Dynamic so its value is updated automatically. I haven’t tested it much so there may be issues.

(Be careful with endless dynamic updating loops)

You can try Dynamic(by the way, l = 2 + 5 won’t make l >= 5 to be False…):

In[20]:= l = 1 + 3

Out[20]= 4

In[19]:= Dynamic[l >= 5]

Out[19]= False



I’ve fixed about comparison, and is their a way to do this for all cell, without wrapping in Dynamic explicitly?
– m0nhawk
May 5 ’13 at 8:39



@m0nhawk No other easy way. You either tell each related cell to listen to a dynamic value by wrapping their contents in Dynamic OR you re-evaluate these cells. You can play with cell options, but Mathematica will never figure out on its own which cells it should update and which cells it shouldn’t.
– István Zachar
May 5 ’13 at 8:49



@m0nhawk Just as what István Zachar has pointed out. (At least I failed to find one 囧. )
– xzczd
May 5 ’13 at 9:01