Skip to content

\resizebox* printed its arguments, and \rule's lift had both signs backwards - #409

Merged
tannevaled merged 2 commits into
mainfrom
fix/resizebox-star
Sep 24, 2026
Merged

tannevaled merged 2 commits into
mainfrom
fix/resizebox-star

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Two box defects, both found by reading the package source and both settled by
asking tectonic.

1. \resizebox* printed its own arguments onto the page

The star is the whole difference between the two forms, and it is one word of
graphics.sty:539-541:

\protected\def\resizebox{%
  \leavevmode
  \@ifstar{\Gscale@@box\totalheight}{\Gscale@@box\height}}

\resizebox sizes the box by its height above the baseline; \resizebox* by
its total height, depth included. Everything else is shared.

The star was never consumed, so neither dimension parsed and the source reached
the page as text:

Y\resizebox*{30mm}{!}{CONTENU}Y   →   Y*30mm!CONTENUY

with the content unscaled. One corpus paper wraps every one of its four figures
this way and printed *45mm! and *65mm! into them, each around a
tikzpicture that then went unscaled.

20 of the 154 corpus papers use \resizebox, 111 times, 4 of them starred.

2. \rule's lift was added to its height instead of crossing the baseline

The lift moves the rule across the baseline; it does not make it taller.
latex.ltx:11900-11907:

\def\@rule[#1]#2#3{%
  \leavevmode
  \hbox{%
    \setlength\@tempdima{#1}%   lift
    \setlength\@tempdimb{#2}%   width
    \setlength\@tempdimc{#3}%   height
    \advance\@tempdimc\@tempdima
    \vrule\@width\@tempdimb\@height\@tempdimc\@depth-\@tempdima}}

so height = #3 + lift and depth = -lift. Both signs were the wrong way
round.
Asked directly, tectonic answers — and this engine now answers the same
three:

\ht \dp
\rule[2pt]{3pt}{6pt} 8.0pt 0.0pt
\rule[-2pt]{3pt}{6pt} 4.0pt 2.0pt
\rule{3pt}{6pt} 6.0pt 0.0pt

Before, a negative lift — the only kind that does anything visible — was added
to the height and asked for a negative depth the packer clamped to zero:
\rule[-2mm]{3mm}{6mm} packed 8mm tall and 0mm deep. One corpus paper writes
\rule[-\textheight/2]{1ex}{\textheight}, meant to straddle the baseline by half
a page each way; it packed one and a half pages above it. 4 papers use a
non-zero lift, 21 times.

A lift of zero — what \rule{w}{h} supplies — is unaffected either way, so
nothing else moves.

A test was pinning the inversion

TestRuleLift demanded height 4pt and depth 2pt for a +2pt lift, which is the
inversion stated as a requirement. It now asks tectonic's answer, and additionally
checks that the enclosing hbox clamps the negative depth the way TeX's hpack
does (tex.web §649).

Measured, 154-paper corpus

before after
Σ|page error| 306 306
glyphs — −12
papers losing >100 glyphs — 0

The −12 is not content: it is exactly *45mm! (6) + *65mm! (6), the leaked
source no longer printed. Checked character by character on the paper concerned.

🤖 Generated with Claude Code

tannevaled and others added 2 commits September 24, 2026 11:28
The star is the whole difference between the two forms, and it is one word of
graphics.sty:539-541:

    \protected\def\resizebox{%
      \leavevmode
      \@ifstar{\Gscale@@box\totalheight}{\Gscale@@box\height}}

\resizebox sizes the box by its HEIGHT above the baseline, \resizebox* by its
TOTAL height, depth included. Everything else is shared.

The star was never consumed, so neither dimension parsed and the source reached
the page as text. `Y\resizebox*{30mm}{!}{CONTENU}Y` set

    Y*30mm!CONTENUY

with the content unscaled. One corpus paper wraps every one of its four figures
this way and printed "*45mm!", "*100mm!" and "*65mm!" into them, each around a
tikzpicture that then went unscaled.

20 of the 154 corpus papers use \resizebox, 111 times, 4 of them starred.

Co-Authored-By: Claude Opus 5 <[email protected]>
The lift of \rule[lift]{width}{height} moves the rule ACROSS the baseline; it does
not make it taller. latex.ltx:11900-11907 says which dimension takes it:

    \def\@rule[#1]#2#3{%
      \leavevmode
      \hbox{%
        \setlength\@tempdima{#1}%   lift
        \setlength\@tempdimb{#2}%   width
        \setlength\@tempdimc{#3}%   height
        \advance\@tempdimc\@tempdima
        \vrule\@width\@tempdimb\@height\@tempdimc\@Depth-\@tempdima}}

so height = #3 + lift and depth = -lift. Both signs were the wrong way round here.

Asked directly, tectonic answers:

    \rule[2pt]{3pt}{6pt}    ht=8.0pt  dp=0.0pt
    \rule[-2pt]{3pt}{6pt}   ht=4.0pt  dp=2.0pt
    \rule{3pt}{6pt}         ht=6.0pt  dp=0.0pt

and this engine now answers the same three. Before, a negative lift — the only
kind that does anything visible — was ADDED to the height and asked for a negative
depth the packer clamped to zero: \rule[-2mm]{3mm}{6mm} packed 8mm tall and 0mm
deep. One corpus paper writes \rule[-\textheight/2]{1ex}{\textheight}, meant to
straddle the baseline by half a page each way; it packed one and a half pages
above it. 4 of the 154 papers use a non-zero lift, 21 times.

A lift of zero, which is what \rule{w}{h} supplies, is unaffected either way, so
nothing else in the corpus moves.

TestRuleLift demanded the inversion outright — height 4pt and depth 2pt for a
+2pt lift — and so pinned it in place. It now asks tectonic's answer, and checks
the enclosing hbox clamps the negative depth the way TeX's hpack does (tex.web
§649).

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit 74bf43a into main Sep 24, 2026
18 checks passed
@tannevaled
tannevaled deleted the fix/resizebox-star branch September 24, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant