4
$\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$
3
  • $\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$ Commented Mar 2, 2018 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$ Commented Mar 2, 2018 at 11:14
  • $\begingroup$ Looks like SingleLetterItalics is switching True and False $\endgroup$ Commented Mar 2, 2018 at 22:09

3 Answers 3

4
$\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$
1
  • $\begingroup$ Thanks @Mike for SingleLetterItalics. Could you tell me how to make SingleLetterItalics -> False as default. $\endgroup$ Commented Mar 3, 2018 at 8:18
4
$\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$
1
  • $\begingroup$ Thanks, @CarlWoll for the detailed answer. $\endgroup$ Commented Mar 4, 2018 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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.