Using function definition in plot caption?

Suppose I have defined f[z_]=z^2-4. Then I want to create a parametric plot for the function f (which I am able to do), that has the caption “f(z) = z²-4”, i.e., I want to join the string "f(z) = " with the parsed output how the function f was defined before. How can I do that?

Hi Jakob,

Here is one way

ClearAll@f    
f[z_] := z^2 - 4;

Plot[f[x], {x, 0, 4},
 PlotLabel -> Row[{HoldForm@TraditionalForm@f[x], " = ", TraditionalForm@f[x]}]]

This can be encapsulated in a function to make it easier to use

ClearAll@functionLabel;
SetAttributes[functionLabel, HoldAll];
functionLabel[function_] := Row[{HoldForm@TraditionalForm@function, " = ", 
 TraditionalForm@function}]

z[x_, y_] := Sin[x]*Cos[y]
Plot3D[z[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotLabel -> functionLabel[z[x, y]]]

The MaTeX paclet can be used to generate typeset labels. e.g.

f[x_] := Evaluate@Integrate[Sin[t], {t, 0, x}]
Plot[f[x], {x, 0, Pi},
 PlotLabel -> MaTeX["f(\\text{x})\\text{ =}\\int_0^x \\sin (t) \\, dt", FontSize -> 16],
 PlotTheme -> "Scientific",
 PlotLabels -> "Expressions"]