# XeLaTeX and font selection

This is almost a duplicate of but its answer doesn't work for me.

I downloaded the complete Roboto superfamily (Roboto, Roboto Condensed, Roboto Slab and Roboto Mono) and I want to use all the families, all the weights, widths, variants and styles inside my document. Of course mine is not a real need, but I want to understand clearly how the fontspecpackage works.

All my .ttf files are located in a directory called fonts, subdivided into directories with the name of the family (fonts/Roboto, fonts/Roboto_Condensed, etc...).

Inpired by XeLaTeX and font weight, the package documentation of fontspec and the texdoc font installation guide I included the Roboto font in this way.

\setmainfont{Roboto}[
Path = fonts/Roboto/,
Extension = .ttf,
%-- Upright --%
FontFace={ul}{n}{Font=*-Thin},
FontFace={l}{n}{Font=*-Light},
FontFace={m}{n}{Font=*-Regular},
FontFace={mb}{n}{Font=*-Medium},
FontFace={b}{n}{Font=*-Bold},
FontFace={eb}{n}{Font=*-Black},
% %-- Italic --%
FontFace={ul}{it}{Font=*-ThinItalic},
FontFace={l}{it}{Font=*-LightItalic},
FontFace={m}{it}{Font=*-Italic},
FontFace={mb}{it}{Font=*-MediumItalic},
FontFace={b}{it}{Font=*-BoldItalic},
FontFace={eb}{it}{Font=*-BlackItalic},
]


But I obtain the following error:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!

! fontspec error: "font-not-found"

!

! The font "Roboto" cannot be found.

!

! See the fontspec documentation for further information.

!

! For immediate help type H .

!...............................................

But the path is right. In fact with this MWE

\documentclass[10pt]{article}

\usepackage{fontspec}

\setmainfont{Roboto}[
Path = fonts/Roboto/,
Extension = .ttf,
UprightFont = *-Regular,
%-- Upright --%
FontFace={ul}{n}{Font=*-Thin},
FontFace={l}{n}{Font=*-Light},
FontFace={m}{n}{Font=*-Regular},
FontFace={mb}{n}{Font=*-Medium},
FontFace={b}{n}{Font=*-Bold},
FontFace={eb}{n}{Font=*-Black},
% %-- Italic --%
FontFace={ul}{it}{Font=*-ThinItalic},
FontFace={l}{it}{Font=*-LightItalic},
FontFace={m}{it}{Font=*-Italic},
FontFace={mb}{it}{Font=*-MediumItalic},
FontFace={b}{it}{Font=*-BoldItalic},
FontFace={eb}{it}{Font=*-BlackItalic},
]

\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}
\DeclareRobustCommand{\mbseries}{\fontseries{mb}\selectfont}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}
\DeclareRobustCommand{\ebseries}{\fontseries{eb}\selectfont}
\DeclareTextFontCommand{\textul}{\ulseries}
\DeclareTextFontCommand{\textl}{\lseries}
\DeclareTextFontCommand{\textm}{\mseries}
\DeclareTextFontCommand{\textmb}{\mbseries}
\DeclareTextFontCommand{\textb}{\bseries}
\DeclareTextFontCommand{\texteb}{\ebseries}

\begin{document}

\sffamily
\textul{Abc Thin} {\ulseries Thin}

\textl{Abc Light} {\lseries Light}

\textm{Abc Light} {\mseries Light}

Abc Regular

\textmb{Abc SemiBold} {\mbseries SemiBold}

\textb{Abc Bold} {\bseries Bold}

\texteb{Abc ExtraBold} {\ebseries ExtraBold}

\end{document}


I obtain this warning

LaTeX Font Warning: Font shape TU/lmss/ul/n' undefined (Font) usingTU/lmss/m/n' instead on input line 53.

LaTeX Font Warning: Font shape TU/lmss/l/n' undefined (Font) usingTU/lmss/m/n' instead on input line 55.

LaTeX Font Warning: Font shape TU/lmss/mb/n' undefined (Font) usingTU/lmss/m/n' instead on input line 61.

LaTeX Font Warning: Font shape TU/lmss/eb/n' undefined (Font) usingTU/lmss/m/n' instead on input line 65.

And this result, that clearly is not what I want.

• Maybe Path=./fonts/Roboto? Where is the fonts directory located? – egreg May 22 '18 at 21:12
• In the same directory where my document is. In the first case it throws the error but if I add UprightFont = *-Regular as shown in the MWE it doesn't throw errors but only warning. – gvgramazio May 22 '18 at 21:17
• So I think that the error is in FontFace={..}{...}{Font=*-...}. I checked the last brackets and all the files have the correct name. For the first two brackets I used the values in Tables A.1 and A.3 of font installation guide as suggested by the fontspec documentation. – gvgramazio May 22 '18 at 21:21
• You should use \setsansfont if you want Roboto for sans serif – egreg May 22 '18 at 21:34
• What an idiot I am. – gvgramazio May 22 '18 at 21:37

The problem was that I didn't select the roman font family but the sans serif one as pointed out by egreg in the comments. However an alone of mistery still remains in my opinion: why xelatex throw an error if I don't put UprightFont = ...?

However, this is the final result

\documentclass[10pt]{article}

\usepackage{fontspec}

\setmainfont{RobotoSlab}[
Path = fonts/Roboto_Slab/,
Extension = .ttf,
UprightFont = *-Regular,
%-- Upright --%
FontFace={ul}{n}{Font=*-Thin},
FontFace={l}{n}{Font=*-Light},
FontFace={m}{n}{Font=*-Regular},
FontFace={b}{n}{Font=*-Bold},
]

\setmonofont{RobotoMono}[
Path = fonts/Roboto_Mono/,
Extension = .ttf,
UprightFont = *-Regular,
%-- Upright --%
FontFace={ul}{n}{Font=*-Thin},
FontFace={l}{n}{Font=*-Light},
FontFace={m}{n}{Font=*-Regular},
FontFace={mb}{n}{Font=*-Medium},
FontFace={b}{n}{Font=*-Bold},
% %-- Italic --%
FontFace={l}{it}{Font=*-LightItalic},
FontFace={m}{it}{Font=*-Italic},
FontFace={mb}{it}{Font=*-MediumItalic},
FontFace={b}{it}{Font=*-BoldItalic},
]

\setsansfont{Roboto}[
Path = fonts/Roboto/,
Extension = .ttf,
UprightFont = *-Regular,
%-- Upright --%
FontFace={ul}{n}{Font=*-Thin},
FontFace={l}{n}{Font=*-Light},
FontFace={m}{n}{Font=*-Regular},
FontFace={mb}{n}{Font=*-Medium},
FontFace={b}{n}{Font=*-Bold},
FontFace={eb}{n}{Font=*-Black},
% %-- Italic --%
FontFace={ul}{it}{Font=*-ThinItalic},
FontFace={l}{it}{Font=*-LightItalic},
FontFace={m}{it}{Font=*-Italic},
FontFace={mb}{it}{Font=*-MediumItalic},
FontFace={b}{it}{Font=*-BoldItalic},
FontFace={eb}{it}{Font=*-BlackItalic},
]

\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}
\DeclareRobustCommand{\mbseries}{\fontseries{mb}\selectfont}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}
\DeclareRobustCommand{\ebseries}{\fontseries{eb}\selectfont}
\DeclareTextFontCommand{\textul}{\ulseries}
\DeclareTextFontCommand{\textl}{\lseries}
\DeclareTextFontCommand{\textm}{\mseries}
\DeclareTextFontCommand{\textmb}{\mbseries}
\DeclareTextFontCommand{\textb}{\bseries}
\DeclareTextFontCommand{\texteb}{\ebseries}

\begin{document}

\textul{Abc Thin} {\ulseries Thin} \par
\textl{Abc Light} {\lseries Light} \par
\textm{Abc Regular} {\mseries Regular} \par
\textb{Abc Bold} {\bseries Bold} \par
\ttfamily
\textul{Abc Thin} {\ulseries Thin} \par
\textl{Abc Light} {\lseries Light} \par
\textm{Abc Regular} {\mseries Regular} \par
\textmb{Abc Medium} {\mbseries Medium} \par
\textb{Abc Bold} {\bseries Bold} \par
\itshape
\textl{Abc Light} {\lseries Light} \par
\textm{Abc Regular} {\mseries Regular} \par
\textmb{Abc Medium} {\mbseries Medium} \par
\textb{Abc Bold} {\bseries Bold} \par
\sffamily\upshape
\textul{Abc Thin} {\ulseries Thin} \par
\textl{Abc Light} {\lseries Light} \par
\textm{Abc Regular} {\mseries Regular} \par
\textmb{Abc SemiBold} {\mbseries SemiBold} \par
\textb{Abc Bold} {\bseries Bold} \par
\texteb{Abc Black} {\ebseries Black} \par
\itshape
\textul{Abc Thin} {\ulseries Thin} \par
\textl{Abc Light} {\lseries Light} \par
\textm{Abc Regular} {\mseries Regular} \par
\textmb{Abc SemiBold} {\mbseries SemiBold} \par
\textb{Abc Bold} {\bseries Bold} \par
\texteb{Abc Black} {\ebseries Black} \par

\end{document}


and this is the result.

Hope that it can be helpful to someone in the future.

If egreg want to put his comment as answer I'll gladly accept it.

• If you don’t include UprightFont=... it tries to load RobotoSlab.ttf, which doesn’t exist. – Will Robertson May 22 '18 at 22:57

Nice self-answer! I do have one thing to add: the official names for font weights in LaTeX are:

• Ultra Light: ul
• Extra Light: el
• Light: l
• Semi Light: sl
• Medium/regular/book m
• Semi bold: sb
• Bold: b
• Extra Bold: eb
• Ultra Bold: ub

These combine with an optional width class to form a series. The official width classes are:

• Ultra Condensed (50%) uc
• Extra Condensed (65.5%) ec
• Condensed (75%) c
• Semi Condensed (87.5%) sc
• Medium (100%) m
• Semi Expanded (112.5%) sx
• Expanded (125%) x
• Extra Expanded (150%) ex
• Ultra Expanded (200%) ux

A weight class followed by a width class form a font series. (Medium width is normally omitted.) So, {bx}{it} is bold expanded italic, and {sbc}{sl} is semi-bold condensed slanted/oblique.

Although you can use any arbitrary letter-strings as series and shape names and fontspec won’t complain, if you’re intending to use commands like \textl on more than just this one font, you’re probably better off using the standard names. You’ll also ease migration from a few NFSS packages, such as nfssext-cfr.

Following these conventions, semibold should be sb rather than mb, and thin could be either ul or el.

Since tracking the information down is a pain, the fontspec manual endorses this scheme without describing it and gives a footnote to the “LaTeX Font Selection” documentation from LaTeX2e. That document says, “Whenever possible, you should use the series and shape names suggested in The LaTeX Companion since this will make it easier to combine new fonts with existing fonts.” This is the book by Frank Mittelbach and Michel Goossens, published by Addison_Wesley. The information is on page 414 of the second edition.

### PS

Thanks for the link to the “Font Installation” document that also lists the series {mb} between {m} and {sb} and {db} between {sb} and {b}. I see that a few packages, such as nfssext-cfr, support them. It’s a good idea to use these series for a font family that comes in separate Regular/Book, Medium, Semibold and Bold weights, or Semibold, Demibold and Bold. If, in fact, you want to use all those different weights within the same document, which many people think you shouldn’t.

If there’s only one font weight between Regular and Bold, though, my personal recommendation is to call it {sb}, even if the official name is Medium or Demibold. That is what Computer Modern Demi does. Or you could even define {mb}, {sb} and {db} for every font family, even if {sb} is the same as {mb} and {db} is the same as {b}, so that you can use \fontseries{mb} freely and always get something sensible. Of course, if you don’t care about compatibility with other packages or being able to replace the font family with another in your preamble, you can call it whatever you want.

• Thanks a lot for your answer. However, are you sure about official names for weights? Could you link a reference? I would appreciate very much. I found that m stands for book and regular while mb stands for medium according to NFSS series (ref. [texdoc.net/texmf-dist/doc/fonts/Type1fonts/… Installation Guide - Appendix A)). I choose medium instead of semibold because the font name was already with medium. Anyway, I'm too noob to say what is the difference between a medium font and a semibold one. – gvgramazio Aug 6 '18 at 13:40
• Also, I agree that tracking the information down is a pain. There are a lot of references but not a clear rule. I still didn't understand if these are conventions or real rules. – gvgramazio Aug 6 '18 at 13:42
• @gvgramazio The reference is page 414 of The LaTeX Companion (cited in the LaTeX2e documentation and the fontspec manual). (As I wrote.) – Davislor Aug 6 '18 at 15:33
• @gvgramazio Thanks for the reference. On page 90, it does list medium-bold and demi-bold as additional weights. This is presumably because some fonts come in demibold or medium weights in addition to semibold. (Usually, Medium is lighter than Semibold and Demibold is heavier.) I see that some packages, including nfssext-cfr, do use those font weights. If there’s only one font weight between Regular and Bold, however, I’d recommend calling it {sb}, as for example Computer Modern Demi does. – Davislor Aug 6 '18 at 15:55
• @Davislor — I'm wondering in fontspec whether I could just allow the user to say BoldFont=x,BoldFont=y,BoldFont=z, and this would produce three weights with series b1, b2, b3, ... , then provide user commands like \textbolder and \textlighter to move between them. Do you think this would be a good approach as a user? – Will Robertson Aug 7 '18 at 10:16