I was just reviewing my "capitalization standards" for titles and such and was wondering if there's a macro to do the same thing I'm forced to do by hand nowadays. My personal rules (feel free to disagree/comment on them) are as follows:
- the first letter (a number is a letter too for the sake of these rules) always gets capitalized,
- every word gets capitalized individually,
- the exception to the rule above (and just the rule above) are closed class words such as prepositions and the like.
In other words: I'd like a capitalization command (like \MakeUppercase
) that will capitalize every word not included in a list of words and that will always capitalize the first word of its argument.
Doable?
PS: one such "list" of closed class words (also known as "function words") can be found here.
Best Answer
Won't work with UTF-8 (unless XeLaTeX or LuaLaTeX are used).
It won't work with UTF-8 in
pdflatex
because\MakeUppercase
will apply only to the first byte of a possible two, three or four byte combination (for Western languages probably only two). For that to work one has to feed the whole block of bytes to\MakeUppercase
.To be clearer: when we say
\MakeUppercase
, LaTeX will uppercase the argument; in general the call is\MakeUppercase{word}
; here we're saying instead\MakeUppercase#1
(without braces), so only the first token (usually a character) will be uppercased; here's where it will fail with input such as\'ecole
: the token passed to\MakeUppercase
would be\'
, which it doesn't know what to do. Usingécole
(and a one byte encoding such aslatin1
),\MakeUppercase
will processé
and give the correct result.With UTF-8 this would fail: what we see as
é
on our screen when writing a LaTeX document is actually two bytes (C3 and A9, foré
) and again\MakeUppercase
would be passed only the first one. So a more complex routine is necessary.In order to have this work with
pdflatex
and UTF-8, the definition of\CheckInList
and\CapitalizeFirst
above can be changed into the followingHowever accent commands are not allowed (they aren't also in the other version).
UPDATE
After a few years, here's a better implementation, thanks to new
expl3
features; it works for all engines.