开发者

a/an substitution in LaTeX

I was wondering if there is a conditional command that I can use in latex (e.g., \ifthenelse) that would allow m开发者_开发百科e 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.


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'.


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.)


Here you have some examples to use conditionals in Latex.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜