重新定义某些字体的默认字体粗细并保持与 siunitx 的兼容性

重新定义某些字体的默认字体粗细并保持与 siunitx 的兼容性

字体打开 Sans提供各种字体粗细,例如,细体、浓缩细体、常规体、半粗体、粗体特粗体

\mdseries“Regular”和“Bold”自然是和的默认值bfseries,但我更喜欢“Light”和“Semibold”作为默认值。

我怎样才能重新定义默认字体粗细,理解他们并且可以吗detect-all

\documentclass{beamer}

\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage[default]{opensans}
\usepackage{siunitx}

\begin{document}

\sisetup{detect-all}

Regular numbers and unit: \SI{42}{\micro\meter}\par
\textit{Regular italic numbers and unit: \SI{42}{\micro\meter}}\par
\textbf{Bold numbers and unit: \SI{42}{\micro\meter}}\par
\textbf{\textit{Bold italic numbers and unit: \SI{42}{\micro\meter}}}\par

\medskip
But I actually want:
\smallskip

\sisetup{detect-none}

{\fontfamily{fos}\fontseries{l}\fontshape{n}\selectfont%
Regular numbers and unit: \SI{42}{\micro\meter}\par
\fontfamily{fos}\fontseries{l}\fontshape{it}\selectfont%
Regular italic numbers and unit: \SI{42}{\micro\meter}\par
\fontfamily{fos}\fontseries{sb}\fontshape{n}\selectfont%
Bold numbers and unit: \SI{42}{\micro\meter}\par
\fontfamily{fos}\fontseries{sb}\fontshape{it}\selectfont%
Bold italic numbers and unit: \SI{42}{\micro\meter}\par
}

\medskip
But \emph{detect-all} of siunitx fails and I'd like to use the commands above.

\end{document}

我想创建一种由我想要使用的 Open Sans 子字体组成的新字体:

\DeclareFontFamily{T1}{fosn}{}
\DeclareFontShape{T1}{fosn}{m}{n}{<-> ssub * fos/l/n }{}
\DeclareFontShape{T1}{fosn}{b}{n}{<-> ssub * fos/sb/n }{}
\DeclareFontShape{T1}{fosn}{m}{it}{<-> ssub * fos/l/it }{}
\DeclareFontShape{T1}{fosn}{b}{it}{<-> ssub * fos/sb/it}{}

\renewcommand{\sfdefault}{fosn}
\renewcommand{\rmdefault}{fosn}
\renewcommand{\familydefault}{\rmdefault}
\renewcommand{\mddefault}{m}
\renewcommand{\bfdefault}{b}
\renewcommand{\seriesdefault}{\mddefault}

看起来效果已经很好了,但希腊字母仍然失败。有什么提示吗?

在此处输入图片描述

我正在明确寻找非字体规范的解决方案。

答案1

我终于找到了可以做我想做的事情的方法——重要的是在使用 fontenc 时保持顺序“LGR, T1”。还要感谢 egreg,他的回答在这里

\documentclass{beamer}

\usepackage[utf8]{luainputenc}
\usepackage[LGR, T1]{fontenc}
\usepackage{amsmath}
\usepackage{sansmathfonts}
\usepackage[default]{opensans}
\usepackage{siunitx}

\DeclareFontFamily{T1}{fosn}{}
\DeclareFontShape{T1}{fosn}{m}{n}{<-> ssub * fos/l/n }{}
\DeclareFontShape{T1}{fosn}{b}{n}{<-> ssub * fos/sb/n }{}
\DeclareFontShape{T1}{fosn}{m}{it}{<-> ssub * fos/l/it }{}
\DeclareFontShape{T1}{fosn}{b}{it}{<-> ssub * fos/sb/it}{}

\DeclareFontFamily{LGR}{fosgreek}{}
\DeclareFontShape{LGR}{fosgreek}{m}{n}{<-> ssub * fos/l/n }{}
\DeclareFontShape{LGR}{fosgreek}{b}{n}{<-> ssub * fos/sb/n }{}
\DeclareFontShape{LGR}{fosgreek}{m}{it}{<-> ssub * fos/l/it }{}
\DeclareFontShape{LGR}{fosgreek}{b}{it}{<-> ssub * fos/sb/it}{}

\renewcommand{\sfdefault}{fosn}
\renewcommand{\rmdefault}{fosn}
\renewcommand{\familydefault}{\rmdefault}
\renewcommand{\mddefault}{m}
\renewcommand{\bfdefault}{b}
\renewcommand{\seriesdefault}{\mddefault}

\DeclareFontEncoding{LGR}{}{}
\DeclareSymbolFont{osgreek}{LGR}{fos}{l}{n}
\SetSymbolFont{osgreek}{bold}{LGR}{fos}{sb}{n}
\DeclareMathSymbol{\upmu}{\mathord}{osgreek}{`m}

\DeclareSymbolFont{osgreekit}{LGR}{fos}{l}{it}
\SetSymbolFont{osgreekit}{bold}{LGR}{fos}{sb}{it}
\DeclareMathSymbol{\mu}{\mathord}{osgreekit}{`m}

\makeatletter
\DeclareRobustCommand{\textmu}{{\usefont{LGR}{fosgreek}{\f@series}{\f@shape}\symbol{\string"6D}}}
\DeclareRobustCommand{\textohm}{{\usefont{LGR}{fosgreek}{\f@series}{\f@shape}\symbol{\string"5F}}}
\makeatother
\sisetup{math-micro=\upmu,text-micro=\textmu,
         math-ohm=\upOmega,text-ohm=\textohm}

\usepackage{mathastext}

\begin{document}

\sisetup{detect-all}

Regular numbers and unit: \SI{42}{\micro\meter}\par
\textit{Regular italic numbers and unit: \SI{42}{\micro\meter}}\par
\textbf{Bold numbers and unit: \SI{42}{\micro\meter}}\par
\textbf{\textit{Bold italic numbers and unit: \SI{42}{\micro\meter}}}\par

\[
\int \sum X_\mathrm{\mu\upmu}\mu\upmu\mathrm{\mu\upmu}A + 2 = \SI{42}{\micro\meter\ampere\gram}
\]

\end{document}

在此处输入图片描述

相关内容