[Tex/LaTex] XeLaTeX and font selection

fontsfontspecxetex

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)
using
TU/lmss/m/n' instead on input line 53.

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

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

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

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

example

Best Answer

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.

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.