定义新命令以在字体的正常/压缩版本之间切换

定义新命令以在字体的正常/压缩版本之间切换

我有一种字体Exo 2,有三个版本:扩展、正常、压缩(我们称之为密度)。我想定义一个新的切换命令,它的工作方式与\itshape, slshape或类似bfseries,但会将我从当前字体切换到另一种密度。类似于\narrowdensity\normdensity\expanddensity

一个不好的解决方法如下:

\documentclass{scrartcl}

\usepackage[no-math]{fontspec}
\usepackage{polyglossia}

\usepackage{lipsum}

\setmainlanguage{english}
\defaultfontfeatures{Ligatures=TeX}

\setmainfont{Exo 2}[%
    Extension       =   .otf,
    UprightFont     =   *-Regular,
    ItalicFont      =   *-Italic,
    BoldFont        =   *-Bold,
    BoldItalicFont  =   *-BoldItalic,
    FontFace        =   {black}{n}{*-Black},
    FontFace        =   {black}{it}{*-BlackItalic},
]

\newfontfamily{\exoexp}{Exo 2}[%
    Extension       =   .otf,
    UprightFont     =   *-Regular Expanded,
    ItalicFont      =   *-Regular Expanded,%because there is no italic expanded
    BoldFont        =   *-Bold Expanded,
    BoldItalicFont  =   *-Bold Expanded,
    FontFace        =   {black}{n}{*-Black Expanded},
    FontFace        =   {black}{it}{*-Black Expanded},
]

\makeatletter

\DeclareRobustCommand\blackseries
{\not@math@alphabet\blackseries\mathbf
    \fontseries{black}\selectfont
}

\makeatother

\begin{document}
\blackseries
\lipsum[1]

{
\exoexp
\lipsum[1]
}

\mdseries
\lipsum[1]

\end{document}

但我必须\exp为所有字体定义不同的命令。是否fontspec提供为字体赋予新特征的功能density,如shapeseries?注意:如果切换了其中一个特征,则另一个特征应保留。

答案1

字体答案可能会有帮助。

如果我想使用超轻重量、浓缩黑色重量和小型大写超浓缩半粗斜体:

三个系列

平均能量损失

 \documentclass[12pt]{article}
\usepackage{xcolor}
\pagecolor{red!3}

\usepackage{fontspec}

\setromanfont{Noto Serif}[
FontFace={ul}{n}{Font=* Thin},
FontFace={ul}{it}{Font=* Thin Italic},
FontFace={xbc}{n}{Font=* Condensed Black},
FontFace={sbxsci}{i}{Font=* ExtraCondensed SemiBold Italic,SmallCapsFont={* ExtraCondensed SemiBold Italic},SmallCapsFeatures={Letters=SmallCaps},},
  ]

\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}
\DeclareRobustCommand{\xbcseries}{\fontseries{xbc}\selectfont}
\DeclareRobustCommand{\sbxsciseries}{\fontseries{sbxsci}\fontshape{i}\scshape\selectfont}




\DeclareTextFontCommand{\textul}{\ulseries}
\DeclareTextFontCommand{\textxbc}{\xbcseries}
\DeclareTextFontCommand{\textsbxsci}{\sbxsciseries}


\begin{document}
\begin{center}
%\fontname\mseries
\section*{Noto Serif}
%\rmfamily
%\itshape
%\scshape

\begin{tabular}{c}Cases\\ \hline\ \\
\textul{Abc Thin} {\ulseries Thin}\\
\textxbc{Abc Black} {\xbcseries Black}\\
\textsbxsci{Abc SemiBold} {\sbxsciseries SemiBold}\\
\end{tabular}
\end{center}

The \textsbxsci{definition} of a \textul{Cat} is ``a domesticated carnivorous \textxbc{quadruped}'' descended, it seems, from a \textit{tiger} ancestor. To use \textbackslash textit with \textul{Cat}, I would have to define an italic item as well, being careful to name the shape as \texttt{it} because that is what \textbackslash textit goes looking for: \textit{\textul{Cat}}.

\end{document}

编辑后添加:Exo

Exo 重量和形状

smcp注意:直立字体中没有小型大写字母 ( )。

梅威瑟:

 \documentclass[12pt]{article}
\usepackage{xcolor}
\pagecolor{red!3}

\usepackage{fontspec}

\setromanfont{Exo}[
FontFace={ul}{n}{Font=* Thin},
FontFace={el}{n}{Font=* ExtraLight},
FontFace={l}{n}{Font=* Light},
FontFace={r}{n}{Font=* Regular},
FontFace={m}{n}{Font=* Medium},
FontFace={sb}{n}{Font=* SemiBold},
FontFace={b}{n}{Font=* Bold},
FontFace={eb}{n}{Font=* ExtraBold},
FontFace={xb}{n}{Font=* Black},
FontFace={uli}{i}{Font=* Thin Italic},
FontFace={eli}{i}{Font=* ExtraLight Italic},
FontFace={li}{i}{Font=* Light Italic},
FontFace={i}{i}{Font=*  Italic},
FontFace={mi}{i}{Font=* Medium Italic},
FontFace={sbi}{i}{Font=* SemiBold Italic},
FontFace={bi}{i}{Font=* Bold Italic},
FontFace={ebi}{i}{Font=* ExtraBold Italic},
FontFace={xbi}{i}{Font=* Black Italic},
FontFace={ulsc}{s}{Font=* Thin,SmallCapsFont={* Thin},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={elsc}{s}{Font=* ExtraLight,SmallCapsFont={* ExtraLight},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={lsc}{s}{Font=* Light,SmallCapsFont={* Light},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={rsc}{s}{Font=* Regular,SmallCapsFont={* Regular},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={msc}{s}{Font=* Medium,SmallCapsFont={* Medium},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={sbsc}{s}{Font=* SemiBold,SmallCapsFont={* SemiBold},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={bsc}{s}{Font=* Bold,SmallCapsFont={* Bold},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={ebsc}{s}{Font=* ExtraBold,SmallCapsFont={* ExtraBold},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={xbsc}{s}{Font=* Black,SmallCapsFont={* Black},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={ulsci}{i}{Font=* Thin Italic,SmallCapsFont={* Thin Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={elsci}{i}{Font=* ExtraLight Italic,SmallCapsFont={* ExtraLight Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={lsci}{i}{Font=* Light Italic,SmallCapsFont={* Light Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={i}{i}{Font=*  Italic,SmallCapsFeatures={Letters=SmallCaps},},
FontFace={msci}{i}{Font=* Medium Italic,SmallCapsFont={* Medium Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={sbsci}{i}{Font=* SemiBold Italic,SmallCapsFont={* SemiBold Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={bsci}{i}{Font=* Bold Italic,SmallCapsFont={* Bold Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={ebsci}{i}{Font=* ExtraBold Italic,SmallCapsFont={* ExtraBold Italic},SmallCapsFeatures={Letters=SmallCaps},},
FontFace={xbsci}{i}{Font=* Black Italic,SmallCapsFont={* Black Italic},SmallCapsFeatures={Letters=SmallCaps},},
  ]

\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}
\DeclareRobustCommand{\elseries}{\fontseries{el}\selectfont}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}
\DeclareRobustCommand{\rseries}{\fontseries{r}\selectfont}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}
\DeclareRobustCommand{\sbseries}{\fontseries{sb}\selectfont}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}
\DeclareRobustCommand{\ebseries}{\fontseries{eb}\selectfont}
\DeclareRobustCommand{\xbseries}{\fontseries{xb}\selectfont}
\DeclareRobustCommand{\uliseries}{\fontseries{uli}\fontshape{i}\selectfont}
\DeclareRobustCommand{\eliseries}{\fontseries{eli}\fontshape{i}\selectfont}
\DeclareRobustCommand{\liseries}{\fontseries{li}\fontshape{i}\selectfont}
\DeclareRobustCommand{\iseries}{\fontseries{i}\fontshape{i}\selectfont}
\DeclareRobustCommand{\miseries}{\fontseries{mi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\sbiseries}{\fontseries{sbi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\biseries}{\fontseries{bi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\ebiseries}{\fontseries{ebi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\xbiseries}{\fontseries{xbi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\ulscseries}{\fontseries{ulsc}\scshape\selectfont}
\DeclareRobustCommand{\elscseries}{\fontseries{elsc}\scshape\selectfont}
\DeclareRobustCommand{\lscseries}{\fontseries{lsc}\scshape\selectfont}
\DeclareRobustCommand{\rscseries}{\fontseries{rsc}\scshape\selectfont}
\DeclareRobustCommand{\mscseries}{\fontseries{msc}\scshape\selectfont}
\DeclareRobustCommand{\sbscseries}{\fontseries{sbsc}\scshape\selectfont}
\DeclareRobustCommand{\bscseries}{\fontseries{bsc}\scshape\selectfont}
\DeclareRobustCommand{\ebscseries}{\fontseries{ebsc}\scshape\selectfont}
\DeclareRobustCommand{\xbscseries}{\fontseries{xbsc}\scshape\selectfont}
\DeclareRobustCommand{\ulsciseries}{\fontseries{ulsci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\elsciseries}{\fontseries{elsci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\lsciseries}{\fontseries{lsci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\itseries}{\fontseries{i}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\msciseries}{\fontseries{msci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\sbsciseries}{\fontseries{sbsci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\bsciseries}{\fontseries{bsci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\ebsciseries}{\fontseries{ebsci}\fontshape{i}\scshape\selectfont}
\DeclareRobustCommand{\xbsciseries}{\fontseries{xbsci}\fontshape{i}\scshape\selectfont}




\DeclareTextFontCommand{\textul}{\ulseries}
\DeclareTextFontCommand{\textel}{\elseries}
\DeclareTextFontCommand{\textl}{\lseries}
\DeclareTextFontCommand{\textr}{\rseries}
\DeclareTextFontCommand{\textm}{\mseries}
\DeclareTextFontCommand{\textsb}{\sbseries}
\DeclareTextFontCommand{\textb}{\bseries}
\DeclareTextFontCommand{\texteb}{\ebseries}
\DeclareTextFontCommand{\textxb}{\xbseries}
\DeclareTextFontCommand{\textuli}{\uliseries}
\DeclareTextFontCommand{\texteli}{\eliseries}
\DeclareTextFontCommand{\textli}{\liseries}
\DeclareTextFontCommand{\texti}{\iseries}
\DeclareTextFontCommand{\textmi}{\miseries}
\DeclareTextFontCommand{\textsbi}{\sbiseries}
\DeclareTextFontCommand{\textbi}{\biseries}
\DeclareTextFontCommand{\textebi}{\ebiseries}
\DeclareTextFontCommand{\textxbi}{\xbiseries}
\DeclareTextFontCommand{\textulsc}{\ulscseries}
\DeclareTextFontCommand{\textelsc}{\elscseries}
\DeclareTextFontCommand{\textlsc}{\lscseries}
\DeclareTextFontCommand{\textrsc}{\rscseries}
\DeclareTextFontCommand{\textmsc}{\mscseries}
\DeclareTextFontCommand{\textsbsc}{\sbscseries}
\DeclareTextFontCommand{\textbsc}{\bscseries}
\DeclareTextFontCommand{\textebsc}{\ebscseries}
\DeclareTextFontCommand{\textxbsc}{\xbscseries}
\DeclareTextFontCommand{\textulsci}{\ulsciseries}
\DeclareTextFontCommand{\textelsci}{\elsciseries}
\DeclareTextFontCommand{\textlsci}{\lsciseries}
\DeclareTextFontCommand{\textit}{\itseries}
\DeclareTextFontCommand{\textmsci}{\msciseries}
\DeclareTextFontCommand{\textsbsci}{\sbsciseries}
\DeclareTextFontCommand{\textbsci}{\bsciseries}
\DeclareTextFontCommand{\textebsci}{\ebsciseries}
\DeclareTextFontCommand{\textxbsci}{\xbsciseries}



\begin{document}
\center
\section*{Exo}
\rmfamily

\begin{tabular}{c}Normal\\ \hline\ \\\textul{Abc Thin} {\ulseries Thin}\\
\textel{Abc ExtraLight} {\elseries ExtraLight}\\
\textl{Abc Light} {\lseries Light}\\
\textr{Abc Regular} {\rseries Regular}\\
\textm{Abc Medium} {\mseries Medium}\\
\textsb{Abc SemiBold} {\sbseries SemiBold}\\
\textb{Abc Bold} {\bseries Bold}\\
\texteb{Abc ExtraBold} {\ebseries ExtraBold}\\
\textxb{Abc Black} {\xbseries Black}\\\end{tabular}
\begin{tabular}{c}Normal Italic\\ \hline\ \\\textuli{Abc Thin} {\uliseries Thin}\\
\texteli{Abc ExtraLight} {\eliseries ExtraLight}\\
\textli{Abc Light} {\liseries Light}\\
\texti{Abc Regular} {\iseries Regular}\\
\textmi{Abc Medium} {\miseries Medium}\\
\textsbi{Abc SemiBold} {\sbiseries SemiBold}\\
\textbi{Abc Bold} {\biseries Bold}\\
\textebi{Abc ExtraBold} {\ebiseries ExtraBold}\\
\textxbi{Abc Black} {\xbiseries Black}\\\end{tabular}

\vskip1.5em
\begin{tabular}{c}Normal Small Caps\\ \hline\ \\\textulsc{Abc Thin} {\ulscseries Thin}\\
\textelsc{Abc ExtraLight} {\elscseries ExtraLight}\\
\textlsc{Abc Light} {\lscseries Light}\\
\textrsc{Abc Regular} {\rscseries Regular}\\
\textmsc{Abc Medium} {\mscseries Medium}\\
\textsbsc{Abc SemiBold} {\sbscseries SemiBold}\\
\textbsc{Abc Bold} {\bscseries Bold}\\
\textebsc{Abc ExtraBold} {\ebscseries ExtraBold}\\
\textxbsc{Abc Black} {\xbscseries Black}\\\end{tabular}
\begin{tabular}{c}Normal Italic Small Caps\\ \hline\ \\\textulsci{Abc Thin} {\ulsciseries Thin}\\
\textelsci{Abc ExtraLight} {\elsciseries ExtraLight}\\
\textlsci{Abc Light} {\lsciseries Light}\\
\textit{Abc Regular} {\itseries Regular}\\
\textmsci{Abc Medium} {\msciseries Medium}\\
\textsbsci{Abc SemiBold} {\sbsciseries SemiBold}\\
\textbsci{Abc Bold} {\bsciseries Bold}\\
\textebsci{Abc ExtraBold} {\ebsciseries ExtraBold}\\
\textxbsci{Abc Black} {\xbsciseries Black}\\\end{tabular}

\end{document}

有一个 Exo 2:它里面有西里尔字母,但没有小写字母。

Exo 和 Exo 2 均采用 Google 字体。

平均能量损失

 \documentclass[12pt]{article}
\usepackage{xcolor}
\pagecolor{red!3}

\usepackage{fontspec}

\setromanfont{Exo 2}[
FontFace={ul}{n}{Font=* Thin},
FontFace={el}{n}{Font=* Extra Light},
FontFace={l}{n}{Font=* Light},
FontFace={r}{n}{Font=*},
FontFace={m}{n}{Font=* Medium},
FontFace={sb}{n}{Font=* Semi Bold},
FontFace={b}{n}{Font=* Bold},
FontFace={eb}{n}{Font=* Extra Bold},
FontFace={xb}{n}{Font=* Black},
FontFace={uli}{i}{Font=* Thin Italic},
FontFace={eli}{i}{Font=* Extra Light Italic},
FontFace={li}{i}{Font=* Light Italic},
FontFace={i}{i}{Font=* Italic},
FontFace={mi}{i}{Font=* Medium Italic},
FontFace={sbi}{i}{Font=* Semi Bold Italic},
FontFace={bi}{i}{Font=* Bold Italic},
FontFace={ebi}{i}{Font=* Extra Bold Italic},
FontFace={xbi}{i}{Font=* Black Italic},
  ]

\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}
\DeclareRobustCommand{\elseries}{\fontseries{el}\selectfont}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}
\DeclareRobustCommand{\rseries}{\fontseries{r}\selectfont}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}
\DeclareRobustCommand{\sbseries}{\fontseries{sb}\selectfont}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}
\DeclareRobustCommand{\ebseries}{\fontseries{eb}\selectfont}
\DeclareRobustCommand{\xbseries}{\fontseries{xb}\selectfont}
\DeclareRobustCommand{\uliseries}{\fontseries{uli}\fontshape{i}\selectfont}
\DeclareRobustCommand{\eliseries}{\fontseries{eli}\fontshape{i}\selectfont}
\DeclareRobustCommand{\liseries}{\fontseries{li}\fontshape{i}\selectfont}
\DeclareRobustCommand{\iseries}{\fontseries{i}\fontshape{i}\selectfont}
\DeclareRobustCommand{\miseries}{\fontseries{mi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\sbiseries}{\fontseries{sbi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\biseries}{\fontseries{bi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\ebiseries}{\fontseries{ebi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\xbiseries}{\fontseries{xbi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\ulscseries}{\fontseries{ulsc}\scshape\selectfont}
\DeclareRobustCommand{\elscseries}{\fontseries{elsc}\scshape\selectfont}
\DeclareRobustCommand{\lscseries}{\fontseries{lsc}\scshape\selectfont}
\DeclareRobustCommand{\rscseries}{\fontseries{rsc}\scshape\selectfont}
\DeclareRobustCommand{\mscseries}{\fontseries{msc}\scshape\selectfont}
\DeclareRobustCommand{\sbscseries}{\fontseries{sbsc}\scshape\selectfont}
\DeclareRobustCommand{\bscseries}{\fontseries{bsc}\scshape\selectfont}
\DeclareRobustCommand{\ebscseries}{\fontseries{ebsc}\scshape\selectfont}
\DeclareRobustCommand{\xbscseries}{\fontseries{xbsc}\scshape\selectfont}




\DeclareTextFontCommand{\textul}{\ulseries}
\DeclareTextFontCommand{\textel}{\elseries}
\DeclareTextFontCommand{\textl}{\lseries}
\DeclareTextFontCommand{\textr}{\rseries}
\DeclareTextFontCommand{\textm}{\mseries}
\DeclareTextFontCommand{\textsb}{\sbseries}
\DeclareTextFontCommand{\textb}{\bseries}
\DeclareTextFontCommand{\texteb}{\ebseries}
\DeclareTextFontCommand{\textxb}{\xbseries}
\DeclareTextFontCommand{\textuli}{\uliseries}
\DeclareTextFontCommand{\texteli}{\eliseries}
\DeclareTextFontCommand{\textli}{\liseries}
\DeclareTextFontCommand{\texti}{\iseries}
\DeclareTextFontCommand{\textmi}{\miseries}
\DeclareTextFontCommand{\textsbi}{\sbiseries}
\DeclareTextFontCommand{\textbi}{\biseries}
\DeclareTextFontCommand{\textebi}{\ebiseries}
\DeclareTextFontCommand{\textxbi}{\xbiseries}



\begin{document}
\center
\section*{Exo 2}
\rmfamily

\begin{tabular}{c}Normal\\ \hline\ \\\textul{Abc Thin} {\ulseries Thin}\\
\textel{Abc ExtraLight} {\elseries ExtraLight}\\
\textl{Abc Light} {\lseries Light}\\
\textr{Abc Regular} {\rseries Regular}\\
\textm{Abc Medium} {\mseries Medium}\\
\textsb{Abc SemiBold} {\sbseries SemiBold}\\
\textb{Abc Bold} {\bseries Bold}\\
\texteb{Abc ExtraBold} {\ebseries ExtraBold}\\
\textxb{Abc Black} {\xbseries Black}\\\end{tabular}
\begin{tabular}{c}Normal Italic\\ \hline\ \\\textuli{Abc Thin} {\uliseries Thin}\\
\texteli{Abc ExtraLight} {\eliseries ExtraLight}\\
\textli{Abc Light} {\liseries Light}\\
\texti{Abc Regular} {\iseries Regular}\\
\textmi{Abc Medium} {\miseries Medium}\\
\textsbi{Abc SemiBold} {\sbiseries SemiBold}\\
\textbi{Abc Bold} {\biseries Bold}\\
\textebi{Abc ExtraBold} {\ebiseries ExtraBold}\\
\textxbi{Abc Black} {\xbiseries Black}\\\end{tabular}


\vskip1.5em
\begin{tabular}{c}Normal\\ \hline\ \\\textul{Шрифт Любя, съешь} {\ulseries Полужирный}\\
\textel{Шрифт Любя, съешь} {\elseries Полужирный}\\
\textl{Шрифт Любя, съешь} {\lseries Полужирный}\\
\textr{Шрифт Любя, съешь} {\rseries Полужирный}\\
\textm{Шрифт Любя, съешь} {\mseries Полужирный}\\
\textsb{Шрифт Любя, съешь} {\sbseries Полужирный}\\
\textb{Шрифт Любя, съешь} {\bseries Полужирный}\\
\texteb{Шрифт Любя, съешь} {\ebseries Полужирный}\\
\textxb{Шрифт Любя, съешь} {\xbseries Полужирный}\\\end{tabular}
\begin{tabular}{c}Normal Italic\\ \hline\ \\\textuli{Шрифт Любя, съешь} {\uliseries Полужирный}\\
\texteli{Шрифт Любя, съешь} {\eliseries Полужирный}\\
\textli{Шрифт Любя, съешь} {\liseries Полужирный}\\
\texti{Шрифт Любя, съешь} {\iseries Полужирный}\\
\textmi{Шрифт Любя, съешь} {\miseries Полужирный}\\
\textsbi{Шрифт Любя, съешь} {\sbiseries Полужирный}\\
\textbi{Шрифт Любя, съешь} {\biseries Полужирный}\\
\textebi{Шрифт Любя, съешь} {\ebiseries Полужирный}\\
\textxbi{Шрифт Любя, съешь} {\xbiseries Полужирный}\\\end{tabular}


\end{document}

将两者合并为一个虚拟家庭是可能的。 外显子 2

答案2

Cicada 发布了关于如何更改系列的正确答案,该系列将宽度和重量结合在一起。(正如该答案中提到的,导致功能添加到的典型问题fontspec这里。)我将以不同的方式回答您的问题,使其不再重复:如何改变仅有的宽度,与重量无关。

在 NFSS 中

nfssext-cfr包裹(由我们自己的 CFR 编写)为此引入了一系列命令。它将标准 NFSS 命令(例如\bfseries,选择粗体和扩展)拆分为宽度命令(例如\cdwidth/,\textcd用于压缩宽度和不变粗细)和粗细命令(例如\sbweight/,\textsb用于半粗体粗细和不变宽度)。

对于任意字体,此功能并不适用。它被其他几个软件包用作构建块,例如cfr-lmventurisadf。您可能希望遵循其命名方案来编写新命令。

无法单独设置粗细和宽度的历史原因是,在上个世纪,TeX 需要与 MS-DOS 兼容。因此,文件名被限制为八个字符加上三个字符的扩展名。这导致采用了一种极其简洁的惯例,即字体的文件名由三到四个字母组成,表示字体系列,加上一到两个字母表示“系列”(粗细和宽度),一到两个字母表示“形状”(最常见的是“正常”或斜体)。很少有字体有额外的宽度。

在现代工具链中

在常规宽度和压缩宽度之间切换的最简单方法fontspec是将压缩版本的字体声明为不同的系列。您甚至可以\DeclareTextFontCommand{\textexoexp}{\exoexp}\textexoexp{expanded text}, 而不是{\exoexp expanded text}

但是,fontspec还支持为字体系列提供任意 NFSS 系列和形状的命令。我没有特定的商业字体可以测试,但你可以这样写:

\setsansfont{Latin Modern Sans}[
   FontFace = {sbc}{n}{lmsansdemicond10-regular.otf} ,
   FontFace = {sbc}{i}{lmsansdemicond10-oblique.otf} ]

\cdwidth为字体定义正确的系列后,您可以移植与中等效的代码nfssext-cfr。这会将当前宽度和粗细保存在字符串变量中(要正常工作,需要在当前组中覆盖变量或将其推送到堆栈上)。 编辑:或者,如果限制为标准名称,则可以使用宏\f@series。)并将请求的宽度与保存的权重相结合,这样就\sbweight\cdwidth\selectfont可以像 一样工作\fontseries{sbc}\selectfont。权重选择命令将对保存的宽度执行相同的操作。

有了像\sbweight和 这样的命令后,您就可以使用和\cdwidth创建其余命令。但是,编写和代码可能更简单,并且足以满足您的目的,这些代码可以在局部变量中保存和恢复先前的宽度和权重设置。\DeclareTextFontCommand{\textcd}{\cdwidth}\DeclareTextFontCommand{\textsb}{\sbweight}\textcd\textsb

相关内容