![使用 siunitx、fourier 和 amsmath 问题进行大胆数学运算](https://linux22.com/image/331111/%E4%BD%BF%E7%94%A8%20siunitx%E3%80%81fourier%20%E5%92%8C%20amsmath%20%E9%97%AE%E9%A2%98%E8%BF%9B%E8%A1%8C%E5%A4%A7%E8%83%86%E6%95%B0%E5%AD%A6%E8%BF%90%E7%AE%97.png)
通过这种配置,除了使用之外,我无法使用粗体 siunitx \pmb
,但会产生丑陋的副作用:
\documentclass[margin=5pt]{standalone}
\usepackage{fourier}
\usepackage{fontspec}
\setmainfont{Erewhon}[
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
SlantedFont=*-RegularSlanted,
BoldSlantedFont=*-BoldSlanted,
SmallCapsFont=*-SmallCaps,
SmallCapsFont=*-Regular,
SmallCapsFeatures={Letters=SmallCaps}
]
\setsansfont{texgyreheros}[
Scale=MatchLowercase,% or MatchUppercase
Extension=.otf,
UprightFont=*-regular,
ItalicFont=*-italic,
BoldFont=*-bold,
BoldItalicFont=*-bolditalic,
]
\usepackage{amsmath,amsfonts,amssymb,mathrsfs}
\usepackage{bm} % Bold math with \bm{}
\RequirePackage{siunitx} % \num{} ...
\sisetup{%
unit-mode = text,%
% detect-weight=true,
% detect-family=true,
% detect-inline-weight=math,
locale=FR,%
%detect-all,% Problème avec euro, inutile
inter-unit-product = \ensuremath{{}\cdot{}},%
group-minimum-digits=4,
text-angstrom={Å},math-angstrom={\text{Å}}
}
\begin{document}
$\pmb{\SI{2109}{kg}}$
\end{document}
答案1
使用[detect-all]
选项siunitx
然后
\let\svSI\SI
\renewcommand\SI[2][]{\bgroup\edef\tmpA{#1}\edef\tmpB{#2}\SIx}
\newcommand\SIx[2][]{%
\textrm{\bfseries\boldmath\expandafter\svSI\expandafter[\tmpA]{\tmpB}[#1]{#2}}\egroup}
在序言中。已编辑以自动对粗体进行分组限制。已编辑以在数学和文本模式下工作。下面的 MWE 演示了修订后的所有可选参数均能\SI
正常工作。
\documentclass[margin=5pt]{article}
\usepackage{fourier}
\usepackage{fontspec}
\setmainfont{Erewhon}[
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
SlantedFont=*-RegularSlanted,
BoldSlantedFont=*-BoldSlanted,
SmallCapsFont=*-SmallCaps,
SmallCapsFont=*-Regular,
SmallCapsFeatures={Letters=SmallCaps}
]
\setsansfont{texgyreheros}[
Scale=MatchLowercase,% or MatchUppercase
Extension=.otf,
UprightFont=*-regular,
ItalicFont=*-italic,
BoldFont=*-bold,
BoldItalicFont=*-bolditalic,
]
\usepackage{amsmath,amsfonts,amssymb,mathrsfs}
\usepackage{bm} % Bold math with \bm{}
\RequirePackage[detect-all]{siunitx} % \num{} ...
\sisetup{%
unit-mode = text,%
% detect-weight=true,
% detect-family=true,
% detect-inline-weight=math,
locale=FR,%
%detect-all,% Problème avec euro, inutile
inter-unit-product = \ensuremath{{}\cdot{}},%
group-minimum-digits=4,
text-angstrom={Å},math-angstrom={\text{Å}}
}
\let\svSI\SI
\renewcommand\SI[2][]{\bgroup\edef\tmpA{#1}\edef\tmpB{#2}\SIx}
\newcommand\SIx[2][]{%
\textrm{\bfseries\boldmath\expandafter\svSI\expandafter[\tmpA]{\tmpB}[#1]{#2}}\egroup}
\begin{document}
Math mode: $\SI{2109}{kg}$
Text mode: \SI[per-mode=symbol]{2109}{\kg \per \s} not bold $xy$
Text mode: \SI[per-mode=fraction]{2109}[\$]{\kg \per \s} not bold $xy$
\end{document}