Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Display an expression in a format intended to maximize readability
|
ResourceFunction["ReadableForm"][expr] displays a version of expr similar to InputForm[expr] that is formatted to maximize readability. |
| CachePersistence | Automatic | specifies how internal caching should be handled |
| CharacterEncoding | "Unicode" | which character encoding to use |
| "DynamicAlignment" | False | whether to use context-sensitive alignment across lines |
| "FormatHeads" | Automatic | a set of heads {h1,h2,…} such that hi[…] should be formatted in StandardForm |
| "IndentSize" | 4 | how many spaces to use for indenting |
| "InitialIndent" | 0 | how much additional indentation to apply to each line |
| PageWidth | 80 | the target character count for each line |
| PerformanceGoal | "Quality" | aspects of performance to try to optimize |
| "PrefixForm" | True | whether to use prefix form (f@x) when appropriate |
| "RealAccuracy" | Automatic | number of digits to the right of the decimal point to display for real numbers |
| "RelativeWidth" | False | whether to count indentation in page width |
| None | improves memory usage at the cost of speed |
| Full | improves speed at the cost of memory usage |
| Automatic | uses a balanced mix |
| Automatic | real numbers are displayed using normal InputForm behavior |
| n | a nonnegative integer specifying a maximum number of digits to display after decimal points |
View the code underlying a formatted expression:
| In[1]:= |
|
| Out[1]= |
|
Visually inspect properties of formatted objects:
| In[2]:= |
|
| Out[2]= |
|
Input-style syntax highlighting is used:
| In[3]:= |
|
| Out[3]= |
|
Use Unevaluated to prevent the expression from evaluating:
| In[4]:= |
|
| Out[4]= |
|
ToString will preserve the whitespace:
| In[5]:= |
|
| Out[5]= |
|
| In[6]:= |
|
| Out[6]= |
|
CopyToClipboard will also preserve much of the formatting:
| In[7]:= |
|
With CachePersistence→None, ReadableForm will not use any caching, which reduces overall memory usage but is the slowest method:
| In[8]:= |
|
| Out[8]= |
|
With the default behavior of CachePersistence→Automatic, ReadableForm will remember some values between evaluations to gain a modest performance boost:
| In[9]:= |
|
| Out[9]= |
|
Using CachePersistence→Full will give the fastest performance, but the extra memory used is not released for the remainder of the kernel session:
| In[10]:= |
|
| Out[10]= |
|
ReadableForm can adjust indentation of certain parts of code in order to obtain alignment across lines when using a monospace font. Here is a helper function to display monospaced results:
| In[11]:= |
|
| In[12]:= |
|
| Out[12]= |
|
By default, ReadableForm will only indent one step at a time:
| In[13]:= |
|
| Out[13]= |
|
Use the setting "DynamicAlignment"→True to perform additional alignment heuristics:
| In[14]:= |
|
| Out[14]= |
|
By default, some expressions are formatted in StandardForm in order to enhance readability:
| In[15]:= |
|
| Out[12]= |
|
Use "FormatHeads" to control which expressions are formatted in StandardForm:
| In[16]:= |
|
| Out[16]= |
|
Use Automatic to include the defaults:
| In[17]:= |
|
| Out[17]= |
|
Change the size of indentation in the output:
| In[18]:= |
|
| Out[18]= |
|
Specify an amount of additional indentation to apply to every line:
| In[19]:= |
|
| Out[19]= |
|
Set a desired page width to control line breaks:
| In[20]:= |
|
| Out[20]= |
|
By default, ReadableForm will traverse expressions as deep as possible to apply formatting:
| In[21]:= |
|
| Out[21]= |
|
With PerformanceGoal→"Speed", ReadableForm traverses only deep enough to format lines and uses InputForm to handle the rest:
| In[22]:= |
|
| Out[22]= |
|
By default, ReadableForm will use Prefix formatting (f@expr) for some expressions:
| In[23]:= |
|
| Out[23]= |
|
Disable Prefix formatting:
| In[24]:= |
|
| Out[24]= |
|
By default, ReadableForm displays real numbers with all available digits:
| In[25]:= |
|
| Out[25]= |
|
Specify a maximum number of digits to display:
| In[26]:= |
|
| Out[26]= |
|
By default, measuring "PageWidth" per line includes the leading whitespace:
| In[27]:= |
|
| Out[19]= |
|
Set "RelativeWidth" to True if you don't want to count the leading whitespace:
| In[28]:= |
|
| Out[28]= |
|
Copy expressions to the clipboard that will be formatted nicely when pasting into email, etc.:
| In[29]:= |
|
Create readable log files with lots of metadata:
| In[30]:= |
|
| In[31]:= |
|
| In[32]:= |
|
ReadableForm can be used to convert a FullDefinition into a formatted package notebook. Here's an example from a resource function:
| In[33]:= |
|
View the default formatting:
| In[34]:= |
|
| Out[34]= |
|
Create formatted cells using ReadableForm:
| In[35]:= |
|
Display in a package notebook:
| In[36]:= |
|
| Out[36]= |
|
For expressions that only require a single line to display, the output will be very similar to InputForm:
| In[37]:= |
|
| Out[37]= |
|
| In[38]:= |
|
| Out[38]= |
|
ReadableForm is just a formatting wrapper; it doesn't evaluate on its own:
| In[39]:= |
|
| Out[39]= |
|
The head is not visible to InputForm:
| In[40]:= |
|
| Out[40]= |
|
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License