# How to automatically switch unit systems?

The question Why use a package to typeset units? made me think about something else: In non-scientific context one may have to provide data for persons using ... imperial units (shiver). But there may be two versions of a report, or the desire to put a secondary unit in parentheses following the primary unit value. Is there any package that treats this? So I'd write something like

$\SI{5}{\m/\s}$


And the output could be chosen to be any of e.g.

5 m/s
5 m/s (11.18 mph)
11.18 mph (18 km/h)


depending on a definition in the preamble?

-
Sure it is possible, however, consider places were meter is compared with the imperial unit miles. You should do \SI{5}{\length/\time} to conform to some kind of consistency. Furthermore, doing \let\length\m or \let\length\miles is probably what you need? (there might be something that should be handled correctly in terms of siunitx). And then some wrapper on \SI –  zeroth Apr 10 '13 at 9:55
@zeroth I think unit conversion is needed here rather than only the symbols. Check 5 becoming 11.18 and 18. –  percusse Apr 10 '13 at 9:56
Yes, I put in the wrapper on \SI to handle this. (my comment was merely noting that \m was not always meters which was troubling me). –  zeroth Apr 10 '13 at 9:58
@zeroth I think I understand what you mean: providing the SI-unit magnitude, and the \lets would have the wrapped \SI decide in which actual unit to display. It's a good idea, though that would not provide an intuitive way for the optional parentheses. –  Tobias Kienzler Apr 10 '13 at 10:02
@TobiasKienzler something like that, but the wrapper can also decide the parenthesis notation? Here you probably need to define a "standard" unit and "parenthesised" unit. And then the wrapper could handle both cases, or make several wrapper functions for parenthesised and non-parenthesised versions. –  zeroth Apr 10 '13 at 10:05

You could define your own command:

\documentclass{article}
\usepackage{pgf}
\usepackage{siunitx}

\newcommand{\speed} [1] {%
\SI{#1}{\metre\per\second} (\pgfmathparse{2.247*#1}\pgfmathresult~mph)%
}

\begin{document}
\speed{5}
\end{document}


The output can be optimized, but with pgf you can define any calculation (like unit conversions, which are basically multiplications with a constant factor).

I don't think there's a finished package yet that supports automatically unit conversions.

-
Sounds good. Using Python with sympy.physics.units, or GNU units, could of course save the hassle of manually converting... –  Tobias Kienzler Apr 10 '13 at 10:06