# Formatting standard function names in plot legends

Consider the following:

Quit[]


Now Plot[{Log[x], Exp[x]}, {x,1,2}, PlotLegends->"Expressions"] yields

So perhaps PlotLegends doesn't use the TraditionalForm output, since the formatting for Exp doesn't correspond. But now:

Unprotect[Log]
Protect[Log]



and now issuing the same plot command yields

I would like exp(x) to print as e^x, so:

Unprotect[Exp]


and I get SetDelayed: Tag Power in MakeBoxes[e^{x_}, TraditionalForm] is Protected. (Note: I've tried this both with the Mathematica ESC e e ESC and just the character e, with the same results.

So I guess I have two questions:

1. What format is used for PlotLegends?
2. Why is there a difference in behavior between Log and Exp in the above code?
• Would using PlotLegends -> {Format[Exp[x], TraditionalForm], Format[Log[x], TraditionalForm]} not solve your issue? – MarcoB Jan 17 '17 at 22:38
• Or perhaps Plot[{Log[x],Exp[x]},{x,1,2},PlotLegends->"Expressions"]/.HoldForm:> TraditionalForm? – chuy Jan 17 '17 at 23:03

For question 1, PlotLegends uses TraditionalForm, but it wraps the functions in HoldForm. For question 2, look at the FullForm of Exp[x]:

FullForm[Exp[x]]


Power[E,x]

The Exp[x] in the Format statement evaluates, which is why you get a SetDelayed::write message:

Unprotect[Exp]
Protect[Exp]


{Exp}

-SetDelayed::write: Tag Power in MakeBoxes[E^x_,TraditionalForm] is Protected.

\$Failed

{Exp}

So, you need to prevent evaluation by using HoldPattern:

Unprotect[Exp]
Protect[Exp]


{Exp}

{Exp}

Now, let's see if it worked:

Hold[Exp[x]]//TraditionalForm


Hold[E^x]

Note that the above is one of the reasons (evaluation leaks) I prefer using MakeBoxes rules instead, something along the lines of:

Unprotect[Exp]

• One question, though: why does my original construct work for Log and not for Exp? Is it because Log appears to be built-in (FullForm[Log[x]] is Log[x]) while Exp is just shorthand for an invocation of the Power function? – rogerl Jan 18 '17 at 15:20