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 (4) 

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 (1) 

Examine a Wolfram Language function definition:

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

Properties and Relations (3) 

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 is not a member of $OutputForms:

In[10]:=
$OutputForms
Out[10]=
In[11]:=
MemberQ[$OutputForms, ResourceFunction["PrettyForm"]]
Out[11]=

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

In[12]:=
ResourceFunction["PrettyForm"][foo`bar]
Out[12]=
In[13]:=
%
Out[13]=
In[14]:=
InputForm[%]
Out[14]=

Compare, for instance, with MatrixForm:

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

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 07 February 2019

Related Resources

License Information