TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 '10 at 17:50
This is more complicated than just checking for consonant/vowel, as the the selection of a/an is phonetic. – Caramdir Dec 6 '10 at 18:06
Caramdir's quite right, don't do that: A unicorn, an ugly unicorn, a horse, an hour. – Hendrik Vogt Dec 6 '10 at 18:17
Exact duplicate of: stackoverflow.com/q/4233707/505649 – Ulrich Schwarz Dec 6 '10 at 20:01
People even disagree over "a" or "an" hotel, which apparently depends on your pronounciation of the 'h'... – Yossi Farjoun Dec 6 '10 at 20:32

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.

share|improve this answer

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
   a\the\vowellist\            % 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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.