Skip to content

compiler: accept hyperref and \hypersetup, and break URLs the way url.sty does (rebase of #385) - #388

Merged
GoKubar merged 6 commits into
mainfrom
agent/linux-integration/hyperref-rebase2
Sep 14, 2026
Merged

GoKubar merged 6 commits into
mainfrom
agent/linux-integration/hyperref-rebase2

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Rebase of #385 (itself the rebase of #379) onto main after #317, #322, #331, #339, #333 and #345 landed. #385 is closed in favour of this one.

Two conflicts, both mechanical:

  • crates/compiler/src/parser.rs — compiler: \pagestyle, \thispagestyle and \pagenumbering are accepted in the preamble (#321) #322 added \pagestyle, \thispagestyle and \pagenumbering arms to the same preamble-or-body match group this branch adds \hypersetup to. Both sides kept; the arms are independent.
  • docs/user/compiler.md, crates/compiler/supported/{supported-latex.json,coverage.md} and the bundled Mac copy — regenerated with crates/compiler/scripts/render_supported_latex.sh and apps/mac/scripts/sync-supported-latex.sh, never hand-merged.

The regeneration also re-syncs apps/mac/Sources/FlashTeXMac/Resources/supported-latex.json, which main had left stale since #380. apps/mac/scripts/sync-supported-latex.sh --check — the mac job's "Completion vocabulary is the compiler's inventory" step — is green on this branch and was red on main before it. That is the only file this PR touches under apps/mac/, and it is generated output, not Swift.

Verified locally on this branch: cargo test --release --no-fail-fast in crates/compiler, 0 failed.

Original #379 rationale follows unchanged.


Four hyperref gaps, each pinned to a pdflatex (TeX Live 2025) measurement.

1. \hypersetup was a hard error. \hypersetup{colorlinks=true,...} in the preamble produced \hypersetup is not supported in the document preamble on a valid document — fixtures/real-world/hyperref-toc line 7 is exactly that call. It is now read and typesets nothing, in the preamble and in the body.

2. \usepackage{hyperref} said "recognised but not implemented". Measured: the corpus document compiled by pdflatex with and without hyperref (control = url.sty plus a text-only \href) is 1062 words on 4 pages with 0 words moved, and a second document exercising \maketitle, abstract, \tableofcontents, \ref/\pageref, \url, \href, a \footnote and a \cited bibliography gives 137 words, 1 page, 0 moved under every one of default, colorlinks, hidelinks, pdfborder, bookmarks=false, breaklinks, linktoc=all, pdfstartview, the pdf* metadata keys, unicode and pdfpagemode.

backref/pagebackref are not claimed neutral: they add back-reference text to every bibliography entry, so they keep warning, as does any key not on the measured list.

… url.sty does

Four hyperref gaps, each pinned to a pdflatex (TeX Live 2025) measurement.

**1. `\hypersetup` was a hard error.** `\hypersetup{colorlinks=true,...}` in
the preamble produced `\hypersetup is not supported in the document
preamble` on a valid document — `fixtures/real-world/hyperref-toc` line 7 is
exactly that call. It is now read and typesets nothing, in the preamble and
in the body.

**2. `\usepackage{hyperref}` said "recognised but not implemented".** That
wording claims the *text* may be wrong. It is not. Measured: the corpus
document compiled by pdflatex with and without hyperref (control = url.sty
plus a text-only `\href`) is **1062 words on 4 pages with 0 words moved**,
and a second document exercising `\maketitle`, `abstract`,
`\tableofcontents`, `\ref`/`\pageref`, `\url`, `\href`, a `\footnote` and a
`\cite`d bibliography gives 137 words, 1 page, 0 moved under every one of
`default`, `colorlinks`, `hidelinks`, `pdfborder`, `bookmarks=false`,
`breaklinks`, `linktoc=all`, `pdfstartview`, the `pdf*` metadata keys,
`unicode` and `pdfpagemode`.

So hyperref is accepted for those options. `backref`/`pagebackref` are
**not**: they add back-reference text to every bibliography entry, and they
would not compile in that harness, so they keep warning rather than being
claimed neutral on an unmeasured guess — as does any key not on the list,
which `\hypersetup` reports once.

What is genuinely missing — the PDF link annotations, destinations,
bookmarks and `colorlinks` colouring — keeps its own existing diagnostic.

**3. The URL break set was wrong in both directions.** Measured by setting
`\url{xxxxxxxx<c>xxxxxxxx}` in a 56pt `minipage`, a width at which the only
possible break is right after `<c>`:

- breaks after `/ . ? & # = + : _ , ; ! | > ) ] ' @`
- does **not** break after `- ~ * $`

`-` and `~` used to break here and now do not, and the ten characters
`: _ , ; ! | > ) ] ' @` were missing. The hyphen is the one that matters:
url.sty refuses to break there so a URL's own hyphen cannot be misread as
hyphenation.

**4. A URL's hyphen carries a 0.5pt kern.** `\setbox0=\hbox{\url{a-b}}` is
17.47511pt where `\texttt{a-b}` is 16.97511pt; `\url{a-b-c}` is 29.29185pt
against `\texttt`'s 28.29185pt — exactly 0.5pt per hyphen and nothing for
any other character (`\url{x.y}` and `\texttt{x.y}` are both 16.97511pt).
Reading the glyph origins back out of the PDF puts the gap immediately after
the hyphen. `push_url_text` now emits that kern, which is also what stops
the pipeline's `\exhyphenpenalty` break from firing there: the hyphen ends
its run and a kern, not glue, follows it.

Suites: compiler 503 passed / 0 failed, against 498 / 0 on main (the
difference is this change's five new tests). Generated inventories
regenerated with `crates/compiler/scripts/render_supported_latex.sh`.

**A vendor re-pin is needed for any of this to reach `flashtex-render`.**
The pipeline builds against `crates/render-pipeline/vendor/compiler`
(`Cargo.toml`: `flashtex-compiler = { path = "vendor/compiler" }`), which is
byte-identical to `crates/compiler` today, so until it is re-pinned the
corpus still sees the old break set, no hyphen kern, and the `\hypersetup`
error. No vendor commit is made here.

pdflatex is an oracle only and is never in the product path.

Implementation-Agent: Claude Opus 5 (lane nixos-hyperref, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Rebased onto main after #380 (natbib) landed in the same files; the only
conflict was the generated command count in `docs/user/compiler.md`, resolved
by regenerating (`crates/compiler/scripts/render_supported_latex.sh`): 259 ->
260 text-mode entries (`\hypersetup`) and 15 -> 16 layout-neutral packages
(`hyperref`). `cargo test --release` on `crates/compiler` with the font
environment set: 533 passed, 0 failed.

Rebase-Executor: Claude Opus 5 (Commander session, linux-primary)
… url.sty does

Rebase of #385 (itself a rebase of #379) onto main after #317, #322, #331
and #339 landed in the same files.

Two conflicts, both mechanical and resolved without hand-editing generated
output:

* `crates/compiler/src/parser.rs` — #322 added `\pagestyle`,
  `\thispagestyle` and `\pagenumbering` arms to the same
  preamble-or-body match group this branch adds `\hypersetup` to. Both
  sides kept; the arms are independent.
* `docs/user/compiler.md`, `crates/compiler/supported/{supported-latex.json,
  coverage.md}` and the bundled Mac copy — regenerated with
  `crates/compiler/scripts/render_supported_latex.sh` and
  `apps/mac/scripts/sync-supported-latex.sh`, never hand-merged.

The regeneration also re-syncs
`apps/mac/Sources/FlashTeXMac/Resources/supported-latex.json`, which main
had left stale since #380; `apps/mac/scripts/sync-supported-latex.sh --check`
(the mac job's "Completion vocabulary is the compiler's inventory" step) is
green here and was red on main before this.

Verified on this branch: `cargo test --release --no-fail-fast` in
crates/compiler, 0 failed.

Implementation-Agent: Claude Opus 5 (lane linux-integration, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
…eX artefacts after #320

Implementation-Agent: Claude Opus 5 (lane linux-integration, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
…eX artefacts after #390

Implementation-Agent: Claude Opus 5 (lane linux-integration, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
…st with #392's allowdisplaybreaks, regenerate the artefacts

Implementation-Agent: Claude Opus 5 (lane linux-integration, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar merged commit 23f6611 into main Sep 14, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/linux-integration/hyperref-rebase2 branch September 16, 2026 04:17
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