This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

OptionsPattern

OptionsPattern[]
is a pattern object that represents a collection of options given as rules, where the values of the options can be accessed using OptionValue.
OptionsPattern[f]
takes default option values from Options[f].
OptionsPattern[{opt1->val1, opt2->val2, ...}]
uses an explicit list of default option values.
  • OptionsPattern matches any sequence or nested list of rules, specified with -> or :>.
  • In OptionsPattern[{spec1, spec2, ...}] the speci can be either heads fi or explicit rules opti->vali. Each head is treated as the list of rules obtained from Options[fi].
  • OptionsPattern[] uses the default options of the nearest enclosing function.
Define default option values for the function f:
In[1]:=
Click for copyable input
Define f, allowing options to be given:
In[2]:=
Click for copyable input
Use f with an explicit option setting:
In[3]:=
Click for copyable input
Out[3]=
Use f with options taken to have their default values:
In[4]:=
Click for copyable input
Out[4]=
 
Define default option values for this assignment without explicitly setting up Options[f]:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
 
Take default option values from Plot:
In[1]:=
Click for copyable input
Use the defaults from Plot:
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
New in 6