Italic-formatted text followed by roman (upright, regular) text can cause typographic problems: the leaning italic letters collide with the upright roman in front.

Italic f is particularly problematic, especially as the last letter in a parenthetical comment (what if) where it will almost always collide with the closing parenthesis.

But italic is not the only culprit: italic t‘s, d‘s, and even question-marks ‘?’ can all cause problems, as you may be able to see, depending on the font you happen to be reading this post in.

The challenge is therefore obvious: How to write an InDesign script to find all such collisions?

I think the non-scripter’s assumption would be to write a simple script to find all instances of italic text followed by roman text. Theoretically that makes sense.

However, there are a couple of problems with such a simplistic approach:

First, different fonts call italics by different names: oblique, slanted, italic, italics, etc.

Secondly, to go through an entire book-worth of text to find such sequences would be extremely slow. Too slow to be practical.

So a different approach must be found.

The script below offers a different solution to these problems:

First, to deal with the speed issue, not all instances of italics followed by roman are sought. Instead, in the first line of the script, an array is set up containing problematic pairs of glyphs. These glyphs can be anything: letters, symbols, numbers. The idea is to build up a list of potentially problematic pairs of characters. The list can be expanded ad inifinitum: just add more pairs to the array.

The advantage of creating such an array is that InDesign’s built-in search can be invoked to find each of those specific pairs, and only those pairs, and this is much quicker than searching through all the text in the document.

Secondly, regarding the different names by which italics can be called, the script takes the following approach: Rather than search specifically for italic styling followed by regular styling, the script marks (with strikethrough) all instances where the font style used for the first glyph in each pair contained in the array is different from the font style used for the second glyph. So the script is not searching for particular styling, just for different styling. Although this may result in some false positives, in my experience (and I have been using this script for a while) they are not too numerous to be a serious problem; the advantages of this approach certainly outweigh the disadvantages.

How to use the script

  1. Modify, if necessary, the first line of the script (pairs = etc.) to include any other potentially problematic pairs of letters, that is, letters that may collide if the first of the pair is italics, and the second regular. I’ve included some common problematic pairs to get you going.
  2. Run the script. The script marks all such pairs with strike-through formatting.
  3. When it finishes, open InDesign’s regular text find/change. The script sets up the find options to find strike-through, so all you need to do is click on “Find Next”. You will be taken to the first instance of potential roman–italic collision.
  4. Fix the collision according to your best typographic sensibilities. Move on to the next marked pair by again clicking on “Find Next”.
  5. Repeat until you’ve dealt with everything.
  6. Finally, don’t forget to remove the redundant strikethrough formatting.

The raw script

// BS"D
// Colliding Pairs
// An InDesign script by TAW (c) 2015 Id-Extras.com. All rights reserved.
// Free to use, but may not be commercially distributed
// Please do not delete this copyright notice
var pairs = ["l’", "f’", "f?", "l”", "d’", "d”", "t’", "t”", "f”", "f)", "f]", "M)", "d)", "d]", "f!", "g!", "?”", "(g"];
var myDoc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.caseSensitive = true;
var myCounter = 0;
for (var i = 0; i < pairs.length; i++){
   var pair = pairs[i];
   app.findTextPreferences.findWhat = pair;
   var myFinds = myDoc.findText();
   for (var j = 0; j < myFinds.length; j++){
      var myFind = myFinds[j];
      if (myFind.characters[0].fontStyle != myFind.characters[1].fontStyle){
         myFind.strikeThru = true;
         myCounter ++;
      }
   }
}
app.findTextPreferences = null;
app.findTextPreferences.strikeThru = true;
app.changeTextPreferences.strikeThru = false;
alert("Found "+myCounter+" potential collisions!");

The script as a file

Click here to download.

I hope you find this little script useful. Thoughts and comments are welcome below.