I was trying to write my own plot function taking as unit size cm instead of points. I've tried
Options[MyPlot] = Options[Plot];
SetOptions[MyPlot, ImageSize -> {8.22, 5.03}];
MyPlot[fun_, int_, opts_: OptionsPattern[]] := {fun, int,
ImageSize -> OptionValue[MyPlot, opts, ImageSize]*72/2.54};
Plot @@ MyPlot[Sin[2 \[Pi] x], {x, 0, 1}, ImageSize -> 10]
and with
Options[MyGraphics] = Options[Graphics];
SetOptions[MyGraphics, ImageSize -> {8.22, 5.03}];
MyGraphics[prims_, opts_: OptionsPattern[]] := {prims,
ImageSize -> OptionValue[MyGraphics, opts, ImageSize]*72/2.54};
Graphics@@MyGraphics[Rectangle[]]
the error: OptionValue::rep: "OptionsPattern[] is not a valid replacement rule." came out.
Where am I wrong? It seems I am a bit confusing on the way to use OptionsPattern[] and using _ or __ in the function arguments before the opts.
Thanks!
x: _ : xpattern isn't unnamed: it's aBlankpattern with namexand default valuex. Try:f[x : _ : x] := x, thenf[]returnsxandf[1]returns1. The casex: a : _ : xis also misinterpreted (but more complicated). – Alexey Popkov May 01 '16 at 15:54x : a : _ : xmeans "the patternanamedxwith default value_ : x": tryClear[f, a, x]; f[x : a : _ : x] := x, thenf[]returns the default value_ : x,f[a]returnsaandf[1]returns unevaluated because1doesn't match the patterna. – Alexey Popkov May 01 '16 at 16:02