Spacing TeX-Core – How to Limit Interword Shrinking Without Affecting Normal Interword Spacing

spacingtex-core

There are many questions about interword spacing in Latex, but this question is different. I'm generally OK with the default spacing and do not want to change it. However, sometimes Latex shortens the interword spacing too much, making the text line very compressed. My guess is that there must be some threshold for how much the normal interword space can be reduced, and I would like to change just this threshold, without affecting anything else.

For example, I set the threshold to 2pt. Then I expect that for each pair of consecutive words with a distance of more than 2 points, this distance will not change, and for each pair of consecutive words with a distance of less than 2 points, this distance will increase to 2 points.

Is it possible?

Best Answer

The amount of shrinkability is defined by the font metrics of the current font. Its value can be retrieved as \fontdimen4\font and it should be compared to the standard interword space, residing in \fontdimen2\font. The standard Computer Modern Roman font at 10pt has

\fontdimen 2 = 3.33333pt
\fontdimen 4 = 1.11111pt

whereas the NewTX font (a clone of Times) has

\fontdimen 2 = 2.5pt
\fontdimen 4 = 1.00006pt

so the interword space can shrink up to 1.5pt. By contrast, TeX Gyre Bonum, which is quite a wide font has

\fontdimen 2 = 3.2pt
\fontdimen 4 = 1.06999pt

There is no “universal threshold”: the font designer decides.

You can change the value of the relevant \fontdimen, but there are some points to be considered:

  1. any assignment to a \fontdimen is global;
  2. assigning a different \fontdimen must be done for every font variant (shape, weight or size) you use.

So, if you do

\AtBeginDocument{\fontdimen4\font=1pt }

this would only affect the \normalfont at \normalsize. You might hook into \selectfont for setting \fontdimen4\font to, say, one third of \fontdimen2\font, but this would also act on the monospaced fonts that, usually, have zero shrinkability.

Example.

\documentclass{article}

\usepackage{newtx}

\AddToHook{selectfont}{%
  \ifdim\fontdimen4\font>0pt
    \fontdimen4\font=\dimexpr\fontdimen2\font/3\relax
  \fi
}

\begin{document}

2: \the\fontdimen2\font

4: \the\fontdimen4\font

\itshape

2: \the\fontdimen2\font

4: \the\fontdimen4\font

\upshape\Large

2: \the\fontdimen2\font

4: \the\fontdimen4\font

\ttfamily

2: \the\fontdimen2\font

4: \the\fontdimen4\font

\end{document}

enter image description here

Without the \AddToHook declaration, the same code would produce

enter image description here

Related Question