Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When using Mathematica how can I get a list of the allowed values of an option? As an example I can use the Options command as follows -

Options[Manipulate]

which gives me a list of available options

(* {Alignment->Automatic,AppearanceElements->Automatic,AutoAction->\
False,AutorunSequencing->Automatic,BaselinePosition->Automatic,\
BaseStyle->{},Bookmarks->{},ContentSize->Automatic,ContinuousAction->\
Automatic,ControlAlignment->Automatic,ControllerLinking->Automatic,\
ControllerMethod->Automatic,ControllerPath->Automatic,\
ControlPlacement->Automatic,ControlType->Automatic,DefaultBaseStyle->\
"Manipulate",DefaultLabelStyle->"ManipulateLabel",Deinitialization:>\
None,Deployed->False,Evaluator->Automatic,Frame->False,FrameLabel->\
None,FrameMargins->Automatic,ImageMargins->0,Initialization:>None,\
InterpolationOrder->Automatic,LabelStyle->{},LocalizeVariables->True,\
Method->{},Paneled->True,PreserveImageOptions->True,RotateLabel->\
False,SaveDefinitions->False,ShrinkingDelay->0,\
SynchronousInitialization->True,SynchronousUpdating->Automatic,\
TouchscreenAutoZoom->False,TouchscreenControlPlacement->Automatic,\
TrackedSymbols->Full,UnsavedVariables:>None,UntrackedVariables:>None} \
*)

I can use Options for a specific parameter, i.e.,

Options[Manipulate,ControlType]
(* {ControlType->Automatic} *)

But this doesn't tell me what the possible allowed values are for this option. Checkbox, Setter etc. Is there a command I can use to find the allowed values of an option?

share|improve this question
    
I think this was already asked here stackoverflow.com/questions/8718912/… –  belisarius Feb 13 '13 at 12:33

2 Answers 2

What follows is merely @halirutan's answer expressed in Wolfram Language:

Fetch symbol names and options:

symbolNamesWithOption@opt_ :=
Quiet @
Cases[
  {#1, Options/@Unevaluated/@#2}& @@@
  ({#, ToExpression[#, InputForm, HoldComplete]}&/@Names@"*") // ReleaseHold
, {symbolName_, {___, (opt -> _) | (opt :> _), ___}} :> symbolName]

Assemble names of files to search in:

notebooksToSearchInForInfoOnOption@opt_ :=
FileNameJoin @
{ $InstallationDirectory
, "Documentation", "English"
, "System", "ReferencePages", "Symbols"
, # <> ".nb"}& /@
Prepend[symbolNamesWithOption@opt, ToString@opt]

(could probably be done smarter with a proper use of `Documentation``)

With a basic formatting…

justSomeGrid@optString_String :=
Grid[
  Prepend[#, Style[#, Bold]& /@
  {"Reference notebook", "Values for "<> optString}]
, Alignment -> Left]&

…show the results:

tableOfExamplesForOption@opt_ :=
With[{optString = ToString@opt}
, { Button[FileBaseName@#1, SystemOpen@#1
    , Appearance -> "Palette", ImageSize -> Automatic]
  , Row[#, ","]& @
    Cases[#2
    , RowBox[{optString, "\[Rule]", val_}] |
      RowBox[{optString, " ", "\[Rule]", " ", val_}] :>
      DisplayForm@val
    , \[Infinity]]}& @@@
  DeleteCases[
    {#, Quiet@Import[#, "NB"]}& /@
    notebooksToSearchInForInfoOnOption@opt
  , {_, $Failed}] // justSomeGrid@optString ]

An example:

tableOfExamplesForOption@Extension

Notes:

  • please check symbolNamesWithOption@Method with Quiet omitted from its definition before trying the whole thing. There could be side-effects, and they may be version-dependent. From my experience, it's safe to run on 8.0 but I had to add an use at ou own risk warning
  • pattern for search could be improved
  • some searches are very slow in this implementation (try tableOfExamplesForOption@Method — I personally haven't yet had enough patience to wait for its result)
  • reference notebooks called with buttons will stay at (and thus, may mess with) your recent files history
  • using special contexts in Names one could search in definitions for examples values not covered in documentation
  • symbolNamesWithOption@_String comes as a nice bonus

Still, I hope it adds something to the description in natural language.

Ideas on improvements are very welcome.

share|improve this answer

Unfortunately, there is no command which tells you that. There are several reasons for that. First, the possible option values are context dependent. This means, e.g. the option Method can be set to different values depending on whether you use it in NDSolve, FindRoot, etc..

Second, as you see with "Elements" or "ImageList" options of Export, options are not always symbols, but usage messages cannot be applied to strings and documentation to string options rarely exists as separate page.

Therefore, the only way you find out about possible option values is the documentation. Note, that you often have two places to look

  1. You want to know what the special option ControlType of Manipulate does, then you first check out the help page of Manipulate
  2. For general information about the option, if it is a symbol, you check out the help page of the symbol itself.
share|improve this answer
    
Thanks, found the info i needed in the documentation but just wasn't sure if there was a command i could use to get the info i needed, would be good if such a command existed but i can see how this is context dependent. Thanks for answer. –  David McHarg Feb 13 '13 at 12:30
1  
and it's not always in the docs, either... –  acl Feb 13 '13 at 23:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.