% Rolf Niepraschk, PTB, Rolf.Niepraschk@ptb.de

\ProvidesPackage{siunitx-PTB}[2017/12/01 v0.1b Addionions to `siunitx'' (PTB/RN)]

\RequirePackage{amsmath,siunitx}

\providecommand*\vl@tempa{}
\providecommand*\vl@tempb{}
\providecommand*\vl@tempc{}
\providecommand*\vl@tempd{}
\providecommand*\vl@tempe{}

\DeclareSIUnit\torr{torr}
\DeclareSIUnit\mbar{mbar}

%%%\AtBeginDocument{%
\sisetup{%
  %%%,exponent-product = \ensuremath { \cdot }     % wird per "locale" gesetzt
  %%%,inter-unit-product = \ensuremath{{}\cdot{}}  % wird per "locale" gesetzt
  %,output-exponent-marker=\text{E}
  ,table-alignment = center
  %%%,table-number-alignment = center
  %%%,table-text-alignment = center
  ,table-align-exponent = false
  ,table-parse-only = true % ?!
  %,parse-numbers = false
  ,table-format = +1.3e+1
  %%%,table-figures-integer = 1
  %%%,table-figures-decimal = 3
  %%%,table-figures-exponent = 2
  %%%,input-uncertainty-signs = +-
  %%%,output-open-uncertainty =
  %%%,output-close-uncertainty =
  %%,separate-uncertainty = true
  ,bracket-numbers = true
  %,per-mode = symbol
  ,per-mode = reciprocal
  ,mode = text % !!!
  ,tight-spacing = false
  ,separate-uncertainty
  %%%,inter-unit-product = \ensuremath{{}\cdot{}}
}%
%%%}
\AtBeginDocument{
  \sisetup{%
    ,inter-unit-product=\ensuremath{{}\cdot{}}
  }%
}

\RequirePackage{trimspaces}

\let\ke@orig@SI=\SI
\renewcommand*\SI[2][]{% tolerant gegenüber "?" statt Zahl
  \def\vl@tempa{#1}%
  \edef\vl@tempb{\trim@spaces{#2}}%
  \ks@SI@i
}
\newcommand*\ks@SI@i[2][]{%
  \def\vl@tempc{?}%
  \ifx\vl@tempb\vl@tempc
    \ensuremath{\textbf{??}}\,\si[#1]{#2}%
  \else
    \edef\vl@tempe{\noexpand\ke@orig@SI[\vl@tempa]{\vl@tempb}[#1]{#2}}%
    \vl@tempe
  \fi
}
\let\ke@orig@num=\num
\renewcommand*\num[1]{% tolerant gegenüber "?" statt Zahl
  \edef\vl@tempb{\trim@spaces{#1}}%
  \def\vl@tempc{?}%
  \ifx\vl@tempb\vl@tempc
    \ensuremath{\textbf{??}}%
  \else
    \ke@orig@num{#1}%
  \fi
}

\RequirePackage{iflang}
\AtBeginDocument{%
  \IfLanguageName{ngerman}{
    \sisetup{locale=DE}
  }{%
    \sisetup{locale=UK}
  }
}

\endinput

