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.

  • 1
    Check out this question: tex.stackexchange.com/q/332/575. In particular, I'd say the answer is "no". There are several packages (ifthen, etoolbox, maybe others) which provide general conditional commands; TeX itself has many, but they are hard to understand. Search the questions on this site for more than one that ask about these.
    – Ryan Reich
    Dec 6, 2010 at 17:50
  • 16
    This is more complicated than just checking for consonant/vowel, as the the selection of a/an is phonetic.
    – Caramdir
    Dec 6, 2010 at 18:06
  • 9
    Caramdir's quite right, don't do that: A unicorn, an ugly unicorn, a horse, an hour. Dec 6, 2010 at 18:17
  • 3
    Exact duplicate of: stackoverflow.com/q/4233707/505649 Dec 6, 2010 at 20:01
  • 2
    People even disagree over "a" or "an" hotel, which apparently depends on your pronounciation of the 'h'... Dec 6, 2010 at 20:32

2 Answers 2


I agree with Caramdir that checking for a vowel is insufficient for determining which article to use. Nonetheless, if you really want to do this, this is how I will do this in ConTeXt.

  {\doifinsetelse{#1}{a,e,i,o,u}{an}{a} #1}

% Alternative definition, but a bit slower
% \def\placearticle#1%
%   {\doifinstringelse{#1}{aeiou}{an}{a} #1}

\placearticle apple,
\placearticle orange,
\placearticle banana,
\placearticle strawberry

I don't know which LaTeX package provides functionality similar to \doifinsetelse or \doifinstringelse.


To do this in plain TeX (works in LaTeX too) I would say something like:

\newtoks\vowellist % make a new empty token register named vowellist
\vowellist{\\a\\e\\i\\o\\u} % put vowels in it delimited by \\
                            % Redefining \\ will allow us to map over the list.
   \edef\tempa{#1}                % In case #1 is a command, fully expand it.
   \def\tempb#1#2.${\let\tempc#1} % make \tempc the first symbol of tempa
   \expandafter\tempb\tempa.$     %
   \def\\##1{\ifx\tempc##1 n\fi}  % Check if the current vowel is the same as the letter in \tempc
        % Map \\ over \vowellist 
   \tempa                      % Insert #1; use tempa to make sure #1 isn't evaluated twice.

This should work with any reasonably sane input, but I haven't te

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .