Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to define macros \etc \ie in latex

Tags:

latex

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?

like image 526
Niall Murphy Avatar asked Jul 19 '10 15:07

Niall Murphy


People also ask

Can you define macros in LaTeX?

Like any self-respecting programming language, LaTeX lets you define your own macros. LaTeX has a \newcommand command that you can use to define personal macros.

How do you write eg in LaTeX?

id est and exempli gratia (i.e. and e.g.) To prevent LaTeX from adding space after the last period, the correct syntax is either " i.e.\ " or " e.g.\ ", or else " i.e., " and " e.g., " with a comma. The comma is interpreted by LaTeX as part of a sentence, since the period is not followed by any space.

How do you write etc in LaTeX?

Just use etc. \ in the middle of a sentence and etc. at its end. Or \&c.

What does \@ mean in LaTeX?

Show activity on this post. For novices, a simple mnemonic rule is: \@ is an invisible (zero-width) lowercase letter. LaTeX considers a sequence <lowercase letter> <punctuation sign> <space> as end of a phrase and adds extra space for readability: in That's all. Thanks , LaTeX adds more space after all. .


2 Answers

Earlier I used macros for "et al.", etc., but nowadays I would discourage people from defining that kind of macros.

One problem is what you already observed: it's surprisingly tricky to get the definitions right so that they handle all special cases correctly (including the interactions with other packages – e.g., those that re-define the "\cite" command and tweak spacing before references).

But more importantly, even if you have a bunch of macros that suit your needs and you know how to use them, your co-authors are likely to be confused with exactly how to use your macros correctly in various special cases.

Hence I'd recommend that you avoid macros for trivial things such as "et al." and simply spell out everything by using standard Latex markup. After all, most cases don't need any special handling ("e.g." is often followed by a comma; "et al." is often followed by "~\cite", etc.), and whenever special handling is needed, all Latex users should know how to use commands such as "\ " and "\@".

like image 84
Jukka Suomela Avatar answered Oct 05 '22 11:10

Jukka Suomela


In CVPR's style package, it is defined as:

\usepackage{xspace}  % Add a period to the end of an abbreviation unless there's one % already, then \xspace. \makeatletter \DeclareRobustCommand\onedot{\futurelet\@let@token\@onedot} \def\@onedot{\ifx\@let@token.\else.\null\fi\xspace}  \def\eg{\emph{e.g}\onedot} \def\Eg{\emph{E.g}\onedot} \def\ie{\emph{i.e}\onedot} \def\Ie{\emph{I.e}\onedot} \def\cf{\emph{c.f}\onedot} \def\Cf{\emph{C.f}\onedot} \def\etc{\emph{etc}\onedot} \def\vs{\emph{vs}\onedot} \def\wrt{w.r.t\onedot} \def\dof{d.o.f\onedot} \def\etal{\emph{et al}\onedot} \makeatother 
like image 40
yangjie Avatar answered Oct 05 '22 12:10

yangjie