# 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 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 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

These are great suggestions. I am using Mathematica 12, and I find that the Quantity function does not always format the units properly. In particular, when I want to express a unit with a superscript of -1, (for example $$\mathrm{s}^{-1}$$ for inverse seconds), the Quantity function gives "per second." Here is my solution (using your example).

Plot[
Sin[x],
{x, 0, 2 Pi},
Frame -> True,
FrameLabel -> {
Row[{"Stress (N/", Superscript["m", 2], ")"}],
Row[{"Acceleration (m/", Superscript["s", 2], ")"}]
},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12}
]


Note that in the example above I include the unit abbreviation as a string (in quotes) within the Superscript command. This keeps the unit from being italicized.

If I want, I can express the units with negative exponents.

Plot[
Sin[x],
{x, 0, 2 Pi},
Frame -> True,
FrameLabel -> {
Row[{"Stress (N ", Superscript["m", -2], ")"}],
Row[{"Acceleration (m ", Superscript["s", -2], ")"}]
},
BaseStyle -> {FontFamily -> "Times", FontSize -> 12}
]


This gives me much more control over the format of my labels, even allowing me to use superscripts of -1 where I want.

An example, just to summarize the main points:

test = Text[
Style[#, FontSlant -> Plain, FontSize -> 32], {0,
0}] & /@ {Indexed[P, {i, j}], P}

Graphics /@ test


Graphics[#, FormatType -> StandardForm] & /@ test


Thanks for the question and the answers.

There is a simple workaround. Namely, one can make a row like this:

Row[{Style["m", 24],
Style["\!$$\*SuperscriptBox[\(\[Placeholder]$$, $$2$$]\)", 24]}]


and then manually remove the placeholder

Row[{Style["m", 24],
Style["\!$$\*SuperscriptBox[\($$, $$2$$]\)", 24]}]


Then the plot looks as follows:

Plot[Sin[x], {x, 0, 2 \[Pi]}, Frame -> True,
FrameLabel -> {Row[{Style["m", 24],
Style["\!$$\*SuperscriptBox[\($$, $$2$$]\)", 24]}],
Row[{Style["m", 24],
Style["\!$$\*SuperscriptBox[\($$, $$3$$]\)", 24]}]}]


yielding this

Have fun!