Skip to content

\textwidth is not \columnwidth, and \begin{document} recomputes the measure - #375

Merged
tannevaled merged 3 commits into
mainfrom
textwidth-own-register
Sep 23, 2026
Merged

tannevaled merged 3 commits into
mainfrom
textwidth-own-register

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Two halves of one defect, found by asking why the corpus's worst "too long" paper (2401.17012, ref 13, ours 20) sets its text 236.9pt wide where the reference sets 483.3pt.

1. \textwidth had no register of its own

\textwidth is the text block — both columns and the gutter in two-column mode — and \columnwidth is one column. \columnwidth is \let to \hsize here, the paragraph measure. A class states both, in this order (oupau.cls:68,70):

\textwidth 170.5mm
\columnwidth 83.25mm

With \textwidth writing only e.hsize, the second line overwrote the first:

\textwidth=300pt \columnwidth=150pt \the\textwidth
tectonic 300.0pt
before 150.0pt
after 300.0pt

2. \begin{document} recomputes the measure

The class's own \columnwidth is discarded there (latex.ltx:6682-6688):

\columnwidth\textwidth
\if@twocolumn \advance\columnwidth -\columnsep \divide\columnwidth\tw@ \fi
\hsize\columnwidth  \linewidth\hsize

Without that, a stray \columnwidth stayed the measure for the whole document.

Measured

The paper goes 20 → 15 pages against a reference of 13, and the hyphenation caused by the narrow measure collapses with it:

hyphenated line ends
reference 3
before 161
after 17

That is also the whole of its "lost" 153 glyphs — hyphens that should never have been set. Worth saying plainly, because the A/B tool flags it as content loss.

On the 154-paper corpus: Σ 301 → 305 (+4). Thirteen papers move. The one that improves is this one (−5); most of the rest grow by a page or two because \textwidth is now right, and a figure asked for at \textwidth is correspondingly wider and taller. Those papers were already too long, so a correct width costs them — the same shape #356 documents for every correction made while the corpus is measured in a substituted face.

Both tests fail without the change.

🤖 Generated with Claude Code

@tannevaled

Copy link
Copy Markdown
Contributor Author

Two corrections to the description above.

A defect I introduced. e.textWidth was a plain field assignment, so \textwidth did not come back at the end of a group:

A=\the\textwidth  {\textwidth=500pt B=\the\textwidth}  C=\the\textwidth
A B C
tectonic 345.0pt 500.0pt 345.0pt
before 345.0pt 500.0pt 500.0pt ← leaked
after 345.0pt 500.0pt 345.0pt

It now travels on the save stack like the measure it accompanies.

The measurement that leak was flattering. With the scoping correct:

Σ
154-paper corpus 301 → 310 (+9), was +4 with the leak
100 Latin Modern papers, font controlled 195 → 204 (+9)

And half my explanation of the +4 was wrong. The papers that grow do carry \textwidth-wide figures, and a correct (wider) \textwidth does make them taller — but rendering those figures for real does not absorb it, which I implied it would. Measured with the rasteriser wired on both sides, the cost is the same: a figure asked for at \textwidth follows \textwidth whether it is a raster or a placeholder.

What stands: both rules are latex.ltx's, both verified against tectonic, and together they take the corpus's worst "too long" paper from 20 pages to 15 against a reference of 13, with its hyphenation going 161 → 17 against the reference's 3.

At +9 this is well outside the ±3 the corpus can resolve, so it is not mine to merge. It belongs with #276, #352 and #370 — correct against a real TeX, costly on a metric that #356 shows is confounded.

tannevaled and others added 2 commits September 23, 2026 13:12
…easure

Two halves of one defect, found by asking why the corpus's worst "too long"
paper (2401.17012, ref 13, ours 20) set its text 236.9pt wide where the
reference sets 483.3pt.

\textwidth is the text BLOCK — both columns and the gutter in two-column mode —
and \columnwidth is one column. \columnwidth is \let to \hsize here, the
paragraph measure. A class states both, in this order (oupau.cls:68,70):

    \textwidth 170.5mm
    \columnwidth 83.25mm

With \textwidth writing only e.hsize the second line overwrote the first:

    \textwidth=300pt \columnwidth=150pt \the\textwidth
        tectonic 300.0pt      before 150.0pt      after 300.0pt

And \begin{document} recomputes the measure from \textwidth — the class's own
\columnwidth is DISCARDED there (latex.ltx:6682-6688):

    \columnwidth\textwidth
    \if@twocolumn \advance\columnwidth -\columnsep \divide\columnwidth\tw@ \fi
    \hsize\columnwidth \linewidth\hsize

Without that the stray column width stayed the measure for the whole document.

MEASURED. The paper goes 20 -> 15 pages against a reference of 13, and its
hyphenation collapses with the narrow measure that caused it:

    hyphenated line ends   reference 3      before 161      after 17

which is also the whole of its "lost" 153 glyphs — hyphens that should never
have been set.

On the 154-paper corpus: Sigma 301 -> 305 (+4). Thirteen papers move; the one
that improves is this one (-5), and most of the rest grow by a page or two
because \textwidth is now RIGHT and a figure asked for at \textwidth is
correspondingly wider and taller. Those papers were already too long, so a
correct width costs them — the same shape #356 documents for every correction
made while the corpus is measured in a substituted face.

Co-Authored-By: Claude Opus 5 <[email protected]>
Two corrections to the commit before this one.

FIRST, a defect I introduced: e.textWidth was a plain field assignment, so
\textwidth did not come back at the end of a group —

    A=\the\textwidth {\textwidth=500pt B=\the\textwidth} C=\the\textwidth
        tectonic  345.0pt  500.0pt  345.0pt
        before    345.0pt  500.0pt  500.0pt   <- leaked
        after     345.0pt  500.0pt  345.0pt

It now travels on the save stack like the measure it accompanies (saveTextWidth).

SECOND, the measurement that leak was flattering. With the scoping correct:

    154-paper corpus                 Sigma 301 -> 310  (+9, was +4 with the leak)
    100 Latin Modern, font controlled      195 -> 204  (+9)

And the explanation offered for the +4 was half wrong. The papers that grow do
carry \textwidth-wide figures, and a correct (wider) \textwidth does make them
taller — but rendering those figures for real does NOT absorb it, as I claimed it
would: measured with the rasteriser wired on BOTH sides, the cost is the same.
A figure asked for at \textwidth follows \textwidth whether it is a raster or a
placeholder.

What stands: the two rules are latex.ltx's (\textwidth and \columnwidth are
different registers; \begin{document} recomputes the measure from \textwidth,
6682-6688), both verified against tectonic, and they take the corpus's worst
"too long" paper from 20 pages to 15 against a reference of 13, with its
hyphenation going 161 -> 17 against the reference's 3.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled

Copy link
Copy Markdown
Contributor Author

Rebased onto today's main (which has since taken #380, #383, #384 and #386), suite green, and re-measured against it:

Σ
main 301
with this change 309 (+8)

Down one from the +9 measured before, and the shape is unchanged: the same single paper improves by five pages (2401.17012, 20 → 15 against a reference of 13) and the same thirteen-odd grow by one or two because \textwidth is now right and a figure asked for at \textwidth follows it.

The one "content loss" the A/B tool flags is that paper's own hyphens — 161 hyphenated line ends before, 17 after, against the reference's 3 — checked rather than assumed.

Still not mine to merge at +8: it belongs with #276, #352 and #370, correct against a real TeX and costly on a metric #356 shows is confounded.

@tannevaled
tannevaled force-pushed the textwidth-own-register branch from fd71ff1 to e1fd4f1 Compare September 23, 2026 11:15
@tannevaled
tannevaled merged commit 11a88bc into main Sep 23, 2026
18 checks passed
@tannevaled
tannevaled deleted the textwidth-own-register branch September 23, 2026 20:58
tannevaled added a commit that referenced this pull request Sep 25, 2026
Fixes #406, a regression from #375.

#375 is right that \textwidth is not \columnwidth in general. A minipage is the
one place where it legitimately stops being the page measure, and latex.ltx puts
all three assignments on consecutive lines (11855-11861, \@iiiminipage):

    \setbox\@tempboxa\vbox\bgroup
      \color@begingroup
        \hsize\@tempdima
        \textwidth\hsize \columnwidth\hsize
        \@parboxrestore

\parbox does NOT do this — \@iiiparbox sets \hsize and nothing else — and
tectonic agrees: inside a 0.33\textwidth minipage \the\textwidth reads
113.85063pt, inside the same-width \parbox it still reads 345.0pt. This engine
now answers both the same way.

Setting only the measure left \textwidth reporting the OUTER block, so
\includegraphics[width=\textwidth] inside a 0.32\textwidth panel scaled to the
full measure — three times too wide, and its proportional height three times too
tall. oneColHsize is saved and cleared with it: inside the box there is no
two-column split for \textwidth to span.

Measured over the 154-paper corpus:

    Sigma|page error|   306 -> 297      glyphs -8, no paper loses content

and the two papers that move are the ones #406 named:

    2404.16039   ref 35p   40p -> 36p
    2406.13839   ref 23p   41p -> 36p

Co-authored-by: Claude Opus 5 <[email protected]>
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