Common abbreviations are surprisingly tricky to format correctly. I'd like some simple macros for them, to be used like so:
You should eat more fruit, \eg apples, bananas, oranges, \etc.
There are (at least) three (interrelated) problems to overcome in defining this:
- If used at the end of a sentence, we end up with doubled-up periods. Simply leaving off the period in the macro seems ugly (especially for things like 'e.g.', 'i.e.', …). A better solution calls for something like
\consumeif{.}
, but I can't find a beast. - The macro should include the behavior of
\xspace
. - It should also produce correct spacing depending on whether it ends a sentence, like the logic of
\@
.
How would I (you) write such a macro? Note: I'm aware of this question and others like it, but the answers don't resolve my problems.
Best Answer
I think the
\eg
and\ie
macros should be defined differently to\etc
, because they will never be at the end of a sentence. You can simply use\@\xspace
at the end to ensure a space with the correct width if one is required. For\etc
you can use\@ifnextchar{.}{<yes>}{<no>}
to check for a following full stop.