In general, fontspec
will try to guess the appropriate fonts to switch to for common changes such as regular/bold weight, upright/italic shape etc. However, it is not unusual for its guesses to be wrong. Fonts are just too variously named for any kind of guarantees here.
When things don't work as you want them to, you often need to be more directive. That is, rather than leaving fontspec
to figure out which font to switch to when you ask for bold, say, you can tell it what to do in advance. Moreover, you can also be more specific about which font you mean by Arial
, say, if it finds the 'wrong' one.
For instance, on my machine, requesting Roboto
doesn't get me the opentype font I expected, but a truetype version which lacks the shapes/weights of the family I wanted.
The following is an example for Roboto
, which doesn't demonstrate the original problem, but can easily be made to demonstrate closely related problems. The general approach should be valid for your situation, too. This also makes it more likely your document will work correctly on another system, which may have different fonts.
\setmainfont{Roboto}
[
Since I don't want the .ttf
fonts, which LuaTeX seems to prefer, I specify use of the .otf
. This is only harmful if you want your document to use either e.g. to support users with one or the other, but not both, formats installed.
Extension = .otf,
The standard, default font is going to be Roboto-Regular.otf
(which is part of TeX Live, but that's not relevant here).
UprightFont = *-Regular,
I want Roboto-Bold.otf
, Roboto-Italic.otf
and Roboto-BoldItalic.otf
for the obvious weights/shapes.
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
I'm also going to tell it to use these when oblique is requested, since this didn't seem to work by default once I got more prescriptive generally.
SlantedFont = *-Italic,
BoldSlantedFont = *-BoldItalic,
There are different methods available at this point and different people will prefer different options for different purposes. The following is probably not the most popular of the available methods. I like it because it corresponds very closely to LaTeX standard font selection commands. (In fact, if I wasn't answering a question here, I might well do the previous lines like this, too.)
The syntax is
FontFace = {<series>}{<shape>}{<font>}
where <series>
combines both weight and width. The default series is m
(medium). Condensed is c
and bold condensed is bc
.
FontFace = {c}{n}{*Condensed-Regular},
n
is upright. So this says that if condensed, regular is requested while the main font is active, fontspec
should load <main font>Condensed-Regular
i.e. RobotoCondensed-Regular.otf
.
FontFace = {bc}{n}{*Condensed-Bold},
Bold concensed (bc
) upright (n
).
Now the italic (it
).
FontFace = {c}{it}{*Condensed-Italic},
FontFace = {bc}{it}{*Condensed-BoldItalic},
Finally, oblique (sl
).
FontFace = {c}{sl}{*Condensed-Italic},
FontFace = {bc}{sl}{*Condensed-BoldItalic},
]
To make things easy, I like to have LaTeX-like font selection commands even for non-standard switches, such as changing from medium width to condensed, so I'd say something like the following.
\makeatletter
\DeclareRobustCommand \cdwidth{%
\not@math@alphabet\cdwidth\relax
\fontseries{c}\selectfont}
This sets up \cdwidth
to do something similar to \bfseries
, but rather than switching both weight and width, this will only change the width. So, if we are currently using regular, we'll get condensed regular; if we're using bold, we'll get condensed bold.
\DeclareTextFontCommand \textcd{\cdwidth}
We might as well have a standard \text<two-letter-suffix>{}
macro, too. So \textcd{}
will work like \textbf{}
, \textit{}
etc.
Then we can write
This is (plain) Roboto.
{\cdwidth
This is Roboto Condensed \textbf{Bold Roboto Condensed}.
This is Roboto Condensed \textbf{\textsl{Bold Slanted Roboto Condensed}}.}
This is Roboto \textbf{\textit{Bold Italic (plain) Roboto}}.
to produce
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Roboto}
[
Extension = .otf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
SlantedFont = *-Italic,
BoldSlantedFont = *-BoldItalic,
FontFace = {c}{n}{*Condensed-Regular},
FontFace = {bc}{n}{*Condensed-Bold},
FontFace = {c}{it}{*Condensed-Italic},
FontFace = {bc}{it}{*Condensed-BoldItalic},
FontFace = {c}{sl}{*Condensed-Italic},
FontFace = {bc}{sl}{*Condensed-BoldItalic},
]
\makeatletter
\DeclareRobustCommand \cdwidth{%
\not@math@alphabet\cdwidth\relax
\fontseries{c}\selectfont}
\DeclareTextFontCommand \textcd{\cdwidth}
\makeatother
\pagestyle{empty}
\begin{document}
This is (plain) Roboto.
{\cdwidth
This is Roboto Condensed \textbf{Bold Roboto Condensed}.
This is Roboto Condensed \textbf{\textsl{Bold Slanted Roboto Condensed}}.}
This is Roboto \textbf{\textit{Bold Italic (plain) Roboto}}.
\end{document}
fontspec
a whole lot, but I don't think you are supposed to keep changing the main document font. You should probably only use that command in the preamble to set the main font and then use other commands to load additional fonts if necessary. Note that it is hard for people to reproduce if you use commercial fonts not everyone has. If you can only demonstrate the issue with Arial, that's one thing. If you can reproduce it using a font supplied as part of TeX Live, say, that's far preferable.fontspec
to avoid issues and have things work smoothly. (Not to avoid this issue, I don't think, but just in general.)