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.

I'm sure this is a pretty standard questions that's been asked (and answered!) a hundered times before, so apologies for boring people.

In LaTeX, I'd like to write a macro for abbreviations, such as, "e.g." or "i.e." but I'd like LaTeX to get the spacing after the trailing dot right: sometimes I enclose the "e.g." in commas and sometimes I don't, depending on the document I'm writing:

A lot of fruits contain vitamin C, e.g., lemons and oranges.

To practice a sport like e.g. rugby, a good level of fitness is adviced.

(Please let's not discuss whether this use of commas is correct or not.)

How can I write a macro \eg that gets the spacing right automatically for both cases?

share|improve this question
    
This question pretty seems to be the same as tex.stackexchange.com/questions/2229/… . If you don't want the bigger space after the period, enter a \ after e.g., like e.g.\ rugby –  Matten Dec 10 '10 at 11:01
2  
@Matten: I disagree. The point of this question is how to have a macro put in the space. The point of that question is how much space to put in (and how to control it). –  Loop Space Dec 10 '10 at 11:12
    
ok, you're right –  Matten Dec 10 '10 at 11:19
2  
I know this is orthogonal to your question, but IMO if you care enough about your document that you want to control the spacing after periods, then you should care enough about the text to avoid abbreviations like "e.g." –  Matthew Leingang Dec 10 '10 at 14:42
    
@Thomas: You might also be interested in this answer to a related question. –  Hendrik Vogt Dec 10 '10 at 14:55
add comment

1 Answer

up vote 11 down vote accepted

You can use the package xspace for this purpose:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{xspace}
\newcommand*{\eg}{e.g.\xspace}

\begin{document}
A lot of fruits contain vitamin C, \eg, lemons and oranges.

To practice a sport like \eg rugby, a good level of fitness is adviced.
\end{document}
share|improve this answer
7  
Actually, the spacing here is incorrect. Thanks to Will's comment on an answer to tex.stackexchange.com/questions/2229/…, the correct definition is \newcommand*{\eg}{e.g.\@\xspace} –  Loop Space Dec 10 '10 at 11:13
2  
@Andrew: This still doesn't handle punctuation that needs double spacing at the end of a sentence, e.g., in "There were all sorts of farmyard animals there: rabbits, pigs, \etc". Some code of mine from SO does handle this, although it doesn't treat "!" and "?", and its use of expl3 makes it a bit heavyweight. –  Charles Stewart Dec 10 '10 at 20:15
    
@Charles: ouch! Mind you, the example given was e.g. and I can't think of that going at the end of a sentence. –  Loop Space Dec 10 '10 at 20:23
3  
@Andrew: "Don't use the three most common Latin abbreviations, i.e., etc., i.e., and e.g." –  Bruno Le Floch Aug 17 '11 at 11:58
    
@Bruno: Very witty. –  Loop Space Aug 17 '11 at 18:03
add comment

Your Answer

 
discard

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