1

Wondering if there is any compression / expansion of the between-letter spacing done in TeX / LaTeX. In looking at the font specs, I noticed they only have 2 horizontal properties: advance width and left side bearing.

The horizontal distance from the current point to the left most point on the glyph is the left side bearing. The horizontal distance the current point moves after the glyph is drawn to be positioned for the next glyph is the advance width.

There is also some kerning that happens, but ignoring that, there is basically just a predefined spacing around each letter (before the start of it, and after the end of it) defined by the font. I am wondering if TeX / LaTeX somehow uses or overrides this behavior. That is, if during it's line breaking procedure or related, it also may decide that certain letters need to be compressed or expanded in some ways. Maybe it does it on an individual letter basis, on a word basis, or a full line basis (e.g. on each line each letter has a set spacing expansion/compression). I know from the linked paper that they have glue that can stretch and shrink which is the spaces between words, but I'm not sure if they mess with the font measurements for between-letter spacing adjustments.

If so, I'd be interested to know where to find more information on what exactly is done with the between-letter spacing.

I know you can manually change the letter spacing on a per-letter basis, but I'm wondering if anything automatic is happening.

  • 4
    see the microtype package – David Carlisle Jul 23 '18 at 10:23
  • The answer is quite simple: the TeX algorithms don't do any letter spacing; line breaking modifies inter-word and inter-sentence spaces and treats the letters as boxes that are placed side by side. For letter spacing you need the microtype or the letterspacing package, with the first one being the more modern one. – gernot Jul 23 '18 at 11:47
  • 1
    Interestingly, the last item of Knuth's tex82.bug is "* Bad ideas that will not be implemented", and it contains: ". if anybody wants letter spacing desperately they should put it in their own private version (e.g. generalize the hpack routine) and NOT call it TeX." – Phelype Oleinik Jul 23 '18 at 14:31
  • That is interesting, I wonder what the thought-process was/is. – Lance Pollard Jul 23 '18 at 16:10
  • 1
    (IIRC) Knuth initially considered letter-spacing as well (as found in some newspapers etc), but all the typographers he spoke to told him it was an awful thing not done in “real” books, so TeX doesn't do it. – ShreevatsaR Jul 24 '18 at 2:35
6

As I understand 'letter-spacing', the term refers to deliberately and visibly increasing the space between certain kinds of letters e.g. small-caps or all-caps.

microtype does support letter-spacing in this sense, as do various other packages.

However, this has nothing whatsoever to do with line-breaking.

What microtype can do, if certain engines are used, is make adjustments to assist the line-breaking algorithm and improve optical alignment etc. This is a very different feature and, by design, should not be noticeable or visible to the reader. That is, of course, it is visible in one sense, but it should not be perceived unless the reader is looking for it and examining the properties of the typesetting, as opposed to examining the content of what is typeset.

Whether any particular document uses micro-typography and, if so, which features it uses with which settings depends on a range of factors.

  • Format used. This is pretty much limited to LaTeX, as far as I know.

  • Is the microtype package loaded? This is required for micro-typography (though not for letter-spacing necessarily).

  • Which engine is used and which version of that engine? Current pdfTeX is fully supported. Current LuaTeX is well supported. Current XeTeX has extremely limited support. TeX has none.

  • Which fonts are used? Some features require scalable fonts.

  • Which fonts are used? There are font-specific configurations for some fonts. Otherwise, microtype will use more conservative 'generic' settings. Of course, people can override these.

  • Which features are activated for which fonts? There are the defaults, but these can obviously be overridden.

  • Does the document class and/or do loaded packages interfere with the implementation of features in specific contexts? For example, optical alignment fails, by default, with most (all?) classes for section headings. (Moreover, I can't get it to work for some classes and packages, even though it can be fixed for the standard classes and Memoir, for instance.)

If the configuration ticks all the needed boxes, microtype can use font expansion to assist line-breaking. Basically, it scales the font by a very small factor to help avoid bad horizontal spacing. The effect of this is not a noticeable change in the size of the font, but an extremely subtle one which really just helps with line-breaking.

In addition, if the necessary boxes are ticked, the package can also do such things as enable hanging punctuation and other aspects of optical alignment. This feature works best with a font-specific configuration, but it works reasonably well with the generic settings for most other fonts.

The full list of available micro-typographic features (from table 1 in the manual) is:

  • Protrusion
  • Expansion (auto or non-auto)

Both features are supported for LuaTeX and pdfTeX. Only protrusion is supported for XeTeX.

  • Kerning
  • Spacing

Only supported for pdfTeX and disabled by default.

Here are two before-and-after shots for illustrative purposes. The lines indicate the page layout, so you can see the edge of the text block easily.

without protrusion

This shows the result without microtype. Things are aligned actually, but not optically.

with protrusion

This shows the result with microtype. Things are aligned optically, because the punctuation is permitted to slightly protrude into the margin.

bad break without expansion

This shows one spot where TeX is having trouble breaking a paragraph into lines. The result is one of several 'bad boxes' in this document. (Note that I had to increase the font size to 12pt and reduce the paper size to A6 to get bad boxes.)

good break with expansion

This shows the improvement with microtype's expansion feature. Loading the package eliminated all bad boxes in this document.

Related non-micro-typographic features (from the same table):

  • Tracking

This is what people generally call 'letter-spacing' on this site. It is supported for pdfTeX and LuaTeX. Although not supported for XeTeX, the fontspec package provides this function as LetterSpace for this engine.

Here's a comparison of standard small-caps:

without tracking

and the same example with microtype's tracking enabled, which applies to small-caps by default:

with tracking

In addition, microtype provides some capacity for disabling ligatures selectively etc.

Code for expansion demo:

\documentclass[british,a6paper,12pt]{article} 
\usepackage[showframe]{geometry}
\usepackage{babel}
\usepackage{cfr-lm} 
\usepackage[utf8]{inputenc} 
\usepackage{microtype}
\usepackage{kantlipsum}


\begin{document}
\kant[1-20]

\end{document}

All examples were compiled with pdfTeX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.