Another GREPping story

For those stalwart folks who follow this blog, you know that I am a GREP enthusiast. I use it as often as possible; I treat it as mental calisthenics; I look for opportunities to GREP my way out of every problem.

For those new to the topic, GREP is a search method that is found in some of the best word processors (Word does not have it); InDesign has it. Text Wrangler does. My favorite, Tex-Edit Plus has it, but unfortunately that program is not compatible with the latest operating system from Apple: Lion. I’m sticking with Snow Leopard until I can solve this problem (I’m teaching myself GREP in Text Wrangler).

GREP is an acronym for Graphical Regular Expressions. It has been around for decades, and was originally found in UNIX. UNIX purists spit at InDesign’s unconventional application of GREP, saying that it’s not pure GREP. I don’t care; it’s delightful.

GREP allows you and me to search for abstract items, as opposed to searching for a specific word or combination of letters. The idea is that you an search a large document, looking for the word “Chapter” followed by any number, followed by a carriage return, and change its Paragraph Style to make it a Chapter Head.

Or, you can take a list of names that is last-name-first, and make it first-name-first. I do this a lot with roll sheets at the University.

My students love GREP because they work a lot with book-length manuscripts, building them into finished books for print publishing and ePub export (more on that in a blog tomorrow). One of my students approached me yesterday to solve a problem with Pride and Prejudice. Her manuscript is over 700 pages in length, and she wanted to know if GREP could style just the chapter heads as I described above. Click-click, beep! It was done. I enjoyed those clicks and beeps immensely!

Just minutes later (this is my Advanced Typography class, so it’s in the heart of their studies this time of year) another student approached me to solve a problem I have encountered before. The text she is working on has emphasized strings in ALL CAPS. She wants them in Italics, lower-case.

InDesign has a menu item for changing case, but it can’t do it as part of a find-and-replace string (which is a shame).

I searched Adobe’s web site, and the Interwebs in general, and in a few minutes I found a nice Javascript written by Thomas Silkjær, a fellow in Denmark that can change CAPS into lower-case, or vice-versa. It also does Small Caps.

The best part of this Javascript is that it uses GREP as its search criteria.

I downloaded the Javascript, which arrived in Firefox as a text file. I saved it, changed its suffix to .jsx, then stuck it into the Scripts folder in InDesign (I didn’t even have to restart InDesign). In a few seconds it appeared in my Scripts panel in InDesign, and I got it working just a few minutes later.

The manuscript is long, and it has many ALL CAPS sections in it. The GREP function for finding all caps is:

…which translated into English is “Find any upper-case character one or more times followed by a space, and store it in a variable called $1.”

I entered this into the script, and clicked OK, and it instantly converted almost all the ALL-CAPS into lower-case letters. When I say almost all, I mean it missed those words that are hyphenated into a compound-expression, words followed by a comma, or a period.

The fix for that was easy. I modified the GREP search string to:

…which means: “Find any upper-case character one or more times, followed by either a space, a comma, a hyphen or a period, and store it in a variable named $1.”

This solved the problem for the manuscript.

Except it also changed all the article I “words” into lower-case i’s. Oops! I suddenly became i.

I fixed those quickly with a standard text search “look for space followed by lower-case i, followed by space, replacing with space-Cap-I-space.”

But this left my GREPping mind unsettled, and I sweated all night thinking about a more elegant solution.

Then I spent far too long today trying to figure out how to use GREP’s negative look-ahead tool to say, “Find one or more cap letters – other than the letter I – followed by a space, but followed by a comma, etc., and change it into lower-case.”

So far I haven’t succeeded in making this work. BUT I PROMISE I WILL (caps intentional).

When I do, I will post it here.

Happy grepping to you!

Thank you to Thomas Silkjær for his script. I made a donation on PayPal for his work, though I couldn’t read much of the Danish as I did it. Is 40,000 Kroners a lot?

About Brian Lawler

Brian Lawler is an Associate Professor of Graphic Communication at California Polytechnic State University, San Luis Obispo. He is currently Visiting Professor at Hochschule München where he teaches in the Druck- und Medientechnik program. He writes about graphic arts processes and technologies for various industry publications, and on his blog, The Blognosticator.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *