No space following macro without argument
The problem of using \naive\
or \naive{}
: If you happen to forget the closing backslash/braces, you'll end with gobbled space without noticing it.
The problem of adding \xspace
to a macro's definition: This may produce inconsistent spacing if the macro uses \emph
. See xspace and italic correction for details.
In the thread linked above, Will Robertson suggested to use "delimited" macros (e.g. with /
at the end) as an alternative. The main advantage of \naive/
is that an error message will occur if you happen to forget the closing slash.
(See also the comments to this answer.)
\documentclass{article}
\newcommand{\naive}{}% To make sure that \naive isn't already defined
\def\naive/{na\"{\i}ve}
\begin{document}
the \naive/ approach
\end{document}
Use the package xspace
. It
provides a single command that looks at what comes after it in the command stream, and decides whether to insert a space to replace one "eaten" by the TeX command decoder.
For your case it can be used as in the following:
\documentclass{article}
\usepackage{xspace}
\def\naive{na\"{\i}ve\xspace}
\begin{document}
the \naive approach
\end{document}
Use braces \naive{}
or \naive\
or xspace
. See the FAQ: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=xspace