I am writing a small book and try to build up an index reference. To make it a little easier I wrote a small script that enables my to type a word and also add it to the index:


However this results in words added to the index that don't start with a capital letter. This makes the index looks a little bit dirty. Is there a way to generate a string out of parameter #1 that switches the first character to its uppercase counterpart and leave the rest of the string the same?

  • 1
    Have you read this: Command to uppercase the first letter of each word in a sentence? – Werner Sep 27 '11 at 18:39
  • Thanks! Nearly the same, but it looks all words get an uppercase character, I will try to convert the script that only the first character gets an uppercase. – Willem Van Onsem Sep 27 '11 at 18:49
  • furthermore something goes wrong when this script tries to manipulate strings with mathematics inside (I expect the $-signs generate some problems) like $n$-army problem. – Willem Van Onsem Sep 27 '11 at 19:01

I would define two commands (actually one command with a *-form):

    \edef\x{\endgroup\noexpand\index{\the\toks0 \the\toks2 }}\x

For entries such as $n$-entry you would use \toindex*[nentry]{$n$-entry}, for word you can use \toindex{word}. The optional argument can be used in either case.

For \toindex* the optional argument is used for collation; it's actually more than optional: makeindex would sort \index{$n$-entry} among symbols.

For \toindex the optional argument can be used for the cases when the word to be indexed is special, for instance


However, I don't see the necessity to capitalize words in the index. Look at the TeXbook, for an example. :)

  • Well it's not that much the fact that an index starts with a capital letter, but more the fact that when you use an item twice (with lowercase and uppercase), two items are added to the index... – Willem Van Onsem Jan 27 '14 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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