Adjust kerning (CS3 and later)

It's not possible in InDesign to adjust a font's kerning table, which is a shame because that's an area where even the best-designed fonts leave some space for improvement -- and these improvements are relatively easy to implement.

Apart from possible shortcomings in a font's kerning table, a limitation of the traditional approach to kerning is that the scope of a font's kerning table is just that font; it's not possible for a font to define kerning between its own characters and characters from another font. This means that nothing can be done about clashes of pairs such as an italic f followed by a roman closing parenthesis and the gaping space between letters such as P, V, and W and a following subscripted letter or digit.

The script

The script described here deals with these problems: it allows you to create tables that specify kern values not only for characters within a font, but also for characters set in different font styles. The script collects the names of the typefaces ('font families') in a document, then reads the user-defined kerning data from a file and applies these data to the document.

Kerning data are stored in a text file. The structure of such a kern data file is simple:

===Regular
Ws	-60
-T	-100

The first line denotes a font style; the script identifies font styles by the three = symbols. Under this heading follow any number of kern instructions. Each instruction consists of a character pair (Ws and -T in the example) followed by a tab, followed by a kern value: positive numbers for positive kerning (loosening), negative values for tightening the space between two characters. The kern value is applied to the space between the two characters in the pair. (You can type more tabs between the characters and the kern value to line up the kerning values and make the file more readable.) Unicode characters can be entered either as characters (just copy and paste the characters from inDesign) or by their unicode numbers, using the format \x{0158}.

A font style followed by any number of kern instructions make up a section. You can add more sections to cover other font styles and to deal with characters from different font styles. To kern character pairs in another font style, just list these under what's already in the file:

===Regular
Ws	-60
-T	-100


===Italic
T-	-135

The script ignores empty lines, so you can use them freely to make the file more readable.

To adjust the kerning between two characters from different font styles, type the two font styles after each other separated by a tab:

===Italic	Regular
f\) 35

In this example, the kerning between an italic f and a roman ) is set to 35. The order in which you type the names of the font styles is important: turn them around in this example and the script will try to find a roman f followed by an italic ). Note: the closing parenthesis must be entered as \). Other characters that need to be preceded by a backslash are ()[]{}.~$^+=?.

Spacing between full-size characters and super-/subscripts is dealt with similarly:

===Regular sub
P1	-80
P2	-80
P3	-80


===Italic super
r1	30
r2	30

Use these words exactly as given here: sub for subscript and super for superscript. Note that any styling for the super- and subscripts is ignored: Regular and Italic in the two examples apply only to P and r, respectively. Here, super and sub match characters to which the normal super- and subscript formatting has been applied. To match characters formatted with OpenType superscript (or superior), use otsuper and otsub. (See below for a full list of keywords.)

Another type of format recognised by the script is the figure style (tabular/proportional oldstyle/lining). For instance, this section fixes the space between 7 and a following en-dash (~=) or dot (\.):

===tabular_lining	Regular
7~=	-20
7\.	-100

The forms of the four figure formats to use in the script are proportional_lining, proportional_oldstyle, tabular_lining, and tabular_oldstyle. Notes: (1) figure formats are handled only in roman (Regular); (2) figure formats are recognised only when the format has been set explicitly (locally or in styles): "default formats" are not processed.

Before continuing with more powerful kerning entries, we'll first deal with the names and locations of the kern data files.

The kern data files

Kern data files are text files. They're are best kept in UTF-8 format (as the example, below). The name of the file is constructed around the name of a font family. If the script finds Helvetica in a document, it wants to read kerning data from a file called kern_Helvetica.txt. That's the way to name files: kern_ followed by a font-family name followed by the extension .txt. Capitalisation can be ignored, but spaces, hyphens, underscores, etc. must be used exactly as you see in the font's name in InDesign. As to location, the script looks in the script folder for the data files.

Note: there's no need to have a data file for every font family in a document: the script just ignores font families for which it can't find a data file; when it finishes it does display a list of font families that it couldn't find a data file for.

Advanced searches

You can use GREP expressions in the search patterns in a data file. Use the standard InDesign format for these expressions. If you know InDesign's GREP formalism you needn't read any further.

If you're not familiar with InDesign's GREP, here are a short outline and some simple examples to get you started. As you'll see, you don't need much knowledge of GREP to make your data file much more flexible.

Take this fragment from a data file:

===Regular sub
P1	-80
P2	-80
P3	-80


===Italic super
r1	30
r2	30

This says that in the fontstyle Regular, P and following 1, 2, or 3 should be kerned together a bit; and that italic r and a superscript digit need some more space than what they get by default. In fact, this goes for all dgits, and we can use the catch-all \d for that (\d stands for 'any digit'). The fragment can then be reduced to this:

===Regular sub
P\d	-80


===Italic super
r\d	30
Here are some other character classes (or 'wildcards'):

\l (slash and lower-case L): any lower-case letter
\u any upper-case letter
\w any letter or digit

You can also define your own character classes. Anything enclosed by square brackets is considered a character class, and this is a flexible and useful tool. Here are some examples:

===Italic	Regular
[rv][:;]	80


===Regular sub
P\d		-80
[VWY][\d\l]	-60

The first line here makes the script look for an italic r and v followed by a roman : or ; -- the search pattern in this one line finds four different instances: r:, r;, v:, and v;. The second instruction tells the script to find P followed by a subscripted digit; the third line reads "find V, W, and Y followed by a subscripted digit or a subscripted lower-case letter".

Kerning series of identical characters

To kern series of of identical characters, such as 111111, you need to use a search string like the following:

1(?=1)	20

If you search for 11, you end up with 1 11 1 11, in other words, every other par of 1s is ignored. By using the so-called lookahead construction (?= ) you avoid that problem.

For more information on how to use GREP searches, see Grep in InDesign.

For an example of a kern data file and more examples of search criteria, see the file kern_Minion Pro.txt that I use myself. If you have any problem with data files or how to define certain search criteria, drop me a line.

Keywords

The keywords you can use are of two types:

1. Any font style associated with a typeface can be used in the script. To see which font styles a typeface has, select some text in an InDesign document and look in the Character panel (Ctrl/Cmd+T).

2. These special keywords can be used as outlined above:

super
otsuper
sub
otsub
proportional_lining
proportional_oldstyle
tabular_lining
tabular_oldstyle

Resetting selected kern pairs

You might want to reset certain kern values to metric ("automatic"). For instance, if you used a GREP expression that matched more than you had thought, you might want to undo the effect of that particular expression, refine it, and run the improved version.

To reset an expression, simply repeat it and use M as the kerning value. Suppose you used this line in the data file to reduce the space between lower-case letters and upper-case V and W:

===Regular	Regular
[\l][VW]	-60

You find that this doesn't work well (naturally) because of the ascender letters so you want to undo it. All you need to do is to use this line in your data file:

===Regular	Regular
[\l][VW]	M

Instead of the kern value you use M (m also works). You could include this line in your data file, but as this is a one-off it may be better to create a separate, temporary, data file.


Version history

1 Jan. 2014: Added a note that to kern series of identical characters such as 11111, you need to search 1(?=1). Added the option to target a selected story (in addition to the active document or all open documents).

29 Oct. 2011: Fixed bug that sometimes caused confusion among typefaces.

17 Nov. 2010: Fixed bug that prevented the kerning of different styles.

4 Nov. 2010: Added possibility to reset selected kern pairs (proposed by Stephan Möbius; see here).

16 June 2010: Fixed issue with the sample date file (kern_Minion Pro.txt).

24 May 2010: Added support for OpenType superior and inferior.


Useful script? Saved you lots of time?

Consider making a donation. To make a donation, please press the button below. This is Paypal's payment system; you don't need a Paypal account to use it: you can use several types/brands of credit and debit card.

Peter Kahrel's paypal account

Download script

Back to script index

Installing and running scripts

Questions, comments? Get in touch