Using siunitx
, I can type $V = \SIrange[range-phrase=\text{ to },range-units=single]{100}{125}{\kilo\m\per\hour}$
to get
However, numerically speaking, I have to specify the step of the range in order to know exactly each speed value I will do my calculations at.
Therefore, I would like to understand how to create a command, e.g. \SIsteps
, where it accepts the following arguments:
<start>
,
<step>
(optional and its default is 1
) it can be integer or float,
<size>
(optional) it is the total number of the elements in the range/interval
<end>
, and
<unit>
.
So, for example, all the following codes should have the same output of
The speed range is $V = \SIsteps[step=5]{100}{125}{\km}$
The speed range is $V = \SIsteps[size=6]{100}{}{\km}$
The speed range is $V = \SIsteps[size=6]{}{125}{\km}$
\documentclass{article}
\usepackage{unicode-math,siunitx}
\sisetup{
load-configurations = abbreviations,
inter-unit-product = \ensuremath{{\hspace{-0.5ex}}\cdot{\hspace{-0.5ex}}}
}
\setmathfont{Cambria Math}
\begin{document}
The speed range is $V = \left\{100,105,\ldots,125\right\}~\si{\km\per\hour}$
\end{document}
Best Answer
The macro
\SIsteps
has\num
\si
As you requested, the default step is 1, but it can be specified either in the options or (following normal scope rules) with
\stepsetup
.The keys are
start
to set the starting pointend
to set the end pointstep
to set the stepsize
to set the number of items to showfull
to specify we want a full display of the values (default false)sep
to specify the separator between items (default comma)You have better to specify two keys among
start
,end
andsize
, but don't specify all three of them.The explicit
\,
between the brace and the unit might be\l__siunitx_number_unit_product_tl
, but this is an internal ofsiunitx
and it's bad practice to use it. This might possibly be offered as a user level token list in the future.You can also add support for angles (but not minutes and seconds, for that you'd be charged a thousand times).
UPDATE for
siunitx
version 3The
load-configurations
option is no longer valid and the first code works the same as with version 2.For the second code, replace
\l__siunitx_number_unit_product_tl
with\l__siunitx_quantity_product_tl
(there seems to be no interface to it yet).In addition
\si
should also become\unit
and, for uniformity,\SIsteps
should perhaps be renamed\qtysteps
.