({{, (RefLink[OptionsPattern, paclet:ref/OptionsPattern])[]
is a pattern object that represents a collection of options given as rules, where the values of the options can be accessed using (RefLink[OptionValue, paclet:ref/OptionValue]). }, {, (RefLink[OptionsPattern, paclet:ref/OptionsPattern])[f] 
takes default option values from (RefLink[Options, paclet:ref/Options])[f].}, {, (RefLink[OptionsPattern, paclet:ref/OptionsPattern])[{(Subscript[opt, 1])->(Subscript[val, 1]),(Subscript[opt, 2])->(Subscript[val, 2]),…}] 
uses an explicit list of default option values.}})

OpenersNotesSection(Spacer1)Details

(RefLink[OptionsPattern, paclet:ref/OptionsPattern]) matches any sequence or nested list of rules, specified with -> or :>.

In (RefLink[OptionsPattern, paclet:ref/OptionsPattern])[{(Subscript[spec, 1]),(Subscript[spec, 2]),…}] the (Subscript[spec, i]) can be either heads (Subscript[f, i]) or explicit rules (Subscript[opt, i])->(Subscript[val, i]). Each head is treated as the list of rules obtained from (RefLink[Options, paclet:ref/Options])[(Subscript[f, i])].

(RefLink[OptionsPattern, paclet:ref/OptionsPattern])[] uses the default options of the nearest enclosing function.

(RefLink[OptionsPattern, paclet:ref/OptionsPattern])[{}] includes no default options.

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Define default option values for the function f:

Options[f]={a->a0,b->b0};

Define f, allowing options to be given:

f[x_,OptionsPattern[]]:={x,OptionValue[a]}

Use f with an explicit option setting:

f[7,a->uuu]

Use f with options taken to have their default values:

f[7]

Define default option values for this assignment without explicitly setting up (RefLink[Options, paclet:ref/Options])[f]:

f[x_,OptionsPattern[{a->a0,b->b0}]]:={x,OptionValue[a]}

f[7]

Take default option values from (RefLink[Plot, paclet:ref/Plot]):

f[x_,OptionsPattern[Plot]]:={OptionValue[AspectRatio],OptionValue[ImageSize]}

Use the defaults from (RefLink[Plot, paclet:ref/Plot]):

f[7]

Override one of the defaults from (RefLink[Plot, paclet:ref/Plot]):

f[7,ImageSize->20]

OpenersExampleSection1(Spacer1)Scope  (4)

Use the options of (RefLink[ArcLength, paclet:ref/ArcLength]), but override the default value of (RefLink[Method, paclet:ref/Method]):

f[OptionsPattern[{Method->"NIntegrate",ArcLength}]]:={OptionValue[Assumptions],OptionValue["Method"]}

Explicit option settings are honored:

f[Assumptions->c>0,Method->"Integrate"]

f uses the same default as (RefLink[ArcLength, paclet:ref/ArcLength]) for (RefLink[Assumptions, paclet:ref/Assumptions]), but not (RefLink[Method, paclet:ref/Method]):

f[]

OptionValue[ArcLength,{Assumptions,Method}]

Take options from both (RefLink[Plot, paclet:ref/Plot]) and (RefLink[Plot3D, paclet:ref/Plot3D]):

f[OptionsPattern[{Plot,Plot3D}]]:={OptionValue[PlotRange],OptionValue[BoxRatios]}

Give an explicit setting:

f[PlotRange->All]

For common options, the default is inherited from (RefLink[Plot, paclet:ref/Plot]):

f[]

Options[Plot,PlotRange]

Options[Plot3D,PlotRange]

The function g inherits defaults for common options from (RefLink[Plot3D, paclet:ref/Plot3D]):

g[OptionsPattern[{Plot3D,Plot}]]:={OptionValue[PlotRange],OptionValue[BoxRatios]}

g[]

Use (RefLink[OptionsPattern, paclet:ref/OptionsPattern]) with no default options:

f[x_, OptionsPattern[{}]]:=OptionValue[a]

Explicit uses of the option are honored:

f[1,a->x,b->y]

The option name is returned if not explicitly present in the options:

f[7,{b->y}]

(RefLink[OptionsPattern, paclet:ref/OptionsPattern]) can be used in normal pattern-matching functions like (RefLink[ReplaceAll, paclet:ref/ReplaceAll]):

f[7,{a->x,b->y}]/.f[_,OptionsPattern[{}]]:>OptionValue[a]

OpenersExampleSection2(Spacer1)Applications  (2)

Define the default option values for a function f:

Options[f]={"Square"->False}

Implement f using a helper function fCore, but still inherit defaults from f:

f[args___] := fCore[f,args]
fCore[f,x_,OptionsPattern[f]] :=If[OptionValue["Square"],x^2,x,"BadOptionValue"]

The default option value of f is honored:

f[2]

An explicit option settings takes precedence:

f[2,"Square"->True]

Define two functions with options:

Options[f]={a->1,b->2};
Options[g]={b->3,c->4};

Define a function h that uses both sets of options, giving preference to the defaults of g:

h[OptionsPattern[{g,f}]] := OptionValue[{a,b,c}]

h[]

h[a->10,b->7]

OpenersExampleSection3(Spacer1)Properties & Relations  (3)

(RefLink[OptionsPattern, paclet:ref/OptionsPattern]) matches any sequence of rules or lists of rules:

MatchQ[f[a->1,b:>3], f[OptionsPattern[]]]

MatchQ[f[{a->1,b:>3}], f[OptionsPattern[]]]

MatchQ[f[{a->1,{b:>3,{c->7}}}], f[OptionsPattern[]]]

An empty sequence matches (RefLink[OptionsPattern, paclet:ref/OptionsPattern]):

MatchQ[f[], f[OptionsPattern[]]]

An empty list matches (RefLink[OptionsPattern, paclet:ref/OptionsPattern]):

MatchQ[f[{}], f[OptionsPattern[]]]

OpenersExampleSection4(Spacer1)Possible Issues  (2)

(RefLink[OptionsPattern, paclet:ref/OptionsPattern]) will match any set of options:

Options[f]={a->1};
f[opts:OptionsPattern[f]] := {opts,OptionValue[a]}

This may cause messages if invalid options are passed:

f[a->1,b->2]

(RefLink[FilterRules, paclet:ref/FilterRules]) can be used to only use options valid for f:

f[opts:OptionsPattern[f]] := {opts,OptionValue[f, FilterRules[Options[f],{opts}],a]}

f[a->1,b->2]

Any nesting of empty lists will match (RefLink[OptionsPattern, paclet:ref/OptionsPattern]):

MatchQ[f[{}], f[OptionsPattern[]]]

MatchQ[f[{{}}], f[OptionsPattern[]]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[OptionValue, paclet:ref/OptionValue])  ▪  (RefLink[BlankSequence, paclet:ref/BlankSequence])  ▪  (RefLink[Repeated, paclet:ref/Repeated])  ▪  (RefLink[FilterRules, paclet:ref/FilterRules])  ▪  (RefLink[KeyValuePattern, paclet:ref/KeyValuePattern])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Patterns and Transformation Rules, paclet:tutorial/PatternsAndTransformationRules])}, {▪(RefLinkPlain[Setting Up Functions with Optional Arguments, paclet:tutorial/SettingUpFunctionsWithOptionalArguments])}, {▪(RefLinkPlain[Manipulating Options, paclet:tutorial/ManipulatingOptions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Options Management, paclet:guide/OptionsManagement])}, {▪(RefLinkPlain[Package Development, paclet:guide/PackageDevelopment])}, {▪(RefLinkPlain[Patterns, paclet:guide/Patterns])}})}})