Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I cannot figure out which of the siunitx font options is the correct to typset the rangephrase when using SIrange in math mode the same way as in text mode. See the MWE

\documentclass{book}
\usepackage{siunitx} 
\sisetup{mode=text} % does NOT have an effect here
\begin{document}
\SIrange{1}{2}{\watt}\\
$\alpha=\SIrange{1}{2}{\watt}$
\end{document}
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

I am not sure why this is not the default behaviour, but if you specify range-phrase = {\text{~to~}} you get the same behavior in and out of math mode:

enter image description here

\documentclass{book}
\usepackage{siunitx} 
\sisetup{mode=text,range-phrase = {\text{~to~}}}
\begin{document}
\SIrange{1}{2}{\watt}\\
$\alpha=\SIrange{1}{2}{\watt}$
\end{document}
share|improve this answer
    
That is a starting point, but how can one get rid of the italics? Is there any reason why ~to~ is not the default? –  Paul Hanson Nov 16 '11 at 1:56
    
The updated solution uses the \text macro to ensure that the to is typeset the same way in and outside of math mode. Am sure @Joseph Wright will see this and since he wrote the package he is probably the best to elaborate. –  Peter Grill Nov 16 '11 at 2:05
add comment

Peter has given an answer to make the range phrase print in text mode, which probably solves the case in point. However, there is a reason that siunitx does not do this by default. In particular, in the documentation it states that \SIrange should only be used in text mode.

To see why this is, try the following demonstration.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
Some filler text.
Some filler text.
Some filler text.
Some filler text.
$1\,$m to $10\,$m

Some filler text.
Some filler text.
Some filler text.
Some filler text.
\SIrange{1}{10}{\m}

\sisetup{range-phrase = \text{ to }}
Some filler text.
Some filler text.
Some filler text.
Some filler text.
\SIrange{1}{10}{\m}

\sisetup{range-phrase = \text{ to }\break}
Some filler text.
Some filler text.
Some filler text.
Some filler text.
\SIrange{1}{10}{\m}

\end{document}

What you'll find is that the use of \text here prevents a line break. More importantly, when we force a line break in conjunction with \text, the end of the line is wrong. There is no reliable way of setting up an \ensuretext macro other than inserting an hbox, and so that is what happens with \text. Within such a box, a space which occurs at the end of a line will not be discarded, and so the layout is wrong. Thus while most of the time this looks fine, if the end of the line comes at an inopportune place then disaster will strike. (See for example https://bitbucket.org/josephwright/siunitx/issue/156/unbreakable-space-in-range-phrases where this came up 'in the wild'.) There is no good solution other than stating that \SIrange should be used in text mode, and so this is the official position. Hence the standard settings are such that they work correctly in all supported cases.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.