[Tex/LaTex] How to remove the space after an exclamation point

spacing

I am creating a document about a project whose name is "Go for it!" with an exclamation point. I am fairly new to Latex, but I figured that there should be a command to print the project name, with the exclamation mark and everything. So I did:

\newcommand{\goforit}{Go for it!}

The problem is the exclamation mark, since Latex prints a space after it, and in case I want to say "Go for it!, due to its awesomeness[…]", it will print a space before the comma, which is undesirable.

From what I've read, I can append "\ " to it, but that will indeed still print a space before the comma.

Best Answer

You could use the \xspace macro of the eponymous package. Consider the following MWE (minimum working example):

\documentclass{article}
\usepackage{xspace}
\newcommand{\gfi}{Go for it!\xspace}
\begin{document}
\gfi Yes, \gfi, right now.
\end{document}

enter image description here

Of course, nothing's ever perfect, and that applies to \xspace as well. To read up on some of its potential shortcomings (which I generally find too dreadful), you may want to read the posting Drawbacks of xspace.

Related Question