Function Repository Resource:

SetDisplayStyle

Source Notebook

Change the output style for any kind of expression

Contributed by: Jon McLoone

ResourceFunction["SetDisplayStyle"][patt,opts]

causes future output that matches pattern patt to be styled with options opts.

ResourceFunction["SetDisplayStyle"][patt,xform,opts]

causes future xform output that matches pattern patt to be styled with options opts.

Details and Options

ResourceFunction["SetDisplayStyle"] supports all options accepted by Style.
ResourceFunction["SetDisplayStyle"] effectively wraps Style around any matching output.
In ResourceFunction["SetDisplayStyle"][patt,xform,opts], xform can be StandardForm or TraditionalForm.

Examples

Basic Examples (3) 

Make all negative numbers format in red:

In[1]:=
ResourceFunction["SetDisplayStyle"][x_ /; x < 0, FontColor -> Red]
In[2]:=
RandomReal[{-1, 1}, 20]
Out[2]=

Set a specific symbol display at a specific size and in italic:

In[3]:=
ResourceFunction["SetDisplayStyle"][y, FontSize -> 30, FontSlant -> Italic]
In[4]:=
x + y
Out[4]=

Cause lists of length 2 and length 3 to have different background colors:

In[5]:=
ResourceFunction["SetDisplayStyle"][{_, _}, Background -> LightBlue];
In[6]:=
ResourceFunction["SetDisplayStyle"][{_, _, _}, Background -> LightYellow];
In[7]:=
{{1, 2, 3}, {4, 5}, {6, 7, 8}, {y}, -10}
Out[7]=

Scope (2) 

You can unset styles by using SetDisplayStyle again with no style options:

In[8]:=
ResourceFunction["SetDisplayStyle"][y]
In[9]:=
x + y
Out[9]=

Only StandardForm output is affected by default:

In[10]:=
ResourceFunction["SetDisplayStyle"][x_ /; x < 0, FontColor -> Red]
In[11]:=
data = RandomReal[{-1, 1}, {4, 4}]
Out[11]=
In[12]:=
TraditionalForm[data]
Out[12]=

You can set display styles for TraditionalForm by using TraditionalForm as the second argument of the three-argument form:

In[13]:=
ResourceFunction["SetDisplayStyle"][x_ /; x < 0, TraditionalForm, FontColor -> Red]
In[14]:=
TraditionalForm[data]
Out[14]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 16 October 2019

Related Resources

License Information