Skip to content

\@biblabel and \@cite are macros the citation path calls, not brackets built in Go - #682

Merged
tannevaled merged 2 commits into
mainfrom
biblabel-is-a-macro
Nov 3, 2026
Merged

tannevaled merged 2 commits into
mainfrom
biblabel-is-a-macro

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Closes #681 for the two formatting hooks the measurement supports. Same shape as
\footnoterule (#679) and \@makefntext (#680): a macro the reference defines is
executed, not imitated.

The defect, in four lines

\documentclass{article}
\makeatletter\def\@biblabel#1{<<#1>>}\makeatother
\begin{document} Texte~\cite{k}.
\begin{thebibliography}{9}\bibitem{k} Une reference.\end{thebibliography}\end{document}
rendu
avant Texte[1].References[1]Unereference.
avant, sans la redéfinition Texte[1].References[1]Unereference.
après Texte[1].References**<<1>>**Unereference.

The two "avant" rows are byte-identical: the redefinition did nothing at all. Same
for \def\@cite#1#2{(((#1#2)))}, now (((1))).

The brackets were written into \@bibitemopt/\@bibitemnoopt (latex.go) and into
doCite (crossref.go). The reference makes both a macro — \def\@biblabel#1{[#1]}
(latex.ltx:13324), \def\@cite#1#2{[{#1\if@tempswa , #2\fi}]} (:13322) — and
article.cls:568 builds the bibliography list's label by calling \@biblabel.

This engine executes real .cls files, so those redefinitions were already in the
eqtb and were dropped at the one point that mattered.

The measurement, corrected

The first count in #681 said "2941 papers, 22 of the 154, redefine the kernel's
citation internals"
. It did not separate a paper's own source from the files it ships:

où la redéfinition se trouve papiers /154
le .tex du papier lui-même 56 0
un .cls embarqué 3093 22
…dont \@biblabel 2961 19
…dont \@cite 1450 12

Not one of the 154 redefines these in its own source; every one of the 22 gets it from a
class. Only 50 of the 154 ship a class at all, so this is 22 of 50 — 44 % of
the papers that bring their own class. Exactly one ships natbib.sty, so it is about
classes, not natbib.

Corpus A/B

Control 4a19ba6 (main), treatment 77f0dd5:

pages  : 154 comparés, 0 ont bougé, Σ|·| = 0, biais = +0
rendu  : 154 comparés, 18 DIFFÉRENTS, dont 18 à pagination identique

18 of 154, against a bound of 19 papers whose class redefines \@biblabel. The tool
printed its own warning on this one, which is the warning working:

⛔ écart nul en PAGES, mais 18 document(s) ont changé de RENDU à pagination identique …
Le zéro ci-dessus est un silence, pas un résultat.

Controls

  • The default is unchanged. All 154 papers carry a bibliography, so a path that moved
    the default would have moved everything; TestCitationDefaultsAreUnchanged asserts it,
    and the page count is flat at 0.
  • Mutation. With the \@cite call disabled, TestCiteWrapperObeysTheDocument and
    TestCiteSetsTheSwitchItsOwnMacroReads fail and the default control still passes.
  • \if@tempswa is set, not inherited. The reference's \cite makes it true when it
    read a bracket and false when it did not (latex.ltx:13283-13284), and a redefined
    \@cite reads it to decide whether to print the note. Leaving it alone would make the
    note's fate depend on whatever last touched the switch — a defect visible only on a
    document that cites twice, with and without a note, in that order. That is the test.

NOT DONE HERE

\@citex, the iteration itself. natbib works by \letting it (natbib.sty:658,666:
\let\@citex\NAT@citexnum, \let\@cite\NAT@cite), so executing it would mean running
real natbib instead of the Go emulation that latex.go:385 describes. No number here
calls for that
— one paper in 154 ships natbib.sty — and #681 keeps it open with the
measurement that says why.

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 3, 2026 15:13
…s built in Go

The marker's brackets were written into \@bibitemopt/\@bibitemnoopt and into doCite,
so no class could change either. The reference makes both a macro:

    \def\@biblabel#1{[#1]}                        (latex.ltx:13324)
    \def\@cite#1#2{[{#1\if@tempswa , #2\fi}]}     (latex.ltx:13322)

and article.cls:568 builds the bibliography list's label by calling \@biblabel.

This engine EXECUTES real .cls files, so those redefinitions were already reaching the
eqtb and were dropped at the one point that mattered. Measured on the corpus, split by
where the redefinition lives — because the first count did not separate a paper's own
source from the files it ships:

    dans le .tex du papier     56 papiers,     0 des 154
    dans un .cls embarque    3093 papiers,    22 des 154
      dont \@biblabel        2961 papiers,    19 des 154
      dont \@cite            1450 papiers,    12 des 154

Only 50 of the 154 ship a class at all, so 22 of 50 — 44% — of the papers that bring
their own class bring one that redefines these hooks. Exactly one of the 154 ships
natbib.sty, so this is about classes, not about natbib.

Measured before and after on a four-line document: \def\@biblabel#1{<<#1>>} and
\def\@cite#1#2{(((#1#2)))} rendered BYTE-IDENTICALLY to a document without them, and
now produce <<1>> and (((1))).

\if@tempswa is SET here rather than inherited. The reference's \cite makes it true when
it read a bracket and false when it did not (latex.ltx:13283-13284), and a redefined
\@cite reads it to decide whether to print the note; leaving it alone would make the
note's fate depend on whatever last touched the switch — a defect visible only on a
document that cites twice, with and without a note, in that order.

NOT DONE HERE: \@citex, the iteration itself. natbib works by \letting it
(natbib.sty:658,666), so executing it would mean running real natbib instead of the Go
emulation — and no number here calls for that: one paper in 154 ships natbib.sty.

Co-Authored-By: Claude Opus 5 <[email protected]>
@tannevaled
tannevaled merged commit 712e574 into main Nov 3, 2026
18 checks passed
@tannevaled
tannevaled deleted the biblabel-is-a-macro branch November 3, 2026 18:15
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.

A class's \@biblabel and \@cite are executed into the eqtb, then ignored by the Go citation code (19 and 12 of 154)

1 participant