# No space following macro without argument [duplicate]

With a macro such as:

\def\naive{na\"{\i}ve}


I find that the space which I would hope to follow it, is absent. So, with

the \naive approach


I get

the naïveapproach

in the output. How do I bring back the space?

## marked as duplicate by Werner macros StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Oct 3 '16 at 6:16

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.

\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}


• no, then it should be \@ifdefinable{...} – user2478 Aug 16 '11 at 11:13
• @Herbert: I don't know \@ifdefinable{...}, why is it better? – user4417 Aug 16 '11 at 11:53
• then you can out a message in the text, which the user understand! – user2478 Aug 16 '11 at 11:57

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

The problem is that the follwing space is uses as macro end. Type \navie{} or use the xspace package.

\documentclass{minimal}

\usepackage{xspace}
\newcomand{\naiv}{naiv\xspace}

\begin{document}
Test \naiv Test.
\end{document}


Quick answer: the \naive\ approach

Better answer: Use the xspace-package

\usepackage{xspace}
\newcommand{\better\xspace }
...

the \better approach


Advantage: xspace take a look on the next character. So you have not an obsolete space in:

Macro at sentence end\better.


A dirty trick: Use a special character in the macro name (not working with \newcommand):

\documentclass{article}
\def\¶naive{na\"{\i}ve}
\begin{document}
the \¶naive approach
\end{document}


Note: Do no start another macro with the same special character, although is possible use again this character in another position.

I don't know xspace package but I mean that it does somethig similar to this:

\def\maybespacelist{.,;!?}
\def\maybespace{\let\nexxt=\space
\edef\maybespaceA{\noexpand\maybespaceB\maybespacelist\relax}%
\futurelet\next\maybespaceA
}
\def\maybespaceB#1{\ifx#1\relax \nexxt \else \ifx#1\next \let\nexxt=\relax\fi
\expandafter\maybespaceB\fi
}
\protected\def\naive{na\"{\i}ve\maybespace}

The \naive approach. The approach is \naive.

\bye


For completeness, you could also define the macro as

\def\naive#{na\"{\i}ve}


which will require that it be followed by {} when ever it is used. For example, the \naive{} approach will work whereas the \naive approach will raise an error which says Use of \naive doesn't match its definition..

See page 204 of The TEXbook for details. Also, this answer may be of interest.