Post by Matthias PospiechUnfortunately it does not. First, the optional parameter of units which
is fixed in your \SI causes an error. This can be rewritten from
\unit[123]{...} to 123\,\unit{...}.
It's been a while since I've used 'units', and my previous post is
mainly proof-of-principle. The optional argument is easy enough to handle.
Post by Matthias PospiechSecond, the unitfrac should be a nicefrac. Is this possible with
mode=math (which was the original question of the whole thread)?
In your question you've used \sfrac, which is not-quite the same as
\nicefrac (see the xfrac documentation). I've assumed in my updated
example that I can use \sfrac; \nicefrac can be done, but needs a
slightly different approach.
Post by Matthias PospiechAnd last, and most important, it switches to serif fonts in a sans serif
math environment. With the units package commands the sans serif fonts
are used, with your code it switches to \rmfamily.
That is deliberate: NIST, ISO, etc., say that units should always be
typeset in roman. However, there is an option to sort this:
'detect-family'. You can also 'detect-weight' if you want. (I note that
units does different things in math and text mode. If you really need
this I can work a bit more more on the emulation: for the moment I've
assumed this is not needed.)
Post by Matthias PospiechIf (more or less) compatible environments could be achieved, I would
introduce siunitx in my next release of my template code. Currently I
require a solution only for my phd-thesis.
With the provisos above, would the following work?
\documentclass{article}
\usepackage{siunitx,xfrac}
% Emulate units package, sort of
\sisetup{detect-family,detect-weight,mode = math}
\NewDocumentCommand\unit{om}{%
\IfNoValueTF{#1}
{\si{#2}}
{\SI{#1}{#2}}%
}
\NewDocumentCommand\unitfrac{omm}{%
\IfNoValueTF{#1}
{\si{\sfrac{#2}{#3}}}
{\SI{#1}{\sfrac{#2}{#3}}}%
}
\begin{document}
\unit{km/s} \unit{\frac{km}{s}} \unitfrac{km}{s}
\unit[10]{km/s} \unitfrac[10]{km}{s} \unit{\micro m}
{
\sffamily
\unit{km/s} \unit{\frac{km}{s}} \unitfrac{km}{s}
\unit[10]{km/s} \unitfrac[10]{km}{s} \unit{\micro m}
}
{
\bfseries
\unit{km/s} \unit{\frac{km}{s}} \unitfrac{km}{s}
\unit[10]{km/s} \unitfrac[10]{km}{s} \unit{\micro m}
}
\end{document}
(This is not 100% emulation of units: I have my notes on how to do this
from v1 of siunitx, which I can check if needed. Note that I've used the
\NewDocumentCommand macro rather than \newcommand, which is possible as
siunitx loads xparse. You could use \newcommand if you prefer, and test
for an empty first argument by hand.)
--
Joseph Wright