A / an replacement in LaTeX

I was wondering if there is a conditional command that I can use in latex (for example, \ ifthenelse) that would allow me to use the word "a" in one case, and in the other case to use the word "an" on whether the following starts word with a vowel.

+7
latex
source share
3 answers

TeX provides a simple if comparing letters. The following will work if you do not 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 force "an" like this, but you should be able to suppress it by writing \ AOrAn {} university.

(Edited for remarkable exceptional cases.)

+3
source share

This will not work at all, because the decision to use a or an is based, not mechanically, on the letter that follows the article, but on its pronunciation. Thus, "uncle", but "university" and "honor."

+6
source share

Here you have examples of using conditional expressions in Latex.

+1
source share

All Articles