1

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.

  • 4
    latex does not add space after ! (and xspace does not remove space) If you are getting a space you must have a space in the source. – David Carlisle Aug 31 '13 at 19:21

2 Answers2

1

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.

Mico
  • 506,678
  • 2
    Xspace should not be relevant here, the OP said latex was printing space... (despite the fact that it's accepted answer:-) – David Carlisle Aug 31 '13 at 19:21
0

I don't know how did the xspace got the right answer here :)

The answer for those who got the same problem is to add a backslash after the exclamation or question marks if they do not end a sentence.

i.e. Go for it!\

  • Welcome to SE. Please avoid external links that could break in the future. An answer like this one can very well stand on its own. Thank you. – Miyase Jul 04 '22 at 23:44