3

I used to (a month or two ago) be able to make my units with some arbitrary text, with spaces, which helped a lot since I use a lot of different units and labels in my data, and I have no need to define special cases for each and every one.

For instance,

\SI{1}{liter soln}

would produce "1 liter soln"

However I recently updated all my packages and apparently this does not work anymore. I now get all the spaces in the units removed, so "1 litersoln".

Can someone confirm that siunitx changed recently to enforce always using properly declared units in \SI{}{}? And if so, is there some easy way to work around? To be clear I DO NOT want to define unique qualifiers and units for each case because I would literally have dozens in my file, each used once.

  • You can define a common configuration file for siunitx that can contain all of those definitions, and gets loaded each time you use siunitx. See this comment thread for how to create such a file: tex.stackexchange.com/questions/27614/… (although I keep searching for this, maybe I should ask a question about it...) – darthbith Jan 28 '15 at 18:37
  • That would be a waste of time, over all my documents there would literally be hundreds of different defintions, not to mention having to refactor all these documents. Nightmare. Is there some kind of "text mode" for units in siunitx? – William Kennerly Jan 28 '15 at 18:40
  • 3
    There is, you can use \sisetup{mode=text} in your preamble to force siunitx to typeset everything in text mode instead of math mode. Beware if you have different fonts for your text and math though, it may not look quite right :-) Out of curiosity, why do you have so many different unit combinations? – darthbith Jan 28 '15 at 18:45
  • Thanks darthbith, that worked perfectly. All the other official declared units work just fine too. I'm a chemist and include the chemical formula along with each quantity... so I have different "units" for "liters soln", "liters methane" "liters gas" "liters nitrogen" ...etc, etc. – William Kennerly Jan 28 '15 at 18:56
8

Unit input in siunitx should in general not include spaces as these are not part of the unit itself. If you really want a space, make an explicit one

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\si{litre\ soln}
\end{document}

(Input should as far as possible not depend on math/text mode or should force the appropriate mode.)

That said, litre is not a unit symbol and siunitx is not intended for dealing the the names of units. As such, a more typical piece of input might read

\documentclass{article}
\usepackage{siunitx}
\sisetup{qualifier-mode = space}
\begin{document}
\si{\litre\of{soln}}
\end{document}

where it is not necessary to have a separate qualifier defined for each type. (Of course, you should not actually have qualifiers in units, as the BIPM make clear!) Done in this way you can define \litre to give 'litre' if you wish.

  • 1
    Thanks for giving the "real" answer to this question. I only wonder: What do you mean by "Input... should force the appropriate mode"? Do you mean we should put \si{\text{liter soln}} and leave the mode setting alone? – darthbith Jan 28 '15 at 20:51
  • 1
    @darthbith In general the input in the document body should work irrespective of math/text mode selection. That's why for example for anything that requires math mode I recommend using \ensuremath. The trick is to 'protect' as little input as possible (it can affect font choice): here, there's no reason 'litre' or 'soln' to be forced into text mode, so I'd prefer a solution which avoids using \text. – Joseph Wright Jan 28 '15 at 20:54
  • Thanks! Two more follow ups: 1) Does setting mode=text set the input into a \text{}, equivalent to the user using that macro in the input (should I ask this as a new question)? 2) As I found out, using \text{} may also affect line breaking, most especially in the range and list macros (although in the case of this question, one may not want a line break between the unit and qualifier) – darthbith Jan 28 '15 at 21:28
  • @darthbith On the line breaking, it's a technical limitation of the way I've implemented the list/range stuff. I have a plan for v3, but in any case it doesn't affect the 'usual' cases. mode=text does indeed (broadly) put everything inside \text. – Joseph Wright Jan 28 '15 at 21:35
3

You can use the mode=text option to get the spaces to be respected.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
Default: \SI{1}{liter soln}

\sisetup{mode=text}
\verb|mode=text|:  \SI{1}{liter soln}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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