How do I prevent my text from being italicized when I annotate it with additional glyphs?

For example if I add a "hat" to a variable, z as in $\widehat z$, but want z to not be italicized to match its use elsewhere:

Plot[x^2, {x,-5,5},
              "Q("<>ToString@StringForm["Overscript[``, ^]",z]<>")"},

Conversely, how do I force z to be italic when it lacks an annotation (ToString@Style[z,Italic] doesn't do the trick)?


Note: This answer has some more details for the first part of your question (i.e. how to prevent italic letters)

To get everything italic, simply specify everything as expression instead of as string:

Plot[x^2, {x, -5, 5}, AxesLabel -> {P[z], Q[OverHat[z]]}, PlotTheme -> "Classic"]

Mathematica graphics

To prevent italic letters, use SingleLetterItalics: (from the linked answer)

Plot[x^2, {x, -5, 5}, 
 AxesLabel -> Thread@Style[{P[z], Q[OverHat[z]]}, SingleLetterItalics -> False], 
 PlotTheme -> "Classic"

Mathematica graphics

| improve this answer | |
  • $\begingroup$ That doesn't generalize well beyond the simple example. The expression I need is more along the lines of P[b|X,Overscript[\[CapitalTheta], ^]\p]/P[Overscript[b, ^]| ...], which I have to build with a mess like ToString[p],"P("<>ToString[p]<>"|X,Overscript[\[CapitalTheta], ^]\\" <> ToString[p]<> ") / P( "<>ToString@StringForm["Overscript[``, ^]",p]<>"|...)", which would be made yet worse if I wanted to fixe the italicized $\widehat b$. $\endgroup$ – orome Sep 10 '17 at 21:26
  • $\begingroup$ I think I still don't fully understand your issue - for me, something like P[b | X, OverHat@p]/P[OverHat@b | \[Ellipsis]] // TraditionalForm looks like it should. And what do you want to achieve with your mix of StringForm and ToString? Does p have a value assigned? If so, what value? $\endgroup$ – Lukas Lang Sep 10 '17 at 22:04
  • $\begingroup$ Let me see if I can work up a more useful MWE (though the process may lead me back to Python; why are strings, and output in general, such a mess in MMA?). $\endgroup$ – orome Sep 10 '17 at 22:16
  • $\begingroup$ OK, I think (after messing with this for too long) I see and just want to conform. Basically, to get anything interesting done, the idiom for each idem in AxesLabel or FrameLabel needs to be of the form Style[Row@{...},options...]. If that's about right then I think I got it. $\endgroup$ – orome Sep 11 '17 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.