Wolfram Research

Function Repository Resource:

PrettyForm

Source Notebook

Print human-readable form of complex expressions

Contributed by: Taliesin Beynon

ResourceFunction["PrettyForm"][expr]

attempts to present expr in a human-readable form.

Details and Options

ResourceFunction[“PrettyForm”] is useful for interpreting structured expressions.
ResourceFunction["PrintDefinitions"] uses ResourceFunction["PrettyForm"].
Symbol contexts are displayed in ResourceFunction[“PrettyForm”] as tooltips, and are color-coded similarly to ResourceFunction["PrintDefinitions"].

Examples

Basic Examples

Examine a ragged array:

In[1]:=
ResourceFunction["PrettyForm"][Table[x^i + j, {i, 3}, {j, i}]]
Out[1]=

Inspect Wolfram Language code:

In[2]:=
ResourceFunction["PrettyForm"][
 Unevaluated[
  Module[{f}, f[1] = f[2] = 1; f[i_] := f[i] = f[i - 1] + f[i - 2]; f[n]]]]
Out[2]=

Hide symbol contexts in tooltips:

In[3]:=
ResourceFunction["PrettyForm"][{foo`symbol, bar`symbol}]
Out[3]=

Interpret a Graphics object:

In[4]:=
ResourceFunction["PrettyForm"][
 Graphics[{Thick, Green, Rectangle[{0, -1}, {2, 1}], Red, Disk[], Blue, Circle[{2, 0}], Yellow, Polygon[{{2, 0}, {4, 1}, {4, -1}}], Purple, Arrowheads[Large], Arrow[{{4, 3/2}, {0, 3/2}, {0, 0}}], Black, Dashed, Line[{{-1, 0}, {4, 0}}]}]]
Out[4]=

Applications

Examine a Wolfram Language function definition:

In[5]:=
ClearAttributes[Information, ReadProtected]
In[6]:=
ResourceFunction["PrettyForm"][Information[Information]]
Out[6]=

Properties and Relations

InputForm prints explicit contexts of symbols:

In[7]:=
dataset = Dataset[{
   <|"a" -> 1, "b" -> "x", "c" -> {1}|>,
   <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>}]
Out[7]=
In[8]:=
InputForm[dataset]
Out[8]=

PrettyForm provides context information in tooltips:

In[9]:=
ResourceFunction["PrettyForm"][dataset]
Out[9]=

PrettyForm does not get stripped off when wrapped around the output:

In[10]:=
ResourceFunction["PrettyForm"][foo`bar]
Out[10]=
In[11]:=
%
Out[11]=
In[12]:=
InputForm[%]
Out[12]=

Compare with, for instance, with MatrixForm:

In[13]:=
MatrixForm[{{1, 2}, {3, 4}}]
Out[13]=
In[14]:=
%
Out[14]=
In[15]:=
InputForm[%%]
Out[15]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

See Also

License Information