siunitx (v3.0.33) 带有文本模式下的字体匹配和单位限定符

siunitx (v3.0.33) 带有文本模式下的字体匹配和单位限定符

尝试使以下操作生效:

\documentclass{scrbook}

\usepackage[x11names]{xcolor}

\usepackage{unicode-math}

\setmainfont[%
    Numbers=Lowercase,% Hanging/OldStyle numbers through Lowercase numbers
    Color=Orange4,% Toggle color for debugging (should be xcolor name)
]{TeX Gyre Pagella}% Load existing font, see also https://tex.stackexchange.com/a/351100/120853

\setmathfont[%
    Color=Green4,% Toggle color for debugging (should be xcolor name)
]{TeX Gyre Pagella Math}% Load existing font, see also https://tex.stackexchange.com/a/351100/120853

\newfontfamily{\unitnumberfont}[
    Numbers=Uppercase,% Lining numbers (as opposed to OldStyle) for quantities
    Color=Blue4,% Toggle color for debugging (should be xcolor name)
]{TeX Gyre Pagella}% Load existing font, see also https://tex.stackexchange.com/a/351100/120853

\usepackage{siunitx}% Typesetting physical units correctly
    \sisetup{%
        % For siunitx v3, the following block replaces what used to be
        % `detect-all` (removed in that release, see
        % https://github.com/josephwright/siunitx/blob/main/CHANGELOG.md#v300 ).
        % It allows the `siunitx` output to match surrounding text/math (italics/bold/...,
        % roman/sans/... etc. as much as possible)
        % mode=match,%
        propagate-math-font=true,
        reset-math-version=false,
        reset-text-family=false,
        reset-text-series=false,
        reset-text-shape=false,% Not part of official fix, but still added (see https://collaborating.tuhh.de/alex/latex-git-cookbook/-/issues/8)
        text-family-to-math=true,
        text-series-to-math=true,
        %
        % Requires siunitx v3+, see also https://tex.stackexchange.com/a/468031/120853,
        % https://github.com/josephwright/siunitx/issues/532 :
        text-font-command=\unitnumberfont,
    }%

    \DeclareSIUnit{\watthour}{Wh}%

    \DeclareSIQualifier{\testingqual}{test}

\begin{document}
Rest of document has hanging numerals (123456789) thus use \texttt{unitnumberfont} as a solution, see https://tex.stackexchange.com/questions/468027/siunitx-and-xelatex-with-oldstyle-in-text-but-lining-in-math .

\newcommand*{\testunit}{\mega\watthour\per\meter\cubed}
% \renewcommand*{\testunit}{\mega\watthour\testingqual\per\meter\cubed}% Toggle this line on and off

\newcommand{\testtext}{%
    Hello \qty[per-mode=fraction]{123.456}{\testunit} World

    \textbf{Hello \qty[per-mode=fraction]{123.456}{\testunit} World}

    \textit{Hello \qty[per-mode=fraction]{123.456}{\testunit} World}

    \textit{\textbf{Hello \qty[per-mode=fraction]{123.456}{\testunit} World}}
}

\subsection*{Text mode}

Has matching capability, but \texttt{SIQualifier} breaks.

\sisetup{mode=text}

\testtext{}% This line errors out if `\testunit` contains `\testingqual`

\subsection*{Math mode}

Loses matching capability, but \texttt{SIQualifier} works.

\sisetup{mode=math}

\testtext{}
\end{document}

产生(相关主题):

在此处输入图片描述

siunitx匹配周围的字体是所需的行为,并且在text模式内工作(有关的)。


然而,包括\testingqual通过

\DeclareSIQualifier{\testingqual}{test}

单位(线renewcommand)内断电text方式:

! LaTeX Error: \mathrm allowed only in math mode.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.68 \testtext
            {}% This line errors out if `\testunit` contains `\testingqual`
? 

math模式继续工作(text模式行被注释掉以便编译):

在此处输入图片描述


我可以确认这v3.0.33,因为这是我用来编译上述代码片段的版本,而该项目的使用仍然基于v3.0.32(通过 Docker 编译,镜像alexpovel/latex)它在那里工作。

整个模式切换和匹配对我来说有点混乱,所以我自己无法解决这个问题。

答案1

先前的变更对某个内部部分存在疏忽。您应该添加

\ExplSyntaxOn
\cs_gset_protected:Npn \__siunitx_print_text_scripts_one:Nn #1#2
  {
    \group_begin:
      \tl_set:Nn \l__siunitx_print_tmp_tl {#2}
      \__siunitx_print_text_replace:N \l__siunitx_print_tmp_tl
      \__siunitx_print_replace_font:N \l__siunitx_print_tmp_tl
    \exp_args:NNV \group_end:
    #1 \l__siunitx_print_tmp_tl
  }
\ExplSyntaxOff

加载后siunitx直到 CTAN 得到修复。

相关内容