# Superscripts and subscripts in graphics causes italics

This is a minor problem but when putting units on graphics I sometimes get italics and sometimes not. I get italics when there are superscripts. Thus

Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
FrameLabel -> {" m \!$$\*SuperscriptBox[\(m$$, $$2$$]\)\*
StyleBox[$$\!\(\* StyleBox[\" \",\nFontSlant->\"Italic\"]$$\)]\!$$\* StyleBox[SuperscriptBox[\"m\", \"3\"],\nFontSlant->\"Italic\"]$$",
"m \!$$\*SuperscriptBox[\(m$$, $$2$$]\)"},
BaseStyle -> {FontFamily -> Times, FontSize -> 24}]


The m without the superscript is upright. The m^2 is italic. In the SI system units should not be italic. In this example things are muddled

    Graphics[{
Style[Text[
"y = a +\!$$\*SubscriptBox[\(a$$, $$0$$]\) + \
\!$$\*SubscriptBox[\(a$$, $$1$$]\) x + \!$$\*SubscriptBox[\(a$$, \
$$2$$]\) \!$$\*SuperscriptBox[\(x$$, $$2$$]\)", {0, 0}],
FontSize -> 24, FontFamily -> Times]}]


The font without subscripts or superscripts is upright while the font with superscripts or subscripts is italic. Even worse there seems to have been a change in font between "a" and "a subscript".

Sometimes one wants italics everywhere, sometimes nowhere. How can this be managed? Version 11.3

Edit

Following helpful suggestions from Carl Woll I am now trying out using Standard form and no strings. I don't understand this as FrameLabel must contain a string for description as well as units. This does not work as seen in this example

Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
FrameLabel -> {Stress / ( N/ m^2 ) , Acceleration  / (m/s^2)},
BaseStyle -> {FontFamily -> Times, FontSize -> 12},
FormatType -> StandardForm]


I don't want everything multiplied out and I want Times font. Am I missing something here?

A better solution is

Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
FrameLabel -> {"Stress / ( N/ \!$$\*SuperscriptBox[\(m$$, $$2$$]\) \
)" , "Acceleration  / (m/\!$$\*SuperscriptBox[\(s$$, $$2$$]\))"},
BaseStyle -> {FontFamily -> Times, FontSize -> 12}]


This is the correct way to put units on plots according to the SI system except there should be no italics. The mess in StackExchange with all the backslashes is not a mess in a notebook; I guess this is a problem with the uploader.

One of the comments suggested using FontSlant -> Plain but this does not work :

   Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
FrameLabel ->
Style[{"Stress / ( N/ \!$$\*SuperscriptBox[\(m$$, $$2$$]\) )" ,
"Acceleration  / (m/\!$$\*SuperscriptBox[\(s$$, $$2$$]\))"},
FontSlant -> Plain],
BaseStyle -> {FontFamily -> Times, FontSize -> 12}]


However this does not work out either because it prevents labeling of both axes.

So I am still at a loss.

• try explicitly setting FontSlant – george2079 May 8 '18 at 22:25
• @george2079 Thanks for the idea. However, I can't get it to work- see my edits – Hugh May 9 '18 at 12:01

Plot by default uses FormatType->TraditionalForm, and in TraditionalForm single letter variables are italicized. Consider:

{"m", m, m^2} // TraditionalForm


The string is not italicized, but the two symbols are. Your FrameLabel includes the string "m" as well as the boxes "\!$$\*SuperscriptBox[\(m$$, \2\)]\)", this is why there is a mix of italic and non-italic letters.

As an aside, there is no reason to use incomprehensible linear syntax, just use Row objects with expressions instead, e.g.:

Row[{"m ", Superscript[m, 2]}]


" m \!$$\*SuperscriptBox[\(m$$, $$2$$]\)"


Now, in StandardForm, Mathematica doesn't italicize single letters, so one possibility is to just use FormatType->StandardForm.

Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
FrameLabel -> {" m \!$$\*SuperscriptBox[\(m$$, $$2$$]\)\*
StyleBox[$$\!\(\* StyleBox[\" \",\nFontSlant->\"Italic\"]$$\)]\!$$\* StyleBox[SuperscriptBox[\"m\", \"3\"],\nFontSlant->\"Italic\"]$$",
"m \!$$\*SuperscriptBox[\(m$$, $$2$$]\)"},
BaseStyle -> {FontFamily -> Times, FontSize -> 24}, FormatType->StandardForm]


(the $m^3$ is still italicized because you explicitly set the FontSlant)

Another possibility is to use strings ("m") instead of symbols (m):

Plot[Sin[x], {x, 0, 2 π}, Frame -> True,
FrameLabel -> {" m \!$$\*SuperscriptBox[\(\"m\"$$, $$2$$]\)\*
StyleBox[$$\!\(\* StyleBox[\" \",\nFontSlant->\"Italic\"]$$\)]\!$$\* StyleBox[SuperscriptBox[\"m\", \"3\"],\nFontSlant->\"Italic\"]$$",
"m \!$$\*SuperscriptBox[\(\"m\"$$, $$2$$]\)"},
BaseStyle -> {FontFamily -> Times, FontSize -> 24}]


(I don't include the output because it looks the same as the previous image).

Another possibility is to just include specific Style wrappers to enforce FontSlant -> Plain.

At any rate, a good first step is stop using strings with linear syntax!

I said you should use Row, but you instead used Times. At any rate, since you're interested in units, I would use the Quantity framework (this also produces the in-line fractions that you wanted):

Plot[
Sin[x],
{x, 0, 2 Pi},
Frame->True,
FrameLabel->{
Row[{"Stress (", Quantity[None, "Newtons"/"Meters"^2],")"}],
Row[{"Acceleration (", Quantity[None, "Meters"/"Seconds"^2],")"}]
},
BaseStyle->{FontFamily->"Times", FontSize->12}
]


• I tend to prefer using SingleLetterItalics->False – b3m2a1 May 9 '18 at 0:51
• Thanks for looking at this. I can't seem to get your ideas to work. Please see my edits. Also the mess with the backslashes is the result of copying using the uploader. I don't know how to avoid that. – Hugh May 9 '18 at 9:33
• Thanks for the update. What a complicated method. I guess I will make a module for FrameLabel. It's seems a shame that such a simple thing as labeling an axis can get so complicated. I very much appreciate your help and patience. – Hugh May 9 '18 at 19:44