4

I want to create a new font family with \newfontfamily{\rb}{Roboto} from here:
https://fonts.google.com/specimen/Roboto?subset=latin&preview.text=Hello&preview.text_type=custom#standard-styles

I want to write a few words with weight 300 for example, it is possible?
I saw this question: Set the "font-weight: lighter/ bolder"

But there are two things:

  1. I want to change it on the specific words, and not overall...
    so I'm looking for kind of a command like \textbf or something like that.
  2. I want to use numbers (the number of the weight).

Thank you!

2
  • 2
    Does this answer help? For your font, the weight 300 version is probably called either Roboto Light or Roboto Light 300. Mar 29, 2021 at 16:17
  • Probably yes... @WillieWong - It's not what I asked for the answer says, but it helps somehow... :) Thank you!
    – heblyx
    Mar 30, 2021 at 14:17

1 Answer 1

3

weight command demo

Roboto weight 300 is called Roboto-Light.ttf, so, using the recommended standard weight series names (see texdoc fntguide), you can load it using fontspec as {l} series and then set up a \textl{} command to use it.

Roboto weights

As to using numbers in command names, you can use Roman numerals (\textiii):

weights

Or alternatively, set up a generic command that takes a numeric option, which in turn calls the matching \text... command behind the scenes.

weight option

MWE

\documentclass[12pt]{article}
\newcommand\myfontname{Roboto}
\usepackage[table]{xcolor}
\usepackage{fontspec}
\setmainfont[
    Path = c:/windows/fonts/, 
         Extension = .ttf,
    UprightFont     = *-Regular,
%    BoldFont = *-Bold,
    ItalicFont = *-Italic,
%    BoldItalicFont = *-BoldItalic,
    FontFace = {ul}{\shapedefault}{*-Thin},
    FontFace = {ul}{it}{*-ThinItalic},
%    FontFace = {el}{\shapedefault}{*-ExtraLight},
%    FontFace = {el}{it}{*-ExtraLightItalic},
    FontFace = {l}{\shapedefault}{*-Light},
    FontFace = {l}{it}{*-LightItalic},
    FontFace = {sl}{\shapedefault}{*-Regular},
    FontFace = {sl}{it}{*-Italic},
    FontFace = {m}{\shapedefault}{*-Medium},
    FontFace = {m}{it}{*-MediumItalic},
%    FontFace = {sb}{\shapedefault}{*-SemiBold},
%    FontFace = {sb}{it}{*-SemiBoldItalic},
    FontFace = {b}{\shapedefault}{*-Bold},
    FontFace = {b}{it}{*-BoldItalic},
%    FontFace = {eb}{\shapedefault}{*-ExtraBold},
%    FontFace = {eb}{it}{*-ExtraBoldItalic},
    FontFace = {ub}{\shapedefault}{*-Black},
    FontFace = {ub}{it}{*-BlackItalic},
]{\myfontname}

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}    \DeclareTextFontCommand{\textul}{\ulseries}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}  \DeclareTextFontCommand{\textl}{\lseries}
\DeclareRobustCommand{\slseries}{\fontseries{sl}\selectfont}    \DeclareTextFontCommand{\textsl}{\slseries}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}  \DeclareTextFontCommand{\textm}{\mseries}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}  \DeclareTextFontCommand{\textb}{\bseries}
    
\DeclareRobustCommand{\ubseries}{\fontseries{ub}\selectfont}    \DeclareTextFontCommand{\textub}{\ubseries}

\newcommand{\texti}[1]{\textul{#1}}
\newcommand{\textiii}[1]{\textl{#1}}
\newcommand{\textiv}[1]{\textsl{#1}}
\newcommand{\textv}[1]{\textm{#1}}
\newcommand{\textvii}[1]{\textb{#1}}
\newcommand{\textix}[1]{\textub{#1}}

\expandafter\newcommand\csname text100\endcsname[1]{\textul{#1}}
\expandafter\newcommand\csname text300\endcsname[1]{\textl{#1}}
\expandafter\newcommand\csname text400\endcsname[1]{\textsl{#1}}
\expandafter\newcommand\csname text500\endcsname[1]{\textm{#1}}
\expandafter\newcommand\csname text700\endcsname[1]{\textb{#1}}
\expandafter\newcommand\csname text900\endcsname[1]{\textub{#1}}

\newcommand\textw[2][400]{\csname text#1\endcsname{#2}}




\newcommand\testtext{{\large abc qwerty}}%  \fontname\font}

\begin{document}

{\Large\bfseries\myfontname}

%\end{tabular}
%------------------------------
\begin{tabular}{llll}
\hline
\rowcolor{blue!12}
Font & Series & Upright & Italic \\
100 ultralight & 
ul  & 
\fontseries{ul}\selectfont\testtext  &
\fontseries{ul}\fontshape{it}\selectfont\testtext  \\
%%
%extralight & 
%el & 
%\fontseries{el}\selectfont\testtext  &
%\fontseries{el}\fontshape{it}\selectfont\testtext  \\
%%
300 light & 
l & 
\fontseries{l}\selectfont\testtext  &
\fontseries{l}\fontshape{it}\selectfont\testtext  \\
%
400 semilight & 
sl & 
\fontseries{sl}\selectfont\testtext  &
\fontseries{sl}\fontshape{it}\selectfont\testtext  \\
%
500 medium & 
m & 
\fontseries{m}\selectfont\testtext  &
\fontseries{m}\fontshape{it}\selectfont\testtext  \\
%%
%semibold & 
%sb & 
%\fontseries{sb}\selectfont\testtext  &
%\fontseries{sb}\fontshape{it}\selectfont\testtext  \\
%%
700 bold & 
b & 
\fontseries{b}\selectfont\testtext  &
\fontseries{b}\fontshape{it}\selectfont\testtext  \\
%
%extrabold & 
%eb & 
%\fontseries{eb}\selectfont\testtext  &
%\fontseries{eb}\fontshape{it}\selectfont\testtext  \\
%%
900 ultrabold & 
ub & 
\fontseries{ub}\selectfont\testtext  &
\fontseries{ub}\fontshape{it}\selectfont\testtext  \\
\hline
\end{tabular}

\bigskip
\scshape
%------------------------------
\begin{tabular}{llll}
\hline
\rowcolor{blue!12}
Font & Series & Upright & Italic \\
ultralight & 
ul  & 
\fontseries{ul}\selectfont\testtext  &
\fontseries{ul}\fontshape{it}\selectfont\testtext  \\
%
%extralight & 
%el & 
%\fontseries{el}\selectfont\testtext  &
%\fontseries{el}\fontshape{it}\selectfont\testtext  \\
%%
light & 
l & 
\fontseries{l}\selectfont\testtext  &
\fontseries{l}\fontshape{it}\selectfont\testtext  \\
%
semilight & 
sl & 
\fontseries{sl}\selectfont\testtext  &
\fontseries{sl}\fontshape{it}\selectfont\testtext  \\
%
medium & 
m & 
\fontseries{m}\selectfont\testtext  &
\fontseries{m}\fontshape{it}\selectfont\testtext  \\
%
%semibold & 
%sb & 
%\fontseries{sb}\selectfont\testtext  &
%\fontseries{sb}\fontshape{it}\selectfont\testtext  \\
%%
bold & 
b & 
\fontseries{b}\selectfont\testtext  &
\fontseries{b}\fontshape{it}\selectfont\testtext  \\
%
%extrabold & 
%eb & 
%\fontseries{eb}\selectfont\testtext  &
%\fontseries{eb}\fontshape{it}\selectfont\testtext  \\
%%
ultrabold & 
ub & 
\fontseries{ub}\selectfont\testtext  &
\fontseries{ub}\fontshape{it}\selectfont\testtext  \\
\hline
\end{tabular}

\bigskip
\textl{This is 300 weight.}
\upshape
\textl{This is 300 weight.} \textbackslash textl\{\}


\bigskip
\scshape
\textiii{This is 300 weight.}
\upshape

\texti{This is 100 weight.} \textbackslash texti\{\}

\textiii{This is 300 weight.} \textbackslash textiii\{\}

\textiv{This is 400 weight.} \textbackslash textiv\{\}

\textv{This is 500 weight.} \textbackslash textv\{\}

\textvii{This is 700 weight.} \textbackslash textvii\{\}

\textix{This is 900 weight.} \textbackslash textix\{\}

\bigskip
xyz \texti{abcde} \textiii{abcde} \textiv{abcde} \textv{abcde} 
\textvii{abcde} \textix{abcde} xyz

\bigskip
\textw[900]{fghijk} = \verb|\textw[900]{fghijk}|

\textw[300]{fghijk} = \verb|\textw[300]{fghijk}|


\end{document}




You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .