Discussion:
siunitx: nicefrac never applied
(too old to reply)
Matthias Pospiech
2011-02-06 09:21:06 UTC
Permalink
The following code produces a µm/s instead of the nicefrac{µm}{s}
version. siunitx Version is 2.1i (texlive latest)

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}

%\usepackage{xfrac} % has no effect
\usepackage{siunitx}
\sisetup{%
mode=text,
exponent-product = \cdot,
number-unit-separator=\text{\,}
}

\begin{document}
$\SI[quotient-mode=fraction, fraction-function=\sfrac]{100}{\micro m/s}$
\end{document}

Am I doing something wrong?
Besides that, the code length is much too long. It might be usefull to
provide a shorter version.
Joseph Wright
2011-02-06 09:46:08 UTC
Permalink
Post by Matthias Pospiech
The following code produces a µm/s instead of the nicefrac{µm}{s}
version. siunitx Version is 2.1i (texlive latest)
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
%\usepackage{xfrac} % has no effect
\usepackage{siunitx}
\sisetup{%
mode=text,
exponent-product = \cdot,
number-unit-separator=\text{\,}
}
\begin{document}
$\SI[quotient-mode=fraction, fraction-function=\sfrac]{100}{\micro m/s}$
\end{document}
Am I doing something wrong?
One or two things :-)

First, you are using literal input in your unit. So it will only ever be
printed 'as is'. You need to use macro units, and so in my example I've
loaded the abbreviated units so I can use '\um\per\s' rather than the
full '\micro\metre\per\second'.

Secondly, the option which sets how \per is handled is called 'per-mode'
not 'quotient-mode' (which is used for quotients in numbers). So an
example which does work is:

\documentclass{article}
\usepackage{fixltx2e,siunitx,xfrac}
\sisetup{
fraction-function = \sfrac ,
load-configurations = abbreviations ,
per-mode = fraction ,
}
\begin{document}
\( \SI{100}{\um\per\s} \)
\end{document}
--
Joseph Wright
GL
2011-02-06 11:18:38 UTC
Permalink
Post by Joseph Wright
First, you are using literal input in your unit. So it will only ever be
printed 'as is'. You need to use macro units, and so in my example I've
loaded the abbreviated units so I can use '\um\per\s' rather than the
full '\micro\metre\per\second'.
The poor educated man i am would have expected:
\µ\m\per\s

(for \µm implicitly assume that µ is a letter...)

Best regards.
FC
Post by Joseph Wright
Secondly, the option which sets how \per is handled is called 'per-mode'
not 'quotient-mode' (which is used for quotients in numbers). So an
\documentclass{article}
\usepackage{fixltx2e,siunitx,xfrac}
\sisetup{
fraction-function = \sfrac ,
load-configurations = abbreviations ,
per-mode = fraction ,
}
\begin{document}
\( \SI{100}{\um\per\s} \)
\end{document}
Robin Fairbairns
2011-02-06 11:40:28 UTC
Permalink
Post by GL
Post by Joseph Wright
First, you are using literal input in your unit. So it will only ever be
printed 'as is'. You need to use macro units, and so in my example I've
loaded the abbreviated units so I can use '\um\per\s' rather than the
full '\micro\metre\per\second'.
\µ\m\per\s
(for \µm implicitly assume that µ is a letter...)
of course, this requires a non-standard latex, and since siunitx was
written to unify a pre-existing set of si* packages, requiring some
different form of latex would seem a little odd.

no doubt, in a few years' time, we'll look back on the present situation
much as we do now regarding the pre-inputenc/fontenc situation. but not
yet.
--
Robin Fairbairns, Cambridge
my address is @cl.cam.ac.uk, regardless of the header. sorry about that.
Joseph Wright
2011-02-06 14:00:12 UTC
Permalink
Post by Robin Fairbairns
Post by GL
\µ\m\per\s
(for \µm implicitly assume that µ is a letter...)
of course, this requires a non-standard latex, and since siunitx was
written to unify a pre-existing set of si* packages, requiring some
different form of latex would seem a little odd.
no doubt, in a few years' time, we'll look back on the present situation
much as we do now regarding the pre-inputenc/fontenc situation. but not
yet.
As it's a single token, the category code for µ would not matter.
However, there are two things to notice here. First, there are no
abbreviations for the prefixes on their own, as some of the letters
overlap (we have \m => \metre, so what would you do for \milli?).
Second, the code is written to work without a UTF-8 engine. So I can'd
include 'µ' in the source (read through the source for section on µ in
XeTeX to see how I handle this). So I can't define \µ one way or the other.

(Also, no-one has ever asked for this, and so I've not worked everything
through.)
--
Joseph Wright
GL
2011-02-06 14:35:06 UTC
Permalink
Post by Joseph Wright
Post by Robin Fairbairns
Post by GL
\µ\m\per\s
(for \µm implicitly assume that µ is a letter...)
of course, this requires a non-standard latex, and since siunitx was
written to unify a pre-existing set of si* packages, requiring some
different form of latex would seem a little odd.
no doubt, in a few years' time, we'll look back on the present situation
much as we do now regarding the pre-inputenc/fontenc situation. but not
yet.
As it's a single token, the category code for µ would not matter.
That's true: \µ is possible and TeX will replace it by \^^b5
Post by Joseph Wright
However, there are two things to notice here. First, there are no
abbreviations for the prefixes on their own, as some of the letters
overlap (we have \m => \metre, so what would you do for \milli?).
That's a good point. \mm should be millimeter but, what about milli
gram, milli mole and milli ampère then ?
Post by Joseph Wright
Second, the code is written to work without a UTF-8 engine. So I can'd
µ is ASCII b5 (^^b5 in TeX hexadecimal - 181 in decimal) and does not
require any unicode setup for input encoding.

Am i wrong ?
Post by Joseph Wright
include 'µ' in the source (read through the source for section on µ in
XeTeX to see how I handle this). So I can't define \µ one way or the other.
(Also, no-one has ever asked for this, and so I've not worked everything
through.)
Philipp Lehman
2011-02-06 15:39:03 UTC
Permalink
Post by GL
µ is ASCII b5 (^^b5 in TeX hexadecimal - 181 in decimal) and does
not require any unicode setup for input encoding.
Nope, there is no "µ" in Ascii. µ is in slot 181 in
Latin1/Latin9/CP1252. Ascii has 128 code positions only (0-127).
--
Sender address blackholed, do not reply directly.
You can still reach me by email at: lehman gmx net.
Enrico Gregorio
2011-02-06 15:56:50 UTC
Permalink
Post by Philipp Lehman
Post by GL
µ is ASCII b5 (^^b5 in TeX hexadecimal - 181 in decimal) and does
not require any unicode setup for input encoding.
Nope, there is no "µ" in Ascii. µ is in slot 181 in
Latin1/Latin9/CP1252. Ascii has 128 code positions only (0-127).
In UTF-8, µ is the two-byte combination <C2><B5>; something like

\def\^^b5{\micro}

in the LaTeX format or in some package (written as usual with
only 7 bit characters) would give no meaning to \µ in a UTF-8
encoded file (with LaTeX and \usepackage[utf8]{inputenc}).

Saying also

{\catcode`\^^c2=\active \catcode`\^^b5=\active
\gdef\^^c2^^b5{\micro}}

would solve this problem, but would raise some others. It's
necessary to activate ^^c2 and ^^b5, since they're active for
UTF-8 encoded files read by LaTeX; so we would be actually
defining \^^c2 to be followed by the active character ^^b5.

Ciao
Enrico
Joseph Wright
2011-02-06 16:07:53 UTC
Permalink
Post by Enrico Gregorio
Post by Philipp Lehman
Post by GL
µ is ASCII b5 (^^b5 in TeX hexadecimal - 181 in decimal) and does
not require any unicode setup for input encoding.
Nope, there is no "µ" in Ascii. µ is in slot 181 in
Latin1/Latin9/CP1252. Ascii has 128 code positions only (0-127).
In UTF-8, µ is the two-byte combination <C2><B5>
I assume you mean 'mu' not 'micro', which is 181.
--
Joseph Wright
Enrico Gregorio
2011-02-06 16:33:22 UTC
Permalink
Post by Joseph Wright
Post by Enrico Gregorio
Post by Philipp Lehman
Post by GL
µ is ASCII b5 (^^b5 in TeX hexadecimal - 181 in decimal) and does
not require any unicode setup for input encoding.
Nope, there is no "µ" in Ascii. µ is in slot 181 in
Latin1/Latin9/CP1252. Ascii has 128 code positions only (0-127).
In UTF-8, µ is the two-byte combination <C2><B5>
I assume you mean 'mu' not 'micro', which is 181.
Well, hexadecimal B5 is decimal 181, isn't it?

According to the Unicode tables, "MICRO SIGN" is U+00B5,
rendered in UTF-8 as the two-byte combination <C2><B5>.

Unicode "GREEK SMALL LETTER MU" is U+038C, which in
UTF-8 is rendered as <CE><BC>.

Ciao
Enrico
GL
2011-02-06 16:39:01 UTC
Permalink
Post by Philipp Lehman
Post by GL
µ is ASCII b5 (^^b5 in TeX hexadecimal - 181 in decimal) and does
not require any unicode setup for input encoding.
Nope, there is no "µ" in Ascii. µ is in slot 181 in
Latin1/Latin9/CP1252. Ascii has 128 code positions only (0-127).
Yes this is true, I forgot that UTF-8 is ASCII only up and including 127
and also that 181 is greater than 127...

big mistake from me ;-)

Thanks for the correction.
Matthias Pospiech
2011-02-06 13:14:48 UTC
Permalink
Post by Joseph Wright
Post by Matthias Pospiech
The following code produces a µm/s instead of the nicefrac{µm}{s}
version. siunitx Version is 2.1i (texlive latest)
...
Post by Joseph Wright
One or two things :-)
First, you are using literal input in your unit. So it will only ever be
printed 'as is'.
Sorry, but I am not considering to write commands unless I have to.
Is the 'as is' handling a design choice? Or could the occurence of a '/'
be detected and replaced by \per ? I am just wondering why the whole
formating is disabled as soon as a non-command is inserted.

I never used or promoted siuntix before because it is generally
incompatible with previous 'as is' unit formating, as it can be achieve
with the really simple units package. I consider siunitx
now because units can not handle \mu properly, \unit{\mu m} does not
work. However it seems, as if I would have to rewrite _every_ unit in my
document.
Joseph Wright
2011-02-06 14:18:03 UTC
Permalink
Post by Matthias Pospiech
Post by Joseph Wright
First, you are using literal input in your unit. So it will only ever be
printed 'as is'.
Sorry, but I am not considering to write commands unless I have to.
Is the 'as is' handling a design choice? Or could the occurence of a '/'
be detected and replaced by \per ? I am just wondering why the whole
formating is disabled as soon as a non-command is inserted.
It's not just formatting. For what I call 'literal' input, the user is
left in charge of the output. So the input might be

\si{J.mol^{-1}.K^{-1}

or

\si{J/(mol K)}

or


\si{J/mol/K}

or

\si{J/mol K}

as all of these are used to represent the same unit (and yes, I know
that some of them are mathematically-invalid). There would be a
significant amount of work to parse all of these cases properly.

You might wonder about that last statement: where does parsing come in?
I was asked by someone else recently about \per, where they assumed that
it worked like \over. That was never the intention, as what happens is
that a 'macro' unit is actually parsed in its entirety before
typesetting from a data structure.

What I can offer is an additional setting, which would allow "/" to work
as you seem to want (i.e. much like \over). That can be done by checking
the unit input for a "/", and if one is present simply dividing the
input into two and typesetting as a fraction. Implementation for this
would be relatively easy, although an option name might be more of a
challenge. Let me know if this is of interest. (First thought is
'literal-mode-slash = per-mode' or '= fraction' for your desired
behaviour versus 'literal-mode-slash = standard' or '= unchanged' for
the current approach.)
Post by Matthias Pospiech
I never used or promoted siuntix before because it is generally
incompatible with previous 'as is' unit formating, as it can be achieve
with the really simple units package. I consider siunitx
now because units can not handle \mu properly, \unit{\mu m} does not
work. However it seems, as if I would have to rewrite _every_ unit in my
document.
If it's just µ, then you might prefer not to bother with siunitx (given
the comments above). In that case, all you want is the _definition_ for
\micro that I've used. That's been through a few changes over the
development of siunitx; the current approach is to use a private copy of
\textmu from the textcomp package. So you might want something like

\documentclass{article}
\usepackage{amstext,textcomp,units}
\newcommand*\micro{\text{\textmu}}
\begin{document}
\unit{\micro m}
\end{document}

Using the \text macro from amstext is how siunitx does the definition:
you might want to do something less complex (say \hbox).
--
Joseph Wright
Matthias Pospiech
2011-02-06 14:45:17 UTC
Permalink
Post by Joseph Wright
Post by Matthias Pospiech
Post by Joseph Wright
First, you are using literal input in your unit. So it will only ever be
printed 'as is'.
Sorry, but I am not considering to write commands unless I have to.
Is the 'as is' handling a design choice? Or could the occurence of a '/'
be detected and replaced by \per ? I am just wondering why the whole
formating is disabled as soon as a non-command is inserted.
It's not just formatting. For what I call 'literal' input, the user is
left in charge of the output. So the input might be
...
Post by Joseph Wright
What I can offer is an additional setting, which would allow "/" to work
as you seem to want (i.e. much like \over). That can be done by checking
the unit input for a "/", and if one is present simply dividing the
input into two and typesetting as a fraction.
I could live with commands that define the output, such as the \unitfrac
from units package does. That way the whole complex setup would be not
necessary. I really like about siunitx the number formating, but the
units parsing is really complex.
Usually (the way I am used to it), if I write km/s I mean 'output as
is'. If I write \frac{\unit{km}}{\unit{s}} I mean use frac (it would be
better if it was \\unit{\frac{km}{s}}, and if I want a nicefrac I write
\unitfrac{km}{s}, here the naming scheme however could be better.
With your package it would be best if one could simply replace \unit by
\si or \SI.
Post by Joseph Wright
If it's just µ, then you might prefer not to bother with siunitx (given
the comments above). In that case, all you want is the _definition_ for
\micro that I've used....
That what I have done already, however I defined \upmu.
Joseph Wright
2011-02-06 15:13:57 UTC
Permalink
Post by Matthias Pospiech
I could live with commands that define the output, such as the \unitfrac
from units package does. That way the whole complex setup would be not
necessary. I really like about siunitx the number formating, but the
units parsing is really complex.
Usually (the way I am used to it), if I write km/s I mean 'output as
is'. If I write \frac{\unit{km}}{\unit{s}} I mean use frac (it would be
better if it was \\unit{\frac{km}{s}}, and if I want a nicefrac I write
\unitfrac{km}{s}, here the naming scheme however could be better.
With your package it would be best if one could simply replace \unit by
\si or \SI.
That was one of the design criteria for the package! In version 1 I
provides some 'drop in' code to do this, but for version 2 decided it
might be safest not to (I was never sure things would be exactly
identical with say the units package and siunitx, and did not want to
give the wrong impression).

What you need to do is use math mode for units: the standard setting for
version 2 is text mode for units, but the change is easy. For what you
would like, something like

\documentclass{article}
\usepackage{siunitx}
\sisetup{mode = math}
\let\unit\si
\newcommand*\unitfrac[2]{\si{\frac{#1}{#2}}}
\begin{document}
% Standard siunitx notation:
\si{\frac{km}{s}}

% units-like
\unit{km/s} \unit{\frac{km}{s}} \unitfrac{km}{s}
\end{document}

should work.
--
Joseph Wright
Matthias Pospiech
2011-02-06 16:23:20 UTC
Permalink
Am 06.02.2011 16:13, schrieb Joseph Wright:
...
Post by Joseph Wright
What you need to do is use math mode for units: the standard setting for
version 2 is text mode for units, but the change is easy. For what you
would like, something like
\documentclass{article}
\usepackage{siunitx}
\sisetup{mode = math}
\let\unit\si
\newcommand*\unitfrac[2]{\si{\frac{#1}{#2}}}
\begin{document}
\si{\frac{km}{s}}
% units-like
\unit{km/s} \unit{\frac{km}{s}} \unitfrac{km}{s}
\end{document}
should work.
Unfortunately 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{...}.
Second, the unitfrac should be a nicefrac. Is this possible with
mode=math (which was the original question of the whole thread)?
And 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.

If (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.
Joseph Wright
2011-02-06 16:43:46 UTC
Permalink
Post by Matthias Pospiech
Unfortunately 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 Pospiech
Second, 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 Pospiech
And 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 Pospiech
If (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
Guenter Milde
2011-02-06 19:34:55 UTC
Permalink
Post by Joseph Wright
Post by Matthias Pospiech
And 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, this is in the contex of "roman" vs. "italic", i.e. about
upright vs. slanted. Unfortunately the term "roman" is ambiguous, but
IMO it is OK to use sans-serif upright letters for units in a
sans-serif context.
Post by Joseph Wright
'detect-family'. You can also 'detect-weight' if you want.
Günter
Matthias Pospiech
2011-02-07 08:32:15 UTC
Permalink
Post by Joseph Wright
With the provisos above, would the following work?
It fails at
\unitfrac[10^9]{V}{m}

because siunitx can not handle ^, however since units handles everything
in [] as math, this has to be rewritten anyway (I have much more complex
math in the [] brackets, which siunitx could never parse)

The sans serif math however does not work, this is the code of my table
It fails because of '\figureversion{tabular}'

\documentclass{scrartcl}

\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{MnSymbol}

%
\usepackage[%
onlytext, % only change the text fonts
% onlymath % only change the math fonts
textlf, % use lining figures in text mode
mathlf, % use lining figures in math mode
mathtabular, % use tabular figures in math mode
]{MyriadPro}


\usepackage[fixamsmath,disallowspaces]{mathtools}
\usepackage{fixmath}

\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}}}%
}

\listfiles

\makeatletter
\DeclareMathVersion{sansmath}
\SetSymbolFont{operators}{sansmath}{T1} {\***@Math@Family}{r}{n}
\SetSymbolFont{letters}
{sansmath}{OML}{MyriadPro-OsF}{r}{\***@Math@LetterShape}
\SetMathAlphabet\mathit {sansmath}{T1} {\***@Math@Family}{r}{it}
\makeatother

\begin{document}

\begin{minipage}[b]{0.39\textwidth}
\renewcommand{\arraystretch}{1.4}
\sffamily\small
\centering%
\figureversion{tabular} % <<--
\mathversion{sansmath}
\begin{tabular}{lc}
\hline
Density & $\rho = 2,2\,\unitfrac{g}{cm^3}$ \\
Transmission & $185 - 2500\,\unit{nm}$ \\
\hline
\end{tabular}
\end{minipage}

\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}
Bruno Le Floch
2011-02-07 11:52:12 UTC
Permalink
Post by Matthias Pospiech
Post by Joseph Wright
With the provisos above, would the following work?
It fails at
\unitfrac[10^9]{V}{m}
because siunitx can not handle ^, however since units handles everything
in [] as math, this has to be rewritten anyway (I have much more complex
math in the [] brackets, which siunitx could never parse)
The options you need for this is "parse-numbers = false"
Joseph Wright
2011-02-07 21:40:03 UTC
Permalink
Post by Matthias Pospiech
Post by Joseph Wright
With the provisos above, would the following work?
It fails at
\unitfrac[10^9]{V}{m}
because siunitx can not handle ^, however since units handles everything
in [] as math, this has to be rewritten anyway (I have much more complex
math in the [] brackets, which siunitx could never parse)
Bruno has answered this part.
Post by Matthias Pospiech
The sans serif math however does not work, this is the code of my table
It fails because of '\figureversion{tabular}'
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{MnSymbol}
%
\usepackage[%
onlytext, % only change the text fonts
% onlymath % only change the math fonts
textlf, % use lining figures in text mode
mathlf, % use lining figures in math mode
mathtabular, % use tabular figures in math mode
]{MyriadPro}
\usepackage[fixamsmath,disallowspaces]{mathtools}
\usepackage{fixmath}
\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}}}%
}
\listfiles
\makeatletter
\DeclareMathVersion{sansmath}
\SetSymbolFont{letters}
\makeatother
\begin{document}
\begin{minipage}[b]{0.39\textwidth}
\renewcommand{\arraystretch}{1.4}
\sffamily\small
\centering%
\figureversion{tabular} % <<--
\mathversion{sansmath}
\begin{tabular}{lc}
\hline
Density & $\rho = 2,2\,\unitfrac{g}{cm^3}$ \\
Transmission & $185 - 2500\,\unit{nm}$ \\
\hline
\end{tabular}
\end{minipage}
\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}
I'm a bit stuck testing the above as I don't have the appropriate font.
So I'll have to speculate on how it looks. The font detection in siunitx
is used to choose on of \mathrm, \mathsf or \mathtt to print things
(assuming math mode is in use). I suspect that the above does not
redefined \mathsf, which is what siunitx should be picking for printing.
You can set 'math-sf = <some math font command>' to alter the behaviour,
but I'm not sure quite what you'd want to put. (Perhaps you might e-mail
me a PDF so I can actually see the output!)

This is one of the reasons I decided _not_ to include compatibility code
in version 2 of siunitx. Some of the underlying approach is very
different from packages such as units, and there are places where the
behaviour will differ. (As I say, siunitx actively picks a math font, so
that things like '\( \mathsf{\num{10}} \)' come out in roman rather than
sans serif, at least by default.)
--
Joseph Wright
Uwe Siart
2011-02-06 18:56:38 UTC
Permalink
I consider siunitx now because units can not handle \mu properly,
\unit{\mu m} does not work.
What about the 'gensymb' package and its generic macros \micro, \degree,
and \ohm which work in both text and math mode?

With this you can write \unit{\micro m} and you're done.
--
Uwe
Matthias Pospiech
2011-02-06 19:03:22 UTC
Permalink
Post by Uwe Siart
I consider siunitx now because units can not handle \mu properly,
\unit{\mu m} does not work.
What about the 'gensymb' package and its generic macros \micro, \degree,
and \ohm which work in both text and math mode?
With this you can write \unit{\micro m} and you're done.
From the docu, regarding \micro (using \upmu):

"It is always upright roman, regardless of whether the surrounding text
is sans serif, bold or whatever."

Since I use sans serif math fonts in tables, it does not work for me.
Also it is up to the font or other packages to provide \upmu.

This can be achieved using 'upgreek', but this loads upmu from a
standard font, and is thus different to the font used in the text and math.
Alexander Zimmermann
2011-02-06 17:34:37 UTC
Permalink
Works for me:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}

\usepackage{xfrac}
\usepackage{siunitx}
\sisetup{%
per-mode=fraction,
fraction-function=\sfrac,
load-configurations=abbreviations
}

\begin{document}
\SI{100}{\micro\meter\per\second}
\end{document}

Alex
Post by Matthias Pospiech
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
%\usepackage{xfrac} % has no effect
\usepackage{siunitx}
\sisetup{%
mode=text,
exponent-product = \cdot,
number-unit-separator=\text{\,}
}
\begin{document}
$\SI[quotient-mode=fraction, fraction-function=\sfrac]{100}{\micro m/s}$
\end{document}
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
Loading...