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?

  • 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). – Andrew Stacey 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

You can use the package xspace for this purpose:


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.
| improve this answer | |
  • 9
    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} – Andrew Stacey 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. – Andrew Stacey 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. – Andrew Stacey Aug 17 '11 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy