Breaking lines in siunitx version 2

Line breaks between units and values are frowned upon by those “in the know”, as the unit–value combination is mathematically one entity. Despite that, in reality this is a feature I’ve been asked for in siunitx.The way I’m implementing things, this is not technically difficult to implement. With a suitable warning, I will include the ability to break between units and values in siunitx version 2.

The other place you could place breaks is between different units (assuming a space is being used as the unit separator). This is much more problematic for a number of reasons. First, unlike between numbers and units, the inter-unit separator might be one of various things. The space between a value and a unit is always some kind of white space, and is always expected by the reader. So working out if a break is sensible would not be easy. Second, siunitx needs to handle two types of unit input, units as macros and literal input. I’ve steered away from processing literal units for various reasons, and reliably breaking both types of input looks difficult. Third, there is a technical problem. Simplifying how siunitx works, currently units are actually printed by some code that does:

\hbox{%
% Some font set up work for maths mode
\ensuremath{%
\mathrm{%
unit \, unit \, unit
}%
}%
}

when printing in maths mode (the default). The key point is that everything needs to be inside an \hbox so that the formatting of maths can be influenced correctly. So breaking units here is not possible. To get around this, I’d need to print each unit separately, with the spaces outside the box. This looks slow and unreliable. All things considered, I’m minded to keep the current approach to units: the unit is a non-divisible block.

3 thoughts on “Breaking lines in siunitx version 2”

1. Will

I don’t mind the *option* to break between numbers and units (although I’d never use it myself), but line-breaking between separate units in a dimensioned number seems like a bad idea to me.

Would you like to elaborate why you prefer non-literal units? I actually much prefer writing “SI{2.3}{N.m}”.

2. Joseph Wright

Hello Will,

I’ve basically come down as you suggest: breaks between numbers and units yes, but not within units.

I didn’t actually say I prefer non-literal units (although I always use the macro versions: logical input). I was taking about how they are handled as a package author. If the input is given in macro form, then there are no possible surprises and siunitx can handle them any way I can think of/code. On the other hand, if the input contains literals then my preference is to limit processing to converting “.” and “~” to spaces or symbols (as in sistyle). I’m very reluctant to do anything else, which includes adding line breaks. (I was asked if I could arrange for “N/m.s” to convert into frac{N}{m.s}, for example: I’ve said “probably not”.)

3. Stefan Pinnow

I also think, that the only “good” point to break the value-unit-combo (if there is one) is between these two and not in between a value or unit.
I also think that that normally is not needed. One possibility where this could be needed, is in articles where small columns are printed. There a long value with a long unit could lead to weird looking lines.