1

I created two custom command such that I could get a properly formatted micro and nanometer suffixes without too much a hastle by using the siunitx package as follows:

\newcommand{\nm}{\si{\nano\meter} }
\newcommand{\um}{\si{\micro\meter} }

Normally the \si command incorporates spacing correctly when using it in a body of text, but when using my custom command I had to add a space at the end of it. Since it doesn't do that automatically when I use it in any bit of text. Which works, usually, but not when I use the command to end a sentence or put it before a comma. Maybe there is some kind of command structure which I am overlooking that takes care of this?

Lythes
  • 23

2 Answers2

1

Whilst it's not the standard setting for a reason, one can create such free-standing units:

\documentclass{article}
\usepackage[free-standing-units, use-xspace]{siunitx}
\begin{document}

The distance~$d$ is given in \nm, so \nm are an SI unit of distance.

\end{document}
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
0

The xspace package is intended for this kind of use: it "smartly" adds a space at the end of your macro (i.e. not when you macro is followed by a punctuation character).
You use it this way:

\newcommand{\nm}{\si{\nano\meter}\xspace}

\documentclass{scrartcl}
    \usepackage{siunitx}
    \usepackage{xspace}

    \newcommand{\nm}{\si{\nano\meter}\xspace}

\begin{document}
    You can say that 13\nm is shorter than 17\nm.
\end{document}

enter image description here

ebosi
  • 11,692