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 f 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
- 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.
- Run the script. The script marks all such pairs with strike-through formatting.
- 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.
- Fix the collision according to your best typographic sensibilities. Move on to the next marked pair by again clicking on “Find Next”.
- Repeat until you’ve dealt with everything.
- 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
I hope you find this little script useful. Thoughts and comments are welcome below.
Raphael Freeman
September 20, 2015 2:32 pmWhat would be very cool would be to able to remember how the problem was dealt with on a per font setting and then run it on future projects. Also you don’t deal with the opposite problem of an opening quote in roman before italics.
Admin
September 20, 2015 3:18 pmHi Raphael,
There’s definitely room for developing this script to something more comprehensive!
Your second point, though, of an opening quote in roman before italics, is easy. Just add the problematic pair to the pairs array at the beginning of the script.
The intention is that with time the pairs array at the beginning is expanded to include other problematic pairs.
In fact, it would be great if people could post pairs of letters they have found to be problematic, so we can all benefit!
Raphael Freeman
September 20, 2015 3:20 pmif you could create the script to be font-specific and you could somehow save the kerning applied, then I would gladly post my kerning pairs for the fonts that I use
IndiGREP
August 28, 2015 1:28 pmVery interesting. Pairs can be complete with Footnote Reference Marker, for example : f^F
Admin
August 28, 2015 1:37 pmGood point! You just reminded me that italics followed by footnote references are indeed often problematic. Thanks.
Abdur
August 28, 2015 1:15 amThis is a great idea. I will try it out.
I was wondering if this could be used to solve another problem. I imported a word document into ID and noticed that in some word, all the italics had not come through properly. Some roman words had a stray italic and some italic words had a stray roman lingering in it. I am looking for something that point these out.
Lori Holland
August 27, 2015 10:27 pmThis is great, it installed and worked perfectly. Thanks so much!
Lori Holland
Rebecca Evans
August 27, 2015 3:14 pmThanks for posting this–it’s tremendously helpful.