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.

9
  • 1
    tex.stackexchange.com/questions/2248/…
    – Joseph Wright
    Commented Jun 25, 2015 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
    Commented Jun 25, 2015 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
    Commented Jun 25, 2015 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
    Commented Jun 25, 2015 at 20:08
  • 1
    @ail246 \, is the usual recommendation: a thin space.
    – Joseph Wright
    Commented Jun 25, 2015 at 20:12

3 Answers 3

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.

1
  • 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
    Commented Jun 26, 2015 at 9: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

7
  • 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
    Commented Jun 25, 2015 at 19:16
  • Celsius is an SI unit :-)
    – Joseph Wright
    Commented Jun 25, 2015 at 19:17
  • Is it? I thought it was the Kelvin
    – Bernard
    Commented Jun 25, 2015 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
    Commented Jun 25, 2015 at 19:44
  • I think Celsius is an SI derived unit physics.nist.gov/cuu/Units/units.html. Kelvin is the bona fide SI unit
    – Au101
    Commented Jun 25, 2015 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .