Suppose I need to write a function to plot the real and imaginary part of some function (just an example). I want to define a function foo
so that foo[f[t],{t,0,10},PlotRange->All,(some other plot options)]
essentially calls
Plot[{Re[f[t]],Im[f[t]]},{t,0,10},PlotRange->All,(some other plot options)]
How to achieve that with, say, pattern matching?
ClearAll[foo]; SetAttributes[foo, HoldFirst]; foo[f_[t_], {t_, tmin_, tmax_}, opts : OptionsPattern[]] := Plot[{Re[f[t]], Im[f[t]]}, {t, tmin, tmax}, PlotRange -> All, opts]
? $\endgroup$foo2 = Plot[{Re[#], Im[#]}, #2, PlotRange -> All, ##3] &;
? $\endgroup$foo[Sin[t] + I*Cos[t], {t, 0, 10}, PlotRange -> All]
does not work on my machine (output is exactly "foo[Sin[t] + I*Cos[t], {t, 0, 10}, PlotRange -> All]"). $\endgroup${Re[f[t]], Im[f[t]]}
withEvaluate@{Re[f[t]], Im[f[t]]}
. These comments should be posted as an answer ;) $\endgroup$