OptionValue
✖
OptionValue
Details

- OptionValue[name] is equivalent to OptionValue[f,name], where f is the head of the left-hand side of the transformation rule in which OptionValue[name] appears.
- OptionValue[f,name] and OptionValue[name] will use values from the first OptionsPattern object that appears as an argument of f.
- In OptionValue[f,opts,name], only the explicit list opts and the defaults derived from f will be considered.
- In OptionValue[f,opts,name], f can be a symbol, a rule, or a list of symbols and rules specifying default values. Each symbol s in f is equivalent to Options[s]. If the same option name is specified multiple times, the first specification determines the default.
- OptionValue[f,opts,name,Hold] returns the option value with Hold wrapped around it.
- OptionValue[Automatic,Automatic,name,Hold] is equivalent to OptionValue[name], except that the option value is returned with Hold wrapped around it.
- OptionValue ignores contexts when comparing option names and treats the symbol s and the string SymbolName[s] interchangeably.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Define default option values for the function f:

https://wolfram.com/xid/0tz6qpmi-opm
Define f, allowing options to be given:

https://wolfram.com/xid/0tz6qpmi-st3
Use f with an explicit option setting:

https://wolfram.com/xid/0tz6qpmi-swj

Use f with options taken to have their default values:

https://wolfram.com/xid/0tz6qpmi-fch

Scope (4)Survey of the scope of standard use cases
Retrieve several option values at once:

https://wolfram.com/xid/0tz6qpmi-m7yd6q

Use an explicit list of options:

https://wolfram.com/xid/0tz6qpmi-v19okd

Define a transformation rule using multiple OptionsPattern constructs:

https://wolfram.com/xid/0tz6qpmi-3rhlxg
OptionValue[a] is treated as OptionValue[f,a] because it is the outer head:

https://wolfram.com/xid/0tz6qpmi-rej9b8

OptionValue tracks where a particular option was specified:

https://wolfram.com/xid/0tz6qpmi-s90kl8

Use Hold in the fourth argument to return the unevaluated forms of options using RuleDelayed:

https://wolfram.com/xid/0tz6qpmi-pjpqy5

Without the Hold, the current value of $Assumptions would be returned:

https://wolfram.com/xid/0tz6qpmi-2yijer

Applications (2)Sample problems that can be solved with this function
Define the default option values for a function f:

https://wolfram.com/xid/0tz6qpmi-za8zy2

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

https://wolfram.com/xid/0tz6qpmi-dpo0lo
The default option value of f is honored:

https://wolfram.com/xid/0tz6qpmi-8bxb5z

An explicit option setting takes precedence:

https://wolfram.com/xid/0tz6qpmi-ndsnip

Define two functions with options:

https://wolfram.com/xid/0tz6qpmi-qa14k9
Define a function h that uses both sets of options, giving preference to the defaults of g:

https://wolfram.com/xid/0tz6qpmi-djt7iw

https://wolfram.com/xid/0tz6qpmi-bv0yr5


https://wolfram.com/xid/0tz6qpmi-08ss7e

Properties & Relations (4)Properties of the function, and connections to other functions
Contexts are ignored when comparing option names:

https://wolfram.com/xid/0tz6qpmi-h8r34i

A string and a symbol are treated interchangeably:

https://wolfram.com/xid/0tz6qpmi-pg4d1e


https://wolfram.com/xid/0tz6qpmi-knd13i

OptionValue checks that all options requested appear in the defaults:

https://wolfram.com/xid/0tz6qpmi-0b6dsh


For simple cases, OptionValue[f,opts,name] is similar to name/.opts/.Options[f]:

https://wolfram.com/xid/0tz6qpmi-ttu11j


https://wolfram.com/xid/0tz6qpmi-i2d24o


https://wolfram.com/xid/0tz6qpmi-8jsit

However, OptionValue performs additional normalization to ensure rules are correctly applied:

https://wolfram.com/xid/0tz6qpmi-25gfth


https://wolfram.com/xid/0tz6qpmi-bk1qwl

Possible Issues (1)Common pitfalls and unexpected behavior
Define a transformation rule where OptionsPattern only appears inside a different function:

https://wolfram.com/xid/0tz6qpmi-6ytzx0
OptionValue[a] does not work because OptionsPattern is not an argument of f:

https://wolfram.com/xid/0tz6qpmi-e1qjzr

Wolfram Research (2007), OptionValue, Wolfram Language function, https://reference.wolfram.com/language/ref/OptionValue.html.
Text
Wolfram Research (2007), OptionValue, Wolfram Language function, https://reference.wolfram.com/language/ref/OptionValue.html.
Wolfram Research (2007), OptionValue, Wolfram Language function, https://reference.wolfram.com/language/ref/OptionValue.html.
CMS
Wolfram Language. 2007. "OptionValue." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/OptionValue.html.
Wolfram Language. 2007. "OptionValue." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/OptionValue.html.
APA
Wolfram Language. (2007). OptionValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OptionValue.html
Wolfram Language. (2007). OptionValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/OptionValue.html
BibTeX
@misc{reference.wolfram_2025_optionvalue, author="Wolfram Research", title="{OptionValue}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/OptionValue.html}", note=[Accessed: 29-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_optionvalue, organization={Wolfram Research}, title={OptionValue}, year={2007}, url={https://reference.wolfram.com/language/ref/OptionValue.html}, note=[Accessed: 29-March-2025
]}