Function Repository Resource:

ExpandableForm

Source Notebook

Print a form where subexpressions can be collapsed (by right clicking) or expanded (by clicking)

Contributed by: Carl Woll

ResourceFunction["ExpandableForm"][expr]

prints a form where selected subexpressions of expr can be collapsed or expanded.

Details and Options

The output is converted from the "Output" cell style to the "Input" cell style when interactively modified.
The output is evaluatable, with collapsed forms returned to their expanded forms.
The option "HotKeys" can be used to define hot keys that will apply function to selected subexpressions when the hot key is used.
"HotKeys"{"event1"func1, "event2"func2,} specifies that funci should be applied to the subexpression when eventi occurs in connection with expr.
The possible event specifications are the same as for EventHandler.

Examples

Basic Examples (2) 

Evaluate an expression:

In[1]:=
ResourceFunction["ExpandableForm"][{Log[8]/Log[2], Log[9]/Log[3]}]
Out[2]=

Select subexpressions, use right click to collapse them and click to expand the collapsed forms:

Hover over the collapsed expressions to see summary information about the collapsed expression in a tooltip.

Scope (4) 

Evaluate an addition expression:

In[3]:=
ResourceFunction["ExpandableForm"][Defer[2 + x + 3]]
Out[4]=

Right click the expression to collapse it:

Left click the collapsed expression to re-expand it. This turns it into an input cell:

In[5]:=
2 + x + 3

The output is evaluatable:

In[6]:=
2 + x + 3
Out[6]=

Options (5) 

HotKeys (2) 

Add a hot key to apply FullSimplify to subexpressions:

In[7]:=
ResourceFunction["ExpandableForm"][Log[8]/Log[2] + Log[9]/Log[3], "HotKeys" -> {{"KeyDown", "f"} -> FullSimplify}]
Out[8]=

Select the second summand and apply FullSimplify by using the hot key "f". The result is an input cell:

In[9]:=
Log[8]/Log[2] + Log[9]/Log[3]

TooltipInformation (3) 

Change the default tooltip information to include ByteCount:

In[10]:=
ResourceFunction["ExpandableForm"][{a, Range[20]}, "TooltipInformation" -> {"Byte count" -> ByteCount}]
Out[10]=

Select the second element of the list and use right click to collapse the list of integers:

The tooltip of the collapsed expression shows the byte count of the collapsed expression:

Publisher

Carl Woll

Version History

  • 1.0.0 – 03 October 2019

License Information