2
$\begingroup$

The objective is to use a Roman (i.e., non-italic) font in FrameLabel.

Consider this

Plot[Sin[x Pi], {x, 0, 2}, Frame -> True,
  FrameLabel -> {"\!\(\*FractionBox[\(x\), \(π\)]\)",
                 "\!\(\*SuperscriptBox[\(y\), \(0\)]\)"},
  LabelStyle -> {20, Black, FontFamily -> "Times"}]

enter image description here

As you can see the FrameLabels are in italics. I can prevent italics for $y^0$ by using Superscript["y", "0"], but I could not find any way to handle the fraction.

Plot[Sin[x Pi], {x, 0, 2}, Frame -> True, 
         FrameLabel -> {DisplayForm[FractionBox["x", "π"]], Superscript["y", "0"]}, 
         LabelStyle -> {20, Black, FontFamily -> "Times"}]

enter image description here

Questions:

  1. Why is SuperScript appearing in Roman but SuperScriptBox is appearing in Italic?

  2. How to get a Roman font for the fraction?

I have not tried using MaTeX yet. I would like to see first if this problem can be fixed with a small tweak. I am using MMA11.1 in Linux.

$\endgroup$
  • $\begingroup$ Digits are simply set upright. That's common practice in mathematical typesetting since constants are not to set in italics. Numbers are constants. Compare also to the practice in LaTeX. In principle, also $\pi$ should be an $\uppi$ (it is available in LaTeX by loading the package upgreek). Replace Superscript["y", "0"] with Superscript["y", "z"] and you will see that exponents are set in italics in general. $\endgroup$ – Henrik Schumacher Mar 2 '18 at 11:09
  • 1
    $\begingroup$ Ah, now I see. The base y is also not in italics in your example. That's weird; it is typeset correctly in MMA 11.0.1 for macos. Maybe applying the Style to both framelabels by hand would help. $\endgroup$ – Henrik Schumacher Mar 2 '18 at 11:14
  • $\begingroup$ Looks like SingleLetterItalics is switching True and False $\endgroup$ – Mike Honeychurch Mar 2 '18 at 22:09
2
$\begingroup$

SingleLetterItalics is controlling this behaviour. For example:

Plot[Sin[x Pi], {x, 0, 2}, Frame -> True, 
 FrameLabel -> {DisplayForm[FractionBox["x", "\[Pi]"]], 
   DisplayForm[SuperscriptBox["y", "0"]]}, 
 LabelStyle -> {20, Black, FontFamily -> "Times"}]

vs making the label two characters long

Plot[Sin[x Pi], {x, 0, 2}, Frame -> True, 
 FrameLabel -> {DisplayForm[FractionBox["x", "\[Pi]"]], 
   DisplayForm[SuperscriptBox["y2", "0"]]}, 
 LabelStyle -> {20, Black, FontFamily -> "Times"}]

If you want to stick with using DisplayForm and boxes then try this:

Plot[Sin[x Pi], {x, 0, 2}, Frame -> True, 
 FrameLabel -> {DisplayForm[FractionBox["x", "\[Pi]"]], 
   DisplayForm[
    SuperscriptBox[Style["y", SingleLetterItalics -> False], "0"]]}, 
 LabelStyle -> {20, Black, FontFamily -> "Times"}]
$\endgroup$
  • $\begingroup$ Thanks @Mike for SingleLetterItalics. Could you tell me how to make SingleLetterItalics -> False as default. $\endgroup$ – Sumit Mar 3 '18 at 8:18
3
$\begingroup$

The default format for Graphics is TraditionalForm:

Options[GraphicsBox, FormatType]

{FormatType -> TraditionalForm}

TraditionalForm uses SingleLetterItalics:

CurrentValue[{StyleDefinitions, "TraditionalForm", SingleLetterItalics}]

True

SingleLetterItalics displays single letter variables in italics. Note that single letter strings are not variables, and so they do not get italicized. So, in the following, the first output is in italics, while the second output is not:

y //TraditionalForm
"y" //TraditionalForm

y

y

So, three simple approaches to avoid italics are:

  1. Use StandardForm (which has SingleLetterItalics->False)
  2. Use strings instead of variables
  3. Put your labels inside of a Style wrapper (e.g., Style[y, Plain] or Style[y, SingleLetterItalics->False])

Now, for the question about why your example had a mixture of italic and plain variables. Mathematica typesetting converts expressions into boxes in order to show them in two-dimensional form. For example:

MakeBoxes[x/π, TraditionalForm] //InputForm

FractionBox["x", "π"]

Notice the presence of the box form FractionBox and that the variable x and constant π have been converted to their symbol names "x" and "π". One can use DisplayForm to print boxes inside an expression in explicit two-dimensional form (I prefer RawBoxes to DisplayForm, because DisplayForm encourages the mixing of expressions and boxes, and I think they should never be mixed). Your first label:

DisplayForm[FractionBox["x", "π"]]

is thus equivalent to the typeset form of x/π, and so naturally in TraditionalForm the x is displayed in italics. Your second label:

Superscript["y", "0"]

is just an expression, and so the "y" is not displayed in italics. If you had used:

DisplayForm[SuperscriptBox["y", "0"]]

instead, then since SuperscriptBox is a box form, "y" would be the box representation of the variable y and it would have been displayed in italics.

Here then are a few examples of a FrameLabel option that would not typeset anything in italics:

FrameLabel -> {"x"/π, "y"^"0"}
FrameLabel -> {"x"/π, HoldForm["y"^0]}
FrameLabel -> {
    Style[x/π, SingleLetterItalics->False],
    Style[Superscript[y,0], Plain]
}
$\endgroup$
  • $\begingroup$ Thanks, @CarlWoll for the detailed answer. $\endgroup$ – Sumit Mar 4 '18 at 16:34
1
$\begingroup$

You could apply Style to each axis label as well:

Plot[Sin[x Pi], {x, 0, 2}, Frame -> True, FrameStyle -> (FontSlant -> Plain),
FrameLabel -> DisplayForm /@ {FractionBox@(Sequence @@ (Style[#, Plain] & /@ {"x","\[Pi]"})),
Superscript[Style["y", Plain], "0"]}, LabelStyle -> {20, Black, FontFamily -> "Times"}]

enter image description here

$\endgroup$

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.