Function with custom Options and modified Options for built-in Symbols

OptionsPattern:

Mathematica graphics

Therefore declare Options for both myGrid and Grid as valid:

Options[myGrid] = {Frame -> All, "Tooltip" -> False};

myGrid[content_, opts : OptionsPattern[{myGrid, Grid}]] := . . .

Then:

myGrid[mat, Background -> Blue]
Grid[mat, Background -> RGBColor[0, 0, 1], Frame -> All]

With no error message.


The problem in this particular case comes from the default setting of the Dividers option, which overrides the Frame option settings. This does not strike me as a right behavior, or at least these options are not as orthogonal as they should be. This appears to fix the problem:

Options[myGrid] = 
   Join[{Frame -> All, "Tooltip" -> False}, 
      DeleteCases[Options[Grid], Dividers -> _]];

On a general note, however, I would add all options you may ever want to pass to some functions inside your function, explicitly as valid options of your function. If you find this too bothersome, you can, for this particular function (myGrid), switch back to good old OptionQ pattern:

myGrid[content_, opts___?OptionQ] := ...

at the expense of the short "magical" version of OptionValue not working any more, so you will have to use OptionValue[myGrid,{opts},"Tooltip"]. I do this sometimes, in exactly this sort of situations.