Alex Rivera | Logout

Correct way to define macros \etc \ie in latex

Asked 2010-07-19T15:11:41.073
47

In this article the author discusses the use of \@ to put correct spacings after full stops that are not at the end of a sentence e.g. Mr. i.e. etc.

The macro suggested

\newcommand\etc{etc\@ifnextchar.{}{.\@}}

is not quite perfect since in the case (\etc more text) it produces (etc.more text).

I have seen a lot of authors who have made their own versions of the \etc macro, mostly variations on etc.\.

What macros for \etc, \ie, \etal, \eg produce the nicest results in the most situations?

Is this something too personal in taste to be solved in general?

Edit
Report

2 Answers

5

A technical challenge! We can avoid the problem of letters after spaces by looking at the catcode of the next character and seeing whether or not it is a letter; this can be done with the Latex3's expl3 macro \peek_charcode:NTF (my first expl3 code!):

\documentclass{article}

\usepackage{expl3}
\ExplSyntaxOn
\newcommand\latinabbrev[1]{
  \peek_meaning:NTF . {% Same as \@ifnextchar
    #1\@}%
  { \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
      #1.\@ }%
    {#1.\@}}}
\ExplSyntaxOff

%Omit final dot from each def.
\def\eg{\latinabbrev{e.g}}
\def\etal{\latinabbrev{et al}}
\def\etc{\latinabbrev{etc}}
\def\ie{\latinabbrev{i.e}}

\begin{document}

Maybe a list, \eg, a, b, c, and d.  Which is to say (\ie) a, b, \etc.  Consider Knuth, \cf The TeXbook.

\end{document}

Jukka's advice I think is sound, though: I'd say the problem Will works around with his \etc macro we should see as a bug in Tex's implementation of double spacing (Will Robertson should ask for his cheque): if you know the bug is there, you can workaround it directly by putting in \@ in cases such as ".)", or you can have tricky code that means you don't have to think in this case, but you have added complexity to the way you typeset which is not going to work for you with the next unexpected glitch, one you probably have introduced yourself.

Postscript Previous version fixed, thanks to Joseph Wright noticing a stupid error at tex.stackexchange.com.

answered 2010-07-19T22:28:39.547
0

All LaTeX commands eliminate space after them. If you want a space, you need to escape it:

\etc\ and more

This is necessary, because you need to be clear where the command name ends. \etcno space cannot be correctly interpreted.

answered 2010-07-19T15:40:37.643

Your Answer