`siunitx` 分数模式中的下标

`siunitx` 分数模式中的下标

我想稍微自动化一下 SI 单位。不幸的是,如果我添加下标文本,则无法获得所需的结果。我尝试了多个版本和\text类似的函数。如何使用 显示带下标的分数siunitx

\documentclass[
    fontsize=12pt,
    paper=a4,
    oneside,
    leqno
    ]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[
    fleqn   
    ]{amsmath}

\usepackage{siunitx}
\sisetup{
    locale = DE,
    per-mode=fraction,
    quotient-mode=fraction,
    fraction-function=\tfrac
}


\NewDocumentCommand\DeclareNewQuantity{mmm}{%
    \DeclareSIUnit{#2}{#3}%
    \DeclareDocumentCommand{#1}{O{}m}{\SI[##1]{##2}{#2}}%
}

\DeclareNewQuantity
    \DoesWhatIWant
    \doesWhatIWant
    {\kg\per\kg}
\DeclareNewQuantity
    \DoesNotWhatIWant
    \doesNotWhatIWant
    {\kg_{H2}\per\kg_{FeTi}}

\begin{document}

$\DoesWhatIWant{1,2345}$

$\DoesNotWhatIWant{1,2345}$

\end{document}

结果如下:

在此处输入图片描述

第二个应该看起来像第一个输出。

答案1

贴花\kg_{H2}\kg_{FeTi}作为新单位\DeclareSIUnit首先使用。

\DeclareSIUnit\kgh{\kg_{H2}}
\DeclareSIUnit\kgfe{\kg_{FeTi}}

在此处输入图片描述

\documentclass[
    fontsize=12pt,
    paper=a4,
    oneside,
    leqno
    ]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[
    fleqn   
    ]{amsmath}

\usepackage{siunitx}
\sisetup{
    locale = DE,
    per-mode=fraction,
    quotient-mode=fraction,
    fraction-function=\tfrac
}

\DeclareSIUnit\kgh{\kg_{H2}}
\DeclareSIUnit\kgfe{\kg_{FeTi}}

\NewDocumentCommand\DeclareNewQuantity{mmm}{%
    \DeclareSIUnit{#2}{#3}%
    \DeclareDocumentCommand{#1}{O{}m}{\SI[##1]{##2}{#2}}%
}

\DeclareNewQuantity
    \DoesWhatIWant
    \doesWhatIWant
    {\kg\per\kg}
\DeclareNewQuantity
    \DoesNotWhatIWant
    \doesNotWhatIWant
    {\kgh\per\kgfe}

\begin{document}

$\DoesWhatIWant{1,2345}$

$\DoesNotWhatIWant{1,2345}$
\end{document}

相关内容