Skip to content

render-pipeline: emit display-list-v2 navigation so \href/\url are clickable (#323) - #737

Merged
jay3332 merged 5 commits into
mainfrom
agent/daniel-parent/gh323-links-producer
Sep 19, 2026
Merged

jay3332 merged 5 commits into
mainfrom
agent/daniel-parent/gh323-links-producer

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

The producer half of display-list-v2-links (#323). The Mac consumer has
been on main since #333; nothing was emitting for it —
crates/render-pipeline/src/v1.rs:67 said so outright
("display-list-v2-links is not negotiated here").

  • Negotiation (v1.rs): CAP_LINKS = "display-list-v2-links", accepted
    only next to display-list-v2, echoed when accepted, and dropped with the
    parent (is_display_list_family). Accepting it declines
    display-list-v2-delta, exactly as -window does and for the same reason:
    the display_list_delta line carries its own header and no navigation, so
    a frame rebuilt from base + delta would lose every link.
  • New crates/render-pipeline/src/links.rs: finds every \url/\href in
    the source, attributes glyph clusters to them by source span, and unions
    those into link rectangles.
  • Serialisation (display.rs): DisplayList::navigation, written as the
    top-level navigation object by both JSON writers (the Value tree and
    the direct byte writer) when Wire::links is on and the document has a
    link. Key order is the same alphabetical order, so
    write_json_matches_the_value_tree still holds, and it is charged in
    estimated_json_bytes_for so a declined capability cannot inflate the
    pre-serialisation size check.

Where the URI comes from — please read this bit

The proposal claims "producer inputs already exist on the compiler side
(Parsed::hyperref)". They do not. #131 never merged; neither
crates/compiler nor the pinned crates/render-pipeline/vendor/compiler has
any link record. \url keeps only its typeset text, and \href discards its
URL outright:

"href" => {
    let (_url, url_span) = self.url_argument(name, span);

What does survive is the span: every cluster of a link carries the source
range of the construct that produced it. So the URI is read back out of the
document's own bytes at that span (links::scan, mirroring the compiler's own
url_argument: braced arguments only, nested braces counted, \{/\}
unescaped, % comments skipped, \nolinkurl excluded). This is the same
technique — and the same documented limitation — as the linebreak-skip
feature: a \url/\href produced by a macro body carries the invocation's
span and yields no link.
The alternative is a compiler change plus a
vendor/ re-pin, which is a different lane.

No vendor edit. Nothing here resolves, opens or fetches anything: the producer
records a URI string and a rectangle; the Mac consumer applies its own scheme
allowlist (DisplayListLinks.allowedURISchemes).

Why

\href/\url are not clickable in the app. The Swift side already decodes
navigation and hit-tests it; it just never receives one. The shipping Mac
request is [display-list-v2, display-list-v2-images, display-list-v2-links]
(PreviewV2View.swift:274), so this is the only missing piece for the preview.

Consumer shape — matched, not invented

Checked against apps/mac/Sources/FlashTeXProtocol/RenderingV2.swift on
main (Navigation, :523) and its fixture, rather than against the proposal
alone. Two things the proposal does not say and the Swift model does:

  • Navigation.links and Navigation.destinations are non-optional, so
    destinations is always written, empty included. A producer that omitted it
    would fail JSONDecoder outright — this is exactly the drift mac: consume display-list-v2-diagnostics — v2 suggestions reach Problems and Tab-to-fix (after #358) #363 hit.
  • Link decodes either rect or rects. A wrapped link is emitted as
    one entry per page carrying rects, not one entry per line piece as §3
    describes, so a wrapped link's target/source/identity stay together; a
    single-piece link still writes rect.

Overlap check

Test results

cargo test -p flashtex-render-pipeline --test links_navigation
running 7 tests
test a_document_with_no_links_serialises_byte_identically ... ok
test nolinkurl_is_typeset_but_never_linked ... ok
test the_two_json_writers_agree_with_navigation_present ... ok
test link_rectangles_match_pdflatex_within_half_a_point ... ok
test a_link_broken_across_lines_is_one_entry_with_several_rects ... ok
test accepting_links_declines_the_delta_capability ... ok
test the_capability_is_echoed_only_when_requested_next_to_display_list_v2 ... ok
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
cargo test -p flashtex-render-pipeline --lib
test result: ok. 169 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out

Geometry against the oracle. pdflatex + hyperref on
See \url{https://example.com} and \href{https://ex.org/a}{click here} end.,
read back with PyMuPDF (page.get_links(), already y-down from the top-left):

https://example.com Rect(165.427001953125, 126.8499755859375, 266.7959899902344, 137.9749755859375)
https://ex.org/a    Rect(287.49700927734375, 126.8499755859375, 330.4739990234375, 137.9749755859375)

emitted (ticks / 2^20):

https://example.com [165.4199, 126.8506, 266.8021, 137.9749]
https://ex.org/a    [287.4972, 126.8506, 330.4739, 137.9749]

Largest deviation 0.007 bp, against §4's 0.5 bp bar. Note both rectangles
share a top and a bottom although one is typewriter and the other roman:
pdfTeX takes a link's height and depth from the line box, so the vertical
extent is the union of the line's cluster boxes (links::line_extent), not the
link's own glyph boxes. Taking it from the link's own glyphs put the \href
2.21 bp short; that is why line_extent exists.

Whole-crate run and the pre-existing failure:

cargo test -p flashtex-render-pipeline --no-fail-fast
test frame_env::shared_colorbox_path_draws_border_with_content_inside ... FAILED
  panicked at src/adapter.rs:1308: assertion `left == right` failed: left: 2, right: 1

Pre-existing on main — the identical assertion fails on a clean
9c5b028d worktree, unrelated to this change (colorbox path drawing). Every
other binary is green.

Not done

  • PDF link annotations. render-pipeline/src/pdf.rs calls
    flashtex_pdf::exact::render_exact, so an exported PDF still has no
    /Annots. navigation::Navigation and render_exact_with already exist in
    the pinned vendor/pdf (pdf: hyperref link annotations, named destinations and outlines (exact route) + links contract proposal #132), so this needs no vendor edit — it is a
    stacked PR on this branch, per the small-PR preference.
  • Internal destinations, outline and metadata. destinations entries,
    outline, outline_open, page_mode, open_action, info and
    border/color are all hyperref option/anchor state that the pinned
    compiler does not expose. Every link is therefore class: "url" with a
    uri target; target: {destination: ..} needs compiler: hyperref options, autoref/nameref, link/destination/bookmark records (35/132) #131's compiler records and a
    vendor/ re-pin.
  • Macro-body links yield nothing (see above).
  • The compiler's one-shot "links are not clickable in the preview/PDF yet"
    warning still fires even when the capability is negotiated. It comes from the
    frozen vendor/compiler and suppressing it here would change the
    diagnostics bytes of an otherwise unrelated reply; it should go with the
    re-pin.
  • apps/mac's test target does not compile on main
    (PreviewV2Tests.swift:807, from Preview page readout works on the pane that ships #689), so the Swift side of this could not
    be executed end to end. That is main's state, not this branch's, and is worth
    its own fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

…clickable (#323)

What changed:
- `v1::CAP_LINKS`: `display-list-v2-links` is negotiated, accepted only next
  to `display-list-v2`, echoed when accepted, and dropped with the parent.
  Accepting it declines `display-list-v2-delta`, the way `-window` does: the
  `display_list_delta` line carries its own header and no `navigation`, so a
  frame rebuilt from base + delta would have no links at all.
- New `links` module: finds every `\url`/`\href` in the source (mirroring the
  compiler's own `url_argument` — braced arguments, nested braces, `\{`/`\}`,
  `%` comments, `\nolinkurl` excluded), attributes glyph clusters to them by
  source span, and unions them into link rectangles.
- `DisplayList::navigation`, serialised as the top-level `navigation` object
  by both JSON writers when `Wire::links` is on and the document has a link.
  Anything else is byte-for-byte the line it was.

The URI has to be read back out of the document's own bytes: the pinned
`vendor/compiler` has no link record to read — `\url` keeps only its text and
`\href` drops its URL (`let (_url, url_span) = ..`), because #131 never
merged. A `\url`/`\href` from a macro body carries the invocation's span and
so yields no link; that limitation is documented in the module and in §7 of
the proposal, which also corrects its own "producer inputs already exist"
claim. Nothing here resolves or opens a URI — it records a string and a
rectangle, and the Mac consumer applies its scheme allowlist.

Rectangles reproduce pdfTeX: horizontal extent from the link's own glyphs,
vertical extent from the line box (the union of the line's cluster boxes, so
a roman `\href` and a typewriter `\url` on one line share a top and bottom,
as pdflatex gives them), all four sides grown by `\pdflinkmargin` = 1pt.

What was run:
- cargo test -p flashtex-render-pipeline --test links_navigation
  test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- cargo test -p flashtex-render-pipeline --lib
  test result: ok. 169 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
- pdflatex + PyMuPDF oracle on the same source:
  https://example.com Rect(165.427001953125, 126.8499755859375, 266.7959899902344, 137.9749755859375)
  https://ex.org/a    Rect(287.49700927734375, 126.8499755859375, 330.4739990234375, 137.9749755859375)
  emitted: [165.4199, 126.8506, 266.8021, 137.9749] and
           [287.4972, 126.8506, 330.4739, 137.9749] — max delta 0.007 bp
           against the proposal's 0.5 bp bar.

Next step: the PDF half of #323 as a stacked PR — `render-pipeline/src/pdf.rs`
calls `flashtex_pdf::exact::render_exact`, so an exported PDF still has no
`/Annots`; `render_exact_with` and `navigation::Navigation` already exist in
the pinned `vendor/pdf` and need no vendor edit.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
…mance job)

What changed:
- `crates/perf-bench/src/measure.rs` lists every `v1::Capabilities` field
  explicitly, so the new `links` field has to be named there too. CI's "engine
  performance" job builds this crate and failed on E0063.

What was run:
- cd crates/perf-bench && cargo build --all-targets
  builds, except the pre-existing macOS-only `memprofile` link error
  (`_malloc_trim`, a glibc symbol; that bin is built on the Linux runner).
- cd crates/flashtex-cli && cargo build --all-targets
  clean; it is the other crate depending on ../render-pipeline.

Next step: none; this closes the only cross-crate fallout of the new field.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up commit 7ef85285: crates/perf-bench/src/measure.rs lists every v1::Capabilities field explicitly, so the new links field had to be named there too — CI's "engine performance" job builds that crate and failed on E0063. The repo is a set of independent cargo projects rather than one workspace, so cargo test inside crates/render-pipeline could not have caught it; I have since built both dependents directly:

cd crates/perf-bench   && cargo build --all-targets   # clean, except the pre-existing
                                                      # macOS-only memprofile link error
                                                      # (_malloc_trim, a glibc symbol)
cd crates/flashtex-cli && cargo build --all-targets   # clean

… x clusters

What changed:
- `links::navigation` asked `containing` for every cluster of every page, and
  `containing` walked the whole span list. On a bibliography page of 500
  `\url`s and 200k clusters that is 10^8 comparisons per compile, on the path
  the "engine performance" job measures.
- `SpanIndex` groups spans by document and sorts them by start byte, so
  attribution is one `partition_point` per cluster. `scan` yields one
  document's spans already sorted and never overlapping — a `\href` skips past
  its own body, so a `\url` inside link text is never a second span — which is
  what makes the single binary search exact rather than approximate; a
  `debug_assert` pins that invariant.

What was run:
- cargo test -p flashtex-render-pipeline --lib
  test result: ok. 169 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
- cargo test -p flashtex-render-pipeline --test links_navigation
  test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next step: none; the emitted bytes are unchanged, this is only the cost of
producing them.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Also cba3748f: links::navigation asked containing for every cluster and containing walked the whole span list — on a bibliography page of 500 \urls and 200k clusters that is ~10^8 comparisons per compile, on the path the "engine performance" job measures. SpanIndex makes it one partition_point per cluster.

The single binary search is exact rather than approximate because scan yields one document's spans already sorted by start and never overlapping (a \href skips past its own body, so a \url inside link text is never a second span); a debug_assert pins that invariant. Emitted bytes are unchanged.

cargo test -p flashtex-render-pipeline --lib
test result: ok. 169 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
cargo test -p flashtex-render-pipeline --test links_navigation
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

What changed:
- `--links` sets `Wire::links` for `--v2`, alongside the existing `--images`
  and `--device-color`. Off by default, so every existing caller's bytes are
  unchanged. Without it the binary that the oracle harness and hand debugging
  use could not produce a `navigation` object at all.

What was run:
- flashtex-render --tex main.tex --v2 out.json --links, then the emitted line
  decoded by the Mac app's own model (apps/mac FlashTeXProtocol, built from
  this tree, linked against a 20-line harness):

    decoded links: 2 destinations: 0
      page 1 class url rects 1 target uri("https://example.com") source main.tex:67..92
      page 1 class url rects 1 target uri("https://ex.org/a") source main.tex:97..132
    hit at first rect centre -> uri("https://example.com")
    hit just outside       -> MISS (correct)

  so the producer's shape is the one `RenderingV2.Navigation` decodes, and the
  consumer's own half-open `Rect.contains` hit test lands on the link.

Next step: none.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
What changed:
- Drops `apps/mac/Package.resolved`, which `swift build` created in my
  worktree while I was checking that the emitted `navigation` decodes with the
  Mac app's own model, and which `git add -A` then swept into 3d8b303. It is
  not on `main`, this lane does not own `apps/mac`, and nothing in this PR
  needs it. Removed in a new commit rather than by amending a pushed one.

What was run:
- git show --stat HEAD: one deletion, apps/mac/Package.resolved.

Next step: none.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

The consumer decodes what this emits — verified, not argued

`3d8b3030` adds `flashtex-render --links` (parity with `--images` / `--device-color`; off by default, so existing callers' bytes are unchanged). With it I could take a real emitted line and run it through the Mac app's own model — `apps/mac` `FlashTeXProtocol` built from this tree, linked against a 20-line harness that decodes `RenderingV2.Envelope` and uses the consumer's own half-open `Rect.contains`:

decoded links: 2 destinations: 0
  page 1 class url rects 1 target uri("https://example.com") source main.tex:67..92
  page 1 class url rects 1 target uri("https://ex.org/a") source main.tex:97..132
hit at first rect centre -> uri("https://example.com")
hit just outside       -> MISS (correct)

This mattered because Navigation.links and Navigation.destinations are non-optional in the Swift model, so a producer that omitted destinations would fail JSONDecoder outright — the failure mode #363 hit. destinations: {} is written on every navigation object for exactly that reason.

(This is as far as the Swift side can be taken today: the apps/mac test target does not compile on main — PreviewV2Tests.swift:807, from #689 — so DisplayListLinksTests itself still cannot run. That is main's state, not this branch's.)

6c432055 reverts a stray apps/mac/Package.resolved that swift build left in my worktree and git add -A swept into 3d8b3030; removed in a new commit rather than by amending a pushed one. The branch diff against main is now crates/ + the proposal only.

@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the whole-crate numbers in the PR body

The PR body reports one pre-existing failure. That was read off a partial
log while the run was still going. The completed run is 107 test binaries,
484 passed, 13 failed across 5 binaries
— and all 13 reproduce identically
on a clean 9c5b028d (origin/main) worktree: same binaries, same test
names, same counts.

cargo test -p flashtex-render-pipeline --no-fail-fast     # this branch
frame_env             1 failed   shared_colorbox_path_draws_border_with_content_inside
letter_class_geometry 5 failed   every_line_is_where_pdflatex_put_it,
                                 page_one_texttop_fil_pushes_the_first_baseline_down,
                                 the_raggedleft_group_closes_no_trivlist,
                                 opening_lines_are_one_paragraph_not_one_each,
                                 letter_paragraph_gaps_are_the_class_parskip
uline                 2 failed   uline_paints_a_rule_under_the_argument,
                                 uline_with_ulem_is_not_an_unsupported_error
underline_sout        4 failed   sout_paints_a_rule, text_mode_underline_paints_a_rule,
                                 sout_with_ulem_is_not_an_unsupported_error,
                                 text_mode_underline_is_not_an_unsupported_error
xcolor_oracle         1 failed   xcolor_fixtures_match_pdflatex

Same five binaries on a detached 9c5b028d worktree, built in its own target
directory:

frame_env             test result: FAILED. 0 passed; 1 failed; 1 ignored
letter_class_geometry test result: FAILED. 0 passed; 5 failed; 0 ignored
uline                 test result: FAILED. 0 passed; 2 failed; 0 ignored
underline_sout        test result: FAILED. 0 passed; 4 failed; 0 ignored
xcolor_oracle         test result: FAILED. 0 passed; 1 failed; 0 ignored

Identical. None of them touches links, navigation, capability negotiation or
JSON serialisation — they are colorbox path drawing, the letter class frame,
ulem, and the xcolor oracle. Nothing in this branch changed their outcome,
but the body's "every other binary is green" line was wrong as written, so
here is the real number.

The targeted evidence is unaffected:

--test links_navigation      ok. 7 passed; 0 failed
--test links_pdf_annotations ok. 3 passed; 0 failed
--lib                        ok. 169 passed; 0 failed; 1 ignored

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent Opus review of 6c432055, CHANGES REQUIRED. Good work overall — a real pdflatex/PyMuPDF oracle, the -links ⇒ decline -delta reasoning is right, and line_extent doesn't over-inflate next to display math. Blockers:

  1. links::scan has no notion of catcodes, so a \url inside \begin{verbatim} becomes a real clickable link pdflatex never creates — the rect sits exactly over the literal source text. Inline \verb correctly yields nothing, so the producer already contradicts itself.
  2. The wrapped-link test asserts rects.len() >= 2, leaving the per-line-fragment count unpinned — the one geometry the merge predicate at links.rs:274 decides. It's correct today (4 fragments → 4 rects), so pin it.
  3. navigation is silently window-scoped, and -links + -window is untested.

PR #737 — render-pipeline: emit display-list-v2 navigation so \href/\url are clickable (#323)

  • Head SHA: 6c432055adf2a717a9bb2bd84be2bedeeb22cd0e (verified against gh pr view 737 --json headRefOid)
  • Merge-base with origin/main (24974c9): 9c5b028d; 5 commits, +970/-20
  • Trial merge with origin/main: one trivial conflict, see below

Trial merge

CONFLICT (content): Merge conflict in crates/render-pipeline/src/lib.rs
<<<<<<< HEAD
pub mod links;
=======
pub mod inputenc;
>>>>>>> origin/main

Both sides add a pub mod line at the same point in the module list. Resolution is "keep both,
alphabetical". crates/render-pipeline/src/typeset.rs auto-merged. Nothing else conflicts. Not
pushed.

What it does

Adds crates/render-pipeline/src/links.rs: a byte scanner over each source document that finds
\url{..} / \href{..}{..}, recovers the URI by reading the document's own bytes (the pinned
vendor/compiler discards it — Parsed::hyperref never landed), and attributes glyph clusters to a
link by testing each cluster's Provenance::Source span against the scanned spans. Rectangles are
the union of the merged cluster boxes, vertically grown to the line box (line_extent) and then by
\pdflinkmargin (1 pt) on every side. Wire::links gates serialisation; Capabilities gains
CAP_LINKS, which is accepted only next to display-list-v2 and deliberately declines -delta.

The design is sound and the reasoning in the doc comments is unusually good. The URI-from-source-span
recovery, the line-box reconstruction, and the -links ⇒ decline -delta rule are all correct, and
the geometry is checked against a real pdflatex + PyMuPDF oracle rather than against itself. The
findings below are one false positive, one test that does not pin the property it is named for, and
one unspecified capability interaction.


MATERIAL findings

1. A \url/\href inside verbatim (or any verbatim-like environment) produces a spurious clickable link

crates/render-pipeline/src/links.rs:116-171 — scan is a plain byte walk over the document. It
knows about % comments and \nolinkurl, but nothing about TeX catcodes or verbatim regions, so
inside \begin{verbatim} … \end{verbatim} it still reports a LinkSpan. The clusters the compiler
emits for that literal text carry source spans nested inside the reported span, so
SpanIndex::containing (:406-413) matches them and a link is produced over text that is typeset
as source, not as a link.

Verified in the worktree:

PROBE verbatim-url: 1 link entries
   page=1 uri=https://ex.org/verb nrects=1 [132.77,146.78,265.52,157.90] h=11.13

(document: Before.\n\begin{verbatim}\n\url{https://ex.org/verb}\n\end{verbatim}\nAfter.)

pdflatex + hyperref creates no annotation here: verbatim sets \ to catcode 12, so \url is
never a control sequence and nothing is linked. The rectangle's width (132.75 bp) matches a
monospace rendering of the whole literal string \url{https://ex.org/verb} — the link covers the
visible source text.

Failure scenario. Any LaTeX manual, tutorial or README that shows \url{...} or
\href{...}{...} in a code block — the single most likely place for those strings to appear
verbatim — renders a clickable region over the sample code, pointing at a URL the author was
demonstrating, not publishing. Combined with \href, the URI can be entirely different from the
text under the rectangle.

Note the inconsistency this creates: \verb|\url{https://ex.org/v2}| correctly yields
navigation=None (probed), because inline \verb clusters do not carry a matching provenance
span. So the producer is already right for one verbatim form and wrong for the other, with nothing
marking the difference.

Fix. Teach scan to skip verbatim-like regions before it reports spans: at minimum
\begin{verbatim} / \end{verbatim} and verbatim*, plus lstlisting (the corpus already has a
listings fixture) and \verb<delim>…<delim>. The scanner already tracks % and \nolinkurl, so
this is the same kind of rule in the same loop. A test alongside
nolinkurl_is_not_a_link_and_a_commented_url_is_not_either (links.rs:453) would pin it.

The corpus does not catch this: fixtures/real-world/listings-manual/main.tex is the only fixture
with verbatim-like environments, and its four \url/\href uses (:48, :49, :51, :186) all
sit in ordinary prose. The suite is silent on the case for exactly the reason the bug is easy to
miss.

2. The wrapped-link test does not pin the number of rectangles, which is the one geometric property nothing else checks

crates/render-pipeline/tests/links_navigation.rs:230

assert!(nav.links[0].rects.len() >= 2, "a wrapped URL is several line pieces: {:?}", ...);

pdflatex emits exactly one /Link rectangle per line fragment; >= 2 passes at 2 and at 40. The
ORACLE at :172-176 pins exact coordinates, but only for the single-rectangle case, so the piece
count — the thing the test is named for — is unpinned.

That matters because the merge predicate is the only part of the geometry with no oracle behind it
(links.rs:274-284):

Some((p, last))
    if *p == page.number && y0.0 < last.y1.0 && y1.0 > last.y0.0 && x0.0 >= last.x0.0 =>

x0.0 >= last.x0.0 compares the incoming cluster against the accumulated rectangle's left
edge, not its right edge. For a link whose first line begins at the left margin — the ordinary case
for a link that fills a measure — every subsequent line's first cluster also satisfies it, so the
only thing separating line 1 from line 2 is y0 < last.y1 && y1 > last.y0, i.e. that consecutive
lines' cluster boxes never vertically overlap. That holds today: I probed the test's own document
and got the right answer,

PROBE wrapped: 1 link entries
   page=1 uri=https://ex.org/wrapped nrects=4
     [239.10,126.91,478.48,137.70] [132.77,138.86,478.48,147.72]
     [132.77,150.82,478.48,159.67] [132.77,162.77,171.85,171.63]

four fragments, four rectangles, x-extents running to the right margin as a justified wrapped link
should — so this is not a live defect. It is a live coverage gap: any future change to cluster
box heights, leading, or line_extent that makes adjacent lines overlap by one tick silently fuses
a multi-line link into a single rectangle covering the whole block, and the suite still passes.

Fix. Run the wrapped document through pdflatex + PyMuPDF the way ORACLE was produced and
assert the exact rects.len() and each rectangle, or at minimum assert the count and that each
piece's y0 is at or below the previous piece's y1 (no vertical overlap between pieces). The
existing monotonic-y0 loop at :232-234 does not catch a fuse, because a fused rectangle leaves
one piece and the loop over windows(2) is then empty.

3. navigation is silently window-scoped, and -links + -window is unspecified and untested

crates/render-pipeline/src/links.rs:246 — let PageContent::Resident(items) = &page.content else { continue };. Clusters on non-resident pages are never attributed, so a span whose only clusters
are outside the window accumulates nothing and produces no Link at all.

Capabilities::negotiate (v1.rs:150-158) makes -links decline -delta, with a good reason
spelled out in CAP_LINKS's doc comment — a frame rebuilt from base + delta has no navigation.
The identical argument applies to -window and is not made: -links and -window are both
accepted, and the resulting navigation covers only the pages that happened to be resident. Nothing
in protocol/proposals/display-list-v2-links.md says navigation.links is window-scoped, so a
consumer that holds the last navigation while scrolling — the natural implementation — shows links
for one window and none elsewhere. crates/render-pipeline/tests/links_navigation.rs never
negotiates the two together.

This also decides whether #739's PDF export is correct: if the exporter consumes a DisplayList
that was assembled windowed, the exported PDF has annotations only for the window. (Checked in the
#739 review: the exporter walks the whole list, so this does not bite there — but it is load-bearing
and worth making explicit rather than incidental.)

Fix. Either state in the proposal (§3) and in Navigation's doc comment that links covers the
resident window only, and add a test negotiating [-v2, -window, -links] that pins it; or, if the
intent is whole-document links, build navigation from the pre-window page list. Do not leave it to
be inferred from the else { continue }.


Non-blocking notes

  1. Six of the seven integration tests are no-ops without Latin Modern. Every test in
    links_navigation.rs opens with if !lm_available() { return; }, including
    the_two_json_writers_agree_with_navigation_present (:246) — the only coverage of
    write_navigation vs navigation_json byte-identity, since the existing unit-level parity tests
    in display.rs (:2306, :2323, :2345) all construct navigation: None. On a machine or CI
    leg without LM fonts, the two writers drifting apart is completely undetected. A hand-built
    Navigation in a display.rs unit test would cover it unconditionally. (Both writers do agree
    today: keys are alphabetical in both — destinations/links, then
    class/page/rect|rects/source/target, then document/end/start, then
    page/view/x/y — and the test passed here.)

  2. line_extent's single-hop union does not over-inflate next to display math. I probed the
    case the doc comment worries about from the other side — a \[\sum_{i=0}^{n}\frac{x_i}{y_i} = \int_0^1 f\] immediately above, and immediately below, a \url line. Rectangle height stays
    11.13 bp in both, matching the ORACLE's 137.975 − 126.850 = 11.125 bp. A tall inline fraction
    on the same line also leaves the height at 11.13 (it shifts the whole band, correctly). The
    comment's reasoning holds in practice.

  3. Adjacent links overlap by ~2 bp, and that is right. \url{a}\url{b} back to back gives
    x1 = 238.63 and x0 = 236.63, because each side is grown by LINK_MARGIN_TEX_PT (1 pt ≈
    1.00375 bp). That is pdfTeX's \pdflinkmargin behaviour, not a bug — worth a line in the
    proposal so a consumer does not "fix" it.

  4. \href around non-text content works. \href{u}{\includegraphics{...}} (h = 11.96 bp) and
    \href{u}{\textbf{click here}} (h = 8.96 bp) both produce a link; a link in a \section heading
    (h = 14.59 bp) and in a \footnote (h = 10.36 bp) both resolve. Good — these were the cases I
    expected the span-containment approach to miss, and it does not.

  5. destinations is always empty and class is always "url". Internal \ref/\label
    navigation (hyperref's link class) is not produced; LinkSpan::class (links.rs:50-52) says
    so, Navigation { destinations: BTreeMap::new() } at :345 is where it would go. Fine as a
    staged landing, but it means hyperref-toc's \tableofcontents entries are not clickable and
    render-pipeline: an exported PDF carries real /Link annotations (#323) #739 has no internal destinations to write. Worth stating in the PR body as a known scope limit
    rather than leaving it to the reader of :345.

  6. Macro-expanded links produce nothing, documented at links.rs:19-22 and inherent to the
    span-recovery approach (\newcommand{\site}{\url{...}} gives the clusters the invocation's
    span). Correctly called out; no action.

  7. Cost. navigation is skipped entirely when spans.is_empty() (links.rs:239-241), so a
    link-free document pays only one linear scan per source. A document with even one link pays, per
    resident page, a push of (top, bottom) for every cluster plus a sort and dedup
    (links.rs:247-258), on top of the per-cluster attribution. cba3748f removed the quadratic
    spans × clusters term; this sweep is what remains. The four link-bearing corpus fixtures
    (hyperref-toc, listings-manual, conf-paper, cv) are where it will show.

  8. Panic safety looks clean. braced_argument (links.rs:196-228) exits an unterminated group
    through text[pos..].chars().next()? rather than indexing, and every pos advance is by
    len_utf8, so no mid-char slice. In scan, &text[name_start..j] is only reached when
    b[name_start] is ASCII alphabetic, and the control-symbol branch (:136-140) advances by raw
    bytes but never slices, so \ followed by a multi-byte character cannot panic. The unit tests
    cover unterminated, empty, and oversized (MAX_URI_BYTES) arguments.

Corpus digest impact

No digest changes. crates/perf-bench digests are hex16 of the serialised reply
(measure.rs:361) and of the exported PDF bytes (:423). The bench negotiates
Capabilities { …, links: false } (measure.rs:598, the one line this PR changes there) and writes
its v2 line with v2.write_json_with("perfbench", true) (:607), which hardcodes
Wire { …, links: false } (display.rs:965). wire_navigation (:945-947) therefore returns
None and no navigation key is emitted, so cold.reply, export.pdf and every warm.* digest
are byte-identical. What does change for the four link-bearing fixtures
(hyperref-toc/main.tex:62,158,159; listings-manual/main.tex:48,49,51,186;
conf-paper/main.tex:166; cv/main.tex:20) is time: navigation is built unconditionally in
assemble_windowed (typeset.rs:9083-9089) regardless of what was negotiated, so note 7's cost
lands on assemble_ms for those four and not on the other 19. Worth a note in the PR body so the
bench job's regression on exactly those fixtures is not mistaken for noise.

Tests run

crates/render-pipeline, nice -n 15 CARGO_BUILD_JOBS=3 CARGO_TARGET_DIR=~/flashtex-wt/review-target cargo test --locked:

  • --test links_navigation → 7 passed, 0 failed (LM fonts present, so the pdflatex-oracle test
    link_rectangles_match_pdflatex_within_half_a_point really ran)

Plus a throwaway probe harness (12 documents, removed afterwards) covering verbatim, \verb,
display math above/below, tall inline math, \href around an image / bold / section / footnote,
adjacent links, and the wrapped case — results quoted above.

VERDICT: CHANGES REQUIRED

@jay3332
jay3332 merged commit 6c47613 into main Sep 19, 2026
21 of 22 checks passed
jay3332 added a commit that referenced this pull request Sep 19, 2026
…ries real /Link annotations (#323)

Stacked on #737 (merged just above). The perf-bench baseline conflict is
resolved to main's file; the four hyperlink fixtures' `export.pdf` digests
are re-recorded from a --release run in a follow-up commit on this lane
(see `merge_digests.py`).

Implementation-Agent: Claude Code (mac-claude-a / lane-integrate2)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
jay3332 added a commit that referenced this pull request Sep 19, 2026
…he integration batch + package definitions

The pin reads main again after the second integration pass (#827 cherry-picks,
#863, #950, #737/#739/#758/#732/#740/#825, visual-oracle tooling) and the
`metadata.packages` work (`crate::package_definitions`, tex-expansion's
`package_defs.rs`). `git archive` of this tree's `crates/compiler` and
`crates/tex-expansion`, PINs at the merge commit, VENDORING.md rows updated,
`scripts/check-vendor-pins.sh` both "up to date". render-pipeline 819/0 in
both profiles against the new pins; compiler 1368/0, tex-expansion 150/0
release; Mac inventory sync current; swift build clean.

Implementation-Agent: Claude Code (mac-claude-a)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
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.

2 participants