[Tex/LaTex] No newline before scientific units without using “~”

line-breakingunits

Is it possible to define a list of units (like ml, °C, nmol, eq., etc.) and forbid latex to insert a newline before those?

I know it is possible to use a ~ between number an unit, but the above described method would be much more convenient for me.

Thanks for helping me!

edit:
thanks for all the comments and answers, but maybe i should explain my reason to look for something like that: I have a very large Document (not yet written in latex) and try to format it using latex. Therefore it would be quite time consuming to edit every value and unit to fit the siunitx syntax. Same problem with the answer from Steven B. Segletes.

Best Answer

If you want minimal mark-up, you can do it using siunitx using either

\documentclass{article}
\usepackage{xspace}
\usepackage{siunitx}
\sisetup{free-standing-units, space-before-unit, use-xspace}
\begin{document}

10\metre or even 10\m (a bit risky)

\end{document}

or

\documentclass{article}
\usepackage{siunitx}
\sisetup{free-standing-units, unit-optional-argument}
\begin{document}

\metre[10] or even \m[10] (a bit risky)

\end{document}

or you could use the older unitsdef package

\documentclass{article}
\usepackage{unitsdef}
\begin{document}

10\meter or \meter[10].

\end{document}

(Notice that the siunitx syntax for 'free-standing' units is in-part based on unitsdef.) As noted in comments and in What package should I use to typeset units?, the 'preferred' syntax in siunitx is

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\SI{10}{\metre} or even \SI{10}{\m}.

\end{document}

as this provides more logical mark-up but also more programmatic control of outcomes. In any of the siunitx cases, the space is adjustable via a key and will not break unless the appropriate setting is altered.

Related Question