[Tex/LaTex] Set the “font-weight: lighter/ bolder”

boldfontsfontspecxetex

I need to know how to set the "font-weight: lighter/ bolder"

font-weight: lighter/ bolder

\documentclass{article} 
\usepackage{fontspec}
\begin{document} 
\font\ta="Times New Roman":color=ff0000 at 10pt
\font\tenrm = cmr17 at 10pt

\font\scra="Charis SIL/m" at 12pt
\font\scrb="Charis SIL/b" at 12pt
\font\scrc="Charis SIL/bx" at 12pt
\font\scrd="Charis SIL/sb" at 12pt
\font\scre="Charis SIL/c" at 12pt


\font\scrTa="Times New Roman/m" at 12pt
\font\scrTb="Times New Roman/b" at 12pt
\font\scrTc="Times New Roman/bx" at 12pt
\font\scrTd="Times New Roman/sb" at 12pt
\font\scrTe="Times New Roman/c" at 12pt


\ta{font-weight: lighter/ bolder }

m Medium
b Bold
bx Bold extended
sb Semi-bold
c Condensed

\scra{am Medium}
\scrb{ab Bold}
\scrc{abx Bold extended}
\scrd{asb Semi-bold}
\scre{ac Condensed}


\scrTa{am Medium}
\scrTb{ab Bold}
\scrTc{abx Bold extended}
\scrTd{asb Semi-bold}
\scrTe{ac Condensed}


\afseries{ultralight}
\lfseries{light}
\sfseries{semibold}
\bfseries{bold}
\cfseries{black}
\xfseries{extra black}

\afseries ultralight
\lfseries light
\sfseries semibold
\bfseries bold
\cfseries black
\xfseries extra black

\tenrm{T1 classT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clasT1 clas }

\end{document}

Please help me.

Thanks

Best Answer

There are various problems with the code you have posted.

  1. You are using TeX primitives to choose fonts rather than the LaTeX commands provided by the fontspec package.

  2. If a particular font doesn't have different weights, then no amount of choosing them will cause the weights to appear. For example, Charis SIL comes only in Regular, Bold, Italic, and Bold Italic.

  3. Even when using the XeTeX commands as opposed to the fontspec commands, the "/" suffix to the font name must be in upper-case, not lower case, and (at least from the XeTeX documentation) there are only four possibilities: B, I, BI and IB (the latter two being identical).

So for other weights, I think you need to choose the font by name directly. Here's a version of your document using fontspec commands and Minion Pro, which has various weights (on my system). If you want to use e.g. bold with a font that doesn't have it, you can use the [AutoFakeBold] option when loading the font.

% !TEX TS-program = XeLaTeX

\documentclass{article} 
\usepackage{fontspec}
\setmainfont{Minion Pro}
\newfontfamily\semibold{Minion Pro Semibold}
\newfontfamily\condensed{Minion Pro Bold Cond}
\newfontfamily\regsemi[BoldFont={* Bold Cond}]{Minion Pro}
\newfontfamily\regitbold[BoldFont={* Bold Italic}]{Minion Pro}
\begin{document} 


{\semibold Some semibold text.}

{\condensed Some bold condensed.}

{\regsemi Regular with \textbf{Semibold} as the bold font.}

{Regular with \textbf{Bold} as the bold font. }

{\regitbold Regular with \textbf{Bold Italic} as the bold font.}
\end{document}

output of code