Custom kerning in InDesign (GREP workflow writeup)

nina's picture

Problem:

Solution:
While InDesign CS4 doesn't feature a kerning table, it does support GREP styles, which can be used to apply custom kerning values to extended text settings. Because I haven't seen this documented in a truly helpful way (not that I've looked too hard) and some peeps have asked about it, here's a quick writeup of a possible procedure. Maybe if some of you have corrections or suggestions how to do it better, we can put together a killer workflow. (Scuse the atypically looong post… I figured Typophile was still the best place to put this.)

So in the text above, note the absence of a kern pair for «Tó» while «To» looks fine.

Step 1: Kern the pair manually, once.

.
.
Step 2: Define character style for kern pair.
It seems that this has to be done in a roundabout way, since custom kerning values cannot be entered in the Character Style dialog.
It's interesting to note that while InDesign only lets you insert a kerning value when the cursor is between the 2 glyphs in question, it seems that the kerning value is treated as a property assigned to the first glyph in the pair. Thus, by selecting the first one of these 2 glyphs and then defining a «New Character Style» you will be able to make a character style that contains this kerning value. (You want to pay attention that it doesn't contain anything else.) I'd name it something telling, like kern_T_oacute in this case.

.
.
Step 3: Apply this Character Style to all occurrences of the pair in question, via GREP.
Make sure your text cursor is in one paragraph in question, then select «GREP Styles» from the Paragraph (not Paragraph Styles) palette flyout. Hit «NEW GREP Style…» and specify to assign the kern_T_oacute character style in case this condition is met:
T(?=ó)
The important thing is to only assign the character style to the "T" (as the kerning value is treated as a property of the first glyph in the pair), but only if it is followed by "ó" – this condition is what the (?=ó) specifies as a Positive Lookahead (cf. Adobe Guideline on Metacharacters). If you want to include other possibilities too (like odieresis), you can specify a class of possible second glyphs in brackets, like in the screenshot below.
When you hit Preview this baby should now automagically apply to all «Tó» pairs in the paragraph:

.
.
Step 4: Redefine Paragraph Style to include GREP style.
Your Paragraph Style will now have a "+" added because the GREP style was added. Select «Redefine Style» to add the GREP style to the Paragraph Style definition. Now the custom kern pair should automatically be applied in all paragraphs based on this paragraph style. (Note that you'll have to do this for all paragraph styles you need the kern pair in.)

Comments, suggestions, please shoot. I will add that in my case I actually solved it differently (via GREP Search&Replace) but found out later that this way would have been much more elegant.

William Berkson's picture

A number of book designers have complained about the lack of global kerning adjustment in InDesign, which is apparently possible in Quark XPress. This creates that capability in InDesign. Very nice, thanks!

Now all Adobe has to do is build an interface for this :)

Tomi from Suomi's picture

Now that is clever, Nina. Thanks.

oldnick's picture

Back in Ye Olden Tymes, when "typesetter" was a profession, kerning was generally accomplished with a search-and-replace function after the text had been keyed in. Additions or exceptions to the standard pairs could easily be added to the swap file, so adjustments like this were no big deal. Sadly, the advent of desktop publishing and "idiot-proof" interfaces removed a certain level of control. This is one reason why--until Corel fouled up the works with Version 8--I always preferred WordPerfect to Microsoft Word: one had access to the underlying code, and global changes were easily accomplished with search-and-replace.

Other things I miss from the days of yore: controllable vertical justification (one could add more or less space between selected elements) and Auto-tabs (the longest entry in an ordered or unordered list could be centered, and all other entries flush left with it). Sigh...

Theunis de Jong's picture

Hey, Nina, great trick! I do have two additional remarks:

To act upon each and every 'o'-like character, accented or not, you don't have to list the exact list. You can still use it if you need absolute control on which characters to include, but if you are positive you want to do this on all 'o' characters, you can use a character class: the command [[=o=]] will match on all o's, with and without accent. The only drawback is that a capital Oh is also an equivalent of plain 'o', so you have to find a way to exclude them. Well -- you can add another lookahead to include only lowercase characters!

T(?=\l)(?=[[=o=]])

The first lookahead asserts only lowercase characters may follow; the second picks up all equivalents of plain ohs.

The other thing is: Unfortunately, GREP styles are oblivious to formatting, so this same trick will be applied to italic, bold, and bold italic, and on every font as well. If you are applying italics formatting though a paragraph style, you can create a new character style for "italic T o" kerning, but for plain text you still have to apply manually workarounds to non-plain text.

Given this constraint, it's still a great trick. I agree: it's about time Adobe copied the Quark Kerning Pair Editor. And does anyone else think it's weird you cannot enter a Kerning value in a Character Style definition? You can only insert one using Nina's trick: first apply, then "Define New Character Style". And if you got it wrong, you cannot edit it. (Perhaps it can be done with a Javascript -- I'll have to check that.)

---

† Malcolm McLaren (22 January 1946 – 8 April 2010) ...

Theunis de Jong's picture

(Perhaps it can be done with a Javascript -- I'll have to check that.)

Checked, and the answer is "No". Text objects in general have properties "kerningMethod" and "kerningValue", but Character styles only have "kerningMethod". Thus adding another riddle: how can it get defined with a certain value in the character style if that can't contain the value ...?

---

† Malcolm McLaren (22 January 1946 – 8 April 2010) ...

nina's picture

Thanks for the responses. I'm glad if this is helpful to some.

Theunis, thank you very much for the input! I'm actually quite a newbie at GREP so these more advanced syntax constructions are quite illuminating.
Using that blanket character class wildcard (like =o=) seems like a bit of a dangerous technique from a type design perspective no? I mean considering that say the oacute and odieresis might need quite different kerning values when following a "T", depending on the design.

"Unfortunately, GREP styles are oblivious to formatting"
Yes, this is really quite a bad constraint. I should have mentioned it. It's pretty stupid actually because if you do a GREP search then you can specify formatting (like in normal searches),* just not for GREP styles. Hmph.
(* I'm not quite sure, but there seems to be a problem here too: In the GREP Search, if any formatting is specified, not only the search term proper needs to match this formatting at but also the Lookahead too. Which is exactly a problem for this technique, since you'd only want to match the first glyph of the pair in terms of formatting. So if you have a pair like say "Ví" and the "í" already has a custom character style applied, and you search for "V(?=í)" with standard formatting it's not going to be found. :-\ )
The interface for these functions definitely needs refining, and I don't only mean a nice clickable GUI here, although that'd be rad too.

"does anyone else think it's weird you cannot enter a Kerning value in a Character Style definition? You can only insert one using Nina's trick: first apply, then "Define New Character Style""
I'm thinking my "trick" might be a loophole. This is likely not meant to be done this way (or at all). Otherwise there would be a better interface for it. But I might be wrong.

"And if you got it wrong, you cannot edit it."
Well you can edit it locally in one instance and then "Redefine Style". Which works, but is also a workaround. OK, hack. :-)

Now of course the big question to the Adobe folks is, will any of this be improved in CS5?

Theunis de Jong's picture

Correct -- the [[=o=]] does treat all variants of oh the same, and if you want to use different values for different ohs, you need to specify them in a [..] list.

Now of course the big question to the Adobe folks is, will any of this be improved in CS5?

It sure could use an overhaul. How many days left on that counter? (Checking ...) 3d 15h 25m 42 s ...

(The main topic on http://cs5launch.adobe.com/ appears to be a complete new set of Flash stuff, fresh out of adobe.labs. We can only hope not all of their programmers have been working on that.)

Tomi from Suomi's picture

Nick-

Ye olden days are not all gone. While working with Finnish edition of Schott's Miscellany books me and publishers editor spent some hundreds of hours filling the paragraphs to avoid loose last lines. In those books most of the paragraphs needed to be truly rectangular, with no ragged last line. That took us a while.

David W. Goodrich's picture

A very nice trick, though I'm still drawn to Peter Kahrel's solution, which puts all the changes in what amounts to a single kerning table covering a font's styles. Kahrel's script can thus automate kerning for an italic f followed by a regular closing parenthesis. But perhaps ID7 will make all such workarounds unnecessary.

David

nina's picture

Nice link! Thank you for sharing.
I wish there was a bit more documentation – I'd love to know how this script is implemented (JavaScript, after all)?

David W. Goodrich's picture

It runs as a "Adobe JavaScript Binary file": kern.jsxbin. As the author notes in his link on installing scripts, *.jsxbin files cannot be modified.

ocular's picture

Has anyone seen Kahrel's ebook (eDoc) on GREP?

Theunis de Jong's picture

Ocular: I've heard of it -- it has frequently been called "the best there is" for InDesign users, because it's specially targeted at using GREP in that environment. Peter Kahrel is a regular poster on Adobe's own InDesign Forum and sure knows a lot on the effective use of GREP with ID.

And for its price -- under a tenner -- it is good value for money.

ocular's picture

Thanks, Theunis! Yeah, for ten US dollars, it isn't much of a gamble.

By the way, there was a mention of an InDesign plugin called Cool Kerning in this thread from 2006. Anyone tried it?

EDIT: OK, now I found two more threads mentioning or discussing Cool Kerning: http://typophile.com/node/7608 and http://www.typophile.com/node/971

William Berkson's picture

I see on one of those threads that global kerning in InDesign is a thing that Thomas Phinney says is upcoming in future versions of InDesign—the post is 2003! I wonder what happened.

moraitis's picture

Do you know of a script that could export a text file detailing all the custom kerning values for each font as specified in an InDesign CS5 file? This would be the reverse of a script I found on Peter Kahrel's site that allows all the kerning pairs to be modified using a text file. (http://www.kahrel.plus.com/indesign/kern.html)

I am working with a client on modifying a custom font used in a book. We kerned the font as used in the English version of the book, so the InDesign CS 5 file has lots of kerning information. Now that the publisher would like to publish in several other languages, we would like to take that kerning information and use FontLab to set up the kerning pairs within the font. So when the publisher translates and flows the new text into the file, we will not have to kern the whole book again.

Any help or advice you could offer would be warmly appreciated.

julietcw's picture

I was so excited to find this! I just tried it in our CS5, but when I went to create the character style, instead of getting a specific manual kerning measurement, it says [None] + pair kern method: Optical. Is this one of the "improvements" of CS5, to remove even that little bit of kerning adjustment functionality, or have I done something incorrectly?

nina's picture

Huh, why Optical? That's odd. Did you set it to Optical?
I don't have CS5 sadly so can't test. I'll be interested to hear what others can say.
I was sure hoping this would get easier, not harder, in newer versions! :-\

Theunis de Jong's picture

Moraitis, if this is still an open question, here is a script to harvest custom kerning pairs inside an InDesign story. Save as a plain text file as "harvestKerning.jsx" in your InDesign scripting folder, click the text cursor in the running story that you want to harvest from, and run the script.

It might run very slow as it has to inspect each and every single character ... perhaps you should try it first on a small amount of text.

If the script encounters a manually kerned letter pair, it looks in its list if it already has encountered these before *with the same value*. If not, it will add them to the list. So beware! Some letter pairs may occur more than once in the list.
The custom kerning pairs and their value are written into a file named "kerning.txt", which will be stored in your local My Documents folder.

Enjoy.

results = [];
text = app.selection[0].parentStory.characters;
for (i=0; i<text.length-1; i++)
{
if (text[i].kerningMethod == "Manual")
addToList (results, [ String(text[i].contents)+String(text[i+1].contents), text[i].kerningValue] );
}
myFileObj = new File(Folder.myDocuments+"/kerning.txt");
if (myFileObj.open("w"))
{
myFileObj.write(results.join("\r"));
myFileObj.close();
} else
alert ("unable to create file kerning.txt");
function addToList (list, entry)
{
var i;
for (i=0; i<list.length; i++)
if (list[i][0] == entry[0] && list[i][1] == entry[1])
return;
list.push (entry);
}

Syndicate content Syndicate content