2

I would like to automate my SI Units a bit. Unfortunately I'm not getting the desired result if I add subscript text. I tried multiple versions with \text and similiar functions. How can I display a fraction with subscripts with 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}

The result looks like this:

enter image description here

The second should look like the first output.

3

Decalre \kg_{H2} and \kg_{FeTi} as new units with \DeclareSIUnit first.

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

enter image description here

\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}
| improve this answer | |
  • Perfect :) Thank you! – Kilian Helfenbein Oct 29 '19 at 9:45
  • Very ugly this answer wih 0 score. My sincere compliments. – Sebastiano Oct 29 '19 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.