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.

DetailsDetails

  • OptionsPattern matches any sequence or nested list of rules, specified with or .
  • In OptionsPattern[{spec1, spec2, ...}] the can be either heads or explicit rules . Each head is treated as the list of rules obtained from Options[fi].
  • OptionsPattern[] uses the default options of the nearest enclosing function.
  • OptionsPattern[{}] includes no default options.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Define default option values for the function :

In[1]:=
Click for copyable input

Define , allowing options to be given:

In[2]:=
Click for copyable input

Use with an explicit option setting:

In[3]:=
Click for copyable input
Out[3]=

Use 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]=

Override one of the defaults from Plot:

In[3]:=
Click for copyable input
Out[3]=
New in 6
New to Mathematica? Find your learning path »
Have a question? Ask support »