4

I want to add some shrinkability to an existing glue, that already has a stretch component, and that also may have a shrink component (although it is not the case for me currently).

For instance:

\newlength{\mylength} \setlength{\mylength}{12pt plus 1pt} \setlength{\mylength}{\glueexpr \the\mylength minus 0.1pt \relax} % speculative syntax \the\mylength % should show “12pt plus 1pt minus 0.1pt” 

It happens that, in this lucky case where there is no preexisting shrink component and I just want to add one, I can do just what I did above, relying on the syntactic order LENGTH plus STRETCH minus SHRINK. This would fail in general, if there was a shrink component that I wanted to modify in some way (either by scaling it, or by adding a constant value to it, or by entirely replacing it with another value). This also fails in the symmetrical situation, where I want to set a stretch component but there is a preexisting shrink component.

How to extract or modify the stretch and shrink components of a glue?

The only related solution I found is how to drop the stretch and shrink components, which does not help.

Use case: add some shrinkability to inter-line and inter-paragraph spacing (\baselineskip, \parskip), which helps avoiding many hideous “underfull \vboxes”, that is, pages that are too empty and where inter-paragraph spaces are stretched far beyond reasonable.

1 Answer 1

4

You want to sum two complete glue specifications:

\documentclass{article} \begin{document} \newlength{\mylength} \setlength{\mylength}{12pt plus 1pt} \setlength{\mylength}{\glueexpr \mylength + 0pt minus 0.1pt \relax} \the\mylength % should show “12pt plus 1pt minus 0.1pt” \end{document} 

enter image description here

You don't need \the inside \glueexpr.

A bit more complicated is to replace a glue stretch or shrink component.

\documentclass{article} \makeatletter \newcommand{\getgluestretch}[1]{% #1 = glue parameter 0pt plus \expandafter\strip@pt\gluestretch#1 \ifcase\gluestretchorder#1% pt\or fil\or fill\or filll \fi minus 0pt } \newcommand{\getglueshrink}[1]{% #1 = glue parameter 0pt plus 0pt minus \expandafter\strip@pt\glueshrink#1\space \ifcase\gluestretchorder#1% pt\or fil\or fill\or filll \fi } \makeatother \begin{document} \newlength{\mylength} \setlength{\mylength}{12pt plus 1pt minus 2pt} \the\mylength \setlength{\mylength}{% \glueexpr \mylength - \getglueshrink\mylength + 0pt minus 0.1pt \relax } \the\mylength \setlength{\mylength}{% \glueexpr \mylength - \getgluestretch\mylength + 0pt plus 1fil \relax } \the\mylength \setlength{\mylength}{% \glueexpr \mylength - \getgluestretch\mylength + 0pt plus 1pt \relax } \the\mylength \end{document} 

We need to replace pt that's added to the value by \gluestretch with the correct glue order.

enter image description here

Replacing both is easy: just multiply the glue parameter by 1, as in

\setlength{\mylength}{1\mylength plus 1fil minus 3pt} 

because multiplication by a factor kills the stretch and shrink components.

1
  • \glueexpr...\relax can be replaced with \skipeval{...} (which may be even better) Commented Nov 21 at 11:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.