GREP Solution to Flawed Title Case Feature
Many people don’t realize that InDesign has a Change Case feature in the Type menu (or the Context menu). For example, you can select some text that someone TYPED IN ALL CAPS and change it to lowercase, Title Case (all words are capitalized), or Sentence case (only the first letter in each sentence is capitalized). Unfortunately, while Title Case is great for headlines, it misses the mark because it doesn’t follow a basic rule: that most conjunctions, articles, and prepositions (such as and, but, the, for, a, an, or, and nor) shouldn’t be capitalized.
Fortunately, GREP and Scripting guy Peter Kahrel wrote to us recently with a fun solution he had found to this Title Case problem based on CS3’s GREP searching feature:
- Select the text you want to change to Title Case.
- Open the Find/Change dialog box (Command/Ctrl-F) and switch to the GREP tab.
- Set the Search pop-up menu to “Selection” (so only the selected text is modified).
- Copy this (including the initial colon) into the Find what field
- Leave the Change what field blank, but click in the Change Format section and turn on the All Caps styling.
- Click Change All to make the change.
In Peter’s words:
The words to ignore are in the list separated by vertical bars, without their first letter: (f|he|nd?|o|y|rom|or) tells the GREP to skip of, and, in, on, to, from, and for (nd? matches an, and, in, on; the single letter o matches to). It may overgeneralise a bit in that ‘if’ and ‘she’ are kept in lower case, which might not be correct, but preventing that is complicated and makes the expression even more unreadable than it already is; and the errors it makes are so few that some manual editing doesn’t bother me. The GREP does two more things: it converts to upper case any word that follows a colon or a hyphen.
He then points out that you can add more words to the exclusion list by typing them — without their first letter, and separated by a vertical bar — in the list. For example, I noticed that “but” was being capitalized, so I added that by changing the grep expression to: :\s\l|[-\s]\l(?!(f|he|nd?|o|y|rom|or|ut)?\b)
Perfect solution? Far from it. In my newer example, the words “gut” and “shut” won’t get capitalized. But I still think it’s better than Adobe’s built-in solution. Thank you, Peter!
Remember that you can save your Find/Change queries, so after you set this up once, click the Save button (it looks like a floppy disk icon… how quaint!) and give it a name.
Note that you can find more GREP solutions in the Search feature on this page (upper-right corner); we’re also developing a list of GREP solutions here.