Consider the expression


which displays as

enter image description here

This is a nice Graphics object, as I can prove by typing //FullForm after it, like this

enter image description here

and getting

   List[List[1.29777, 1.29777], List[0., 0.648886], 
   List[0.648886, 0.648886], List[0.324443, 0.], List[0.973329, 0.], 
      Inset[Framed[Style[Plus, "StandardForm", "Output", Rule[LineColor, 

It has framed elements in it, as I can prove by either looking at the text above, or by typing

enter image description here

But, the TreeForm expression itself does not have any framed elements in it. For instance

TreeForm[a+b^2+c^3+d] /. (x_Framed :> Print[x])

produces the original graphic

Somehow, the Notebook is not allowing me to capture and rewrite the expression form of the graphic -- the only way I know to access it is by cutting and pasting the graphical form of the object manually by mouse into the places where I need to manipulate it. This is no good. I need SecretEvaluator, such that

SecretEvaluator[TreeForm[a+b^2+c^3+d]] /. (x_Framed :> Print[x])

produces the same output as


3 Answers 3


The reason your original code fails is that the TreeFrom object is only formatted as Graphics object, meaning that it converted for display rather that as part of the normal evaluation sequence.

You can convert to and from box form to recover your Graphics object:

tf = TreeForm[a + b^2 + c^3 + d];

gr = tf // ToBoxes // ToExpression

gr /. (x_Framed :> Print[x]);

enter image description here

  • $\begingroup$ ToBoxes and also MakeBoxes are the top-level clues to understanding how expressions are rendered and converted. $\endgroup$
    – Reb.Cabin
    Commented Apr 11, 2014 at 12:56
  • $\begingroup$ @Reb.Cabin Thanks for the Accept. $\endgroup$
    – Mr.Wizard
    Commented Apr 11, 2014 at 17:23

From this answer

Network`GraphPlot`ExprTreePlot[a+b^2+c^3+d] /. (x_Framed :> Print[x])

Building on swish's answer, I would write

nodes = Cases[Network`GraphPlot`ExprTreePlot[a + b^2 + c^3 + d], _Framed, ∞];

This has the advantage of allowing you to work with the individual node objects; for example:



If want output that looks like your printed output just evaluate




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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