Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a/an substitution in LaTeX

Tags:

latex

I was wondering if there is a conditional command that I can use in latex (e.g., \ifthenelse) that would allow me to, in one case, use the word 'a' and in another use the word 'an' based on the whether or not the following word starts with a vowel.

like image 839
Raffi Khatchadourian Avatar asked Nov 20 '10 16:11

Raffi Khatchadourian


3 Answers

This won't work in general, because the decision to use a or an is based, not mechanically on the letter that follows the article, but on its pronunciation. Thus 'an uncle', but 'a university' and 'an honour'.

like image 89
Norman Gray Avatar answered Oct 15 '22 13:10

Norman Gray


TeX provides a plain \if that compares letters. The following will work, unless you do something like \AOrAn \myapplecommand, which will give unexpected results.

\documentclass{article}
\makeatletter
\newcommand\AOrAn[1]{%
  a%
  \@for\@vowel:=a,e,i,o,u,y,A,E,I,O,U,Y\do{%
    \expandafter\ifx\@vowel#1%
      n%
    \fi
  } % keep this space
  #1%
}

\makeatother
\begin{document}
\AOrAn apple, \AOrAn orange, \AOrAn banana.


an apple, an orange, a banana.
\end{document}

You cannot manually enforce an "an" like this, but you should be able to suppress it by writing \AOrAn {}university.

(Edited to take remark re exceptional cases into account.)

like image 29
Ulrich Schwarz Avatar answered Oct 15 '22 13:10

Ulrich Schwarz


Here you have some examples to use conditionals in Latex.

like image 1
kuszi Avatar answered Oct 15 '22 15:10

kuszi