3

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.

ail246
  • 51
  • 1
    http://tex.stackexchange.com/questions/2248/what-package-should-i-use-to-typeset-units – Joseph Wright Jun 25 '15 at 16:51
  • 1
    See Josephs link, just wanted to mention that in most cases ~ would be the wrong spacing to use. It should be smaller. – daleif Jun 25 '15 at 16:52
  • @JosephWright: thanks for the link, even though it does not directly answer my question (see edit), it provides some interesting information on your package, that seems to be very useful for scientific documents. I will certainly use it in the future. – ail246 Jun 25 '15 at 20:08
  • @daleif: are you sure? I cannot see any difference when exchanging the ~ with a normal "space". What would you recommend instead? – ail246 Jun 25 '15 at 20:08
  • 1
    @ail246 \, is the usual recommendation: a thin space. – Joseph Wright Jun 25 '15 at 20:12
  • I've reopened based on the edit: feel free to ping me and request closing again if this seems wrong. – Joseph Wright Jun 25 '15 at 20:17
  • @JosephWright oh, i got the comment wrong. I thought he meant that the ~ would be bigger than a usual text-space... thanks for the advice to both of you – ail246 Jun 25 '15 at 20:19
  • Might me time consuming, but still the right to to do – daleif Jun 25 '15 at 20:20
  • @daleif well it seems to be the only possibility.. – ail246 Jun 26 '15 at 09:17

3 Answers3

2

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.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • thanks for summarizing the possibilities in SIunitx. I really appreciate how much effort you make to help a noob like me. I think I'm going to write a small perl programm using regular expressions to get all the units into the right syntax. – ail246 Jun 26 '15 at 09:24
1

If one chooses to not use the siunitx package which was designed to handle units, one could define \myunit{} that accomplishes the goal of avoiding such breaks before the unit.

\documentclass{article}
\def\myunit#1{\unskip\,\textrm{#1}}
\begin{document}
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
8 \myunit{ml}\ or $\pi \myunit{$^\circ$C}$.
\end{document}

enter image description here

0

Do you mean something like that?

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{siunitx}
\usepackage[inline]{enumitem}
\DeclareSIUnit{\Fahrenheit}{\degree\,F}
\DeclareSIUnit{\drachm}{dr\,av}
\DeclareSIUnit{\oz}{oz\,av}
\DeclareSIUnit{\yard}{yd}
\sisetup{per-mode=symbol}

\begin{document}

Here is a list of some typical non SI units:
\begin{itemize*}[itemjoin=\hskip0.8em, afterlabel=\hskip0.25em, before=\quad]
  \item \si{\celsius}
  \item \si{\Fahrenheit}
  \item \si{\decibel}
  \item \si{\drachm}
  \item \si{\drachm\per\yard\squared}
\end{itemize*}


\end{document} 

enter image description here

Bernard
  • 271,350
  • What's drav/drachm? Sorry, I know this isn't really on topic, I'm just really curious! I wikipedia'd drachm and found something that made sense, but it didn't mention drav. – Au101 Jun 25 '15 at 19:16
  • Celsius is an SI unit :-) – Joseph Wright Jun 25 '15 at 19:17
  • Is it? I thought it was the Kelvin – Bernard Jun 25 '15 at 19:28
  • 1
    @Au101: It is 1/16 n ounce, or 1/256 pound in the avoirdupois imperial system, about 1.772 g. Not to be confused with the apothecaries drachm, 1/96 pound, subdivided in 3 scruples. – Bernard Jun 25 '15 at 19:44
  • I think Celsius is an SI derived unit http://physics.nist.gov/cuu/Units/units.html. Kelvin is the bona fide SI unit – Au101 Jun 25 '15 at 19:49
  • @Au101 Both are bona fide SI units, derived units are quite allowed: http://www.bipm.org/en/publications/si-brochure/. – Joseph Wright Jun 25 '15 at 20:23
  • @JosephWright No doubt. Sorry, I didn't mean it quite like that. But Kelvin is the base unit, it's the ... it's the 24 carat SI unit, it's the pure SI unit, not based on any other SI unit, the fundamental, the element, you know what I mean – Au101 Jun 25 '15 at 20:46