1

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?

4
  • 1
    I think that \fontdimen4\font=0pt will limit the shrinkage to 0pt Commented May 28, 2022 at 13:27
  • @StevenB.Segletes Ok, thank you. However, I do not want to remove shrinkage at all; it is necessary in many cases. I just want to tune it a little to avoid cases of too much compressed text.
    – Ilia
    Commented May 28, 2022 at 13:34
  • @StevenB.Segletes And the tuning must be relative to the default value.
    – Ilia
    Commented May 28, 2022 at 13:43
  • I have edited my answer to address the issue of relative change of fontdimen4 Commented May 28, 2022 at 13:50

2 Answers 2

1

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

2
  • 1
    Two additional things to consider: (1) Is this affected by microtype? (2) For a letter with an overhang (like "f"), that would still extend into the interword space, but can be overcome by an italic correction (\/). Italic correction is applied automatically if \textit or \emph is used, but not for a transition from italic to upright when only \itshape is used. (An explicit italic correction may be desirable even in an all-upright environment with a juxtaposition like "of W" if the line is set tight.) Commented May 28, 2022 at 23:34
  • @egreg Thank you, your answer is closest to what i wanted.
    – Ilia
    Commented May 29, 2022 at 10:25
1

REVISED ANSWER

My original answer still provides useful information so I leave it below. However, the OP, in revising the question would seem to like to specify the default interword space (\fontdimen2), would like there to be zero interword contraction below the threshold (\fontdimen4). It is unclear if the OP wishes to specify the amount of allowable expansion of the interword space (\fontdimen3).

These may be set to achieve the OP's aims, in the following manner:

\fontdimen2\font=2pt% What the OP calls "Threshold"
\fontdimen3\font=22pt% allowable expansion beyond "Threshold"
\fontdimen4\font=0pt% Space will never shrink below threshold

See the accepted answer at What do different \fontdimen<num> mean for more details.

ORIGINAL ANSWER

Shrinkage can potentially occur any time that the nominal width of the characters on a [full] line does not match the line width. At that point, when typesetting the paragraph, TeX will either expand or shrink gluey dimensions in an effort to both match the linewidth while maximizing the "quality" algorithm, which it does through a series of user-settable penalties.

Commands like \sloppy are merely a reset of certain penalties used by the quality-algorithm.

The current value of \fontdimen4 may be seen with \the\fontdimen4\font. Its value may be changed in a relative way with

\fontdimen4\font=\dimexpr\fontdimen4\font-1pt\relax

In all 3 cases below, the line exceeds the textwidth given by the rule. However, the amount of allowable shrinkage varies based on the setting of \fontdimen4.

\documentclass[11pt]{article}
\textwidth=.95in

\begin{document}

\noindent\rule{\textwidth}{2pt}

Test of spacing 

\fontdimen4\font=0pt
Test of spacing 

\fontdimen4\font=3pt
Test of spacing 
\end{document}

enter image description here

When there is no requirement for shrinkage, as when the \textwidth is set to 2in, all 3 cases are indistinguishable. Also shown is how to change \fontdimen4 relative to its current value.

\documentclass[11pt]{article}
\textwidth=2in

\begin{document}

\noindent\rule{\textwidth}{2pt}

Test of spacing 

\fontdimen4\font=0pt
Test of spacing 

\fontdimen4\font=3pt
Test of spacing 

Value of fontdimen4:
\the\fontdimen4\font

Changing its relative value:
\fontdimen4\font=\dimexpr\fontdimen4\font-1pt\relax
\the\fontdimen4\font

\end{document}

enter image description here

2
  • Thank you Steven. I tried your answer, but unfortunately it is not what I wanted. It affects the space between EVERY two consecutive words, while I only want to fix the space that is less than the threshold. Perhaps the wording of my question was not clear enough, and I edited it.
    – Ilia
    Commented May 28, 2022 at 16:13
  • @Ilia My revised answer should provide what you need. Only reset \fontdimen3 if you want to specify the allowable expansion. Commented May 28, 2022 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .