Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

As scientific species names should be written in italic, I have adopted a shortcut to do this in LaTex by creating a definition in the preamble:

\def\GM{{\it Gadus morhua~}} 

Then it's easy to call for \GM is a fish, which returns "Gadus morhua is a fish". Note that I have added ~ to the definition, so that I won't need to write \GM~. This works except, if I want to write The fish is called \GM., which would return "The fish is called Gadus morhua ." (with a space between morhua and period). In order to maximize my lazy writing style I would like to find a way to "eat away" that space I defined earlier. I know that a negative space exists in math mode, but writing $\GM\!$ does not lead to a right result. Is there a way adding a negative space to text mode?

share|improve this question
    
Please note that the \it, \bf, etc. font macros are deprecated because they do not use the new font selection scheme introduced with LaTeX2e. Please use {\itshape ..}, {\bfseries ..} or \textit{..}, \textbf{..} instead. See Does it matter if I use \textit or \it, \bfseries or \bf, etc. and Will two-letter font style commands (\bf, \it, …) ever be resurrected in LaTeX? for more information. –  Martin Scharrer May 21 '12 at 11:50

1 Answer 1

up vote 10 down vote accepted

This is exactly what the xspace package is for. The manual says:

»After defining \newcommand{\gb}{Great Britain\xspace}, the command \gb will determine when to insert a space after itself and when not.«

share|improve this answer
    
Thanks! It seems not to work with \def, though. If I define \def\GM{{\it Gadus morhua\xspace}}, I'll get Gadus morhuais a fish without space –  Mikko May 21 '12 at 10:41
1  
@Largh Don't use \def, first of all, nor the deprecated command \it. Use \newcommand{\GM}{\textit{Gadus morhua}\xspace} instead. –  egreg May 21 '12 at 10:47
    
Ops, I placed it inside \it{}. That's why it didn't work. Thanks for help! –  Mikko May 21 '12 at 10:49
    
Well, thanks to David Carlisle and Morten Høgholm, who wrote the package! –  Keks Dose May 21 '12 at 10:56
    
@Largh: Also \xspace must be the very last thing in the macro definition in order to be able to check for a following space. Having a } or anything after it will make it useless. –  Martin Scharrer May 21 '12 at 11:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.