Skip to content

Commit 878768f

Browse files
committed
fix: centre the annotation circles on the cap height of their text
1 parent 3fff6de commit 878768f

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎llm-docs/typst-code-annotations.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ A fenced echo block (`{{python}}`) gets one extra line, because the filter write
5757

5858
## Rendering helpers (`definitions.typ`)
5959

60-
- `quarto-circled-number` draws the circle. It sits inside a `math.equation` that carries the text alternative "Annotation N", because `box`, `text` and `link` do not accept `alt`. The circle sits in a zero-height box, so it overflows its row and adds no height. That box needs `baseline: 0.55em` with a matching `move(dy: -0.55em)`. With the default baseline, a zero-height box still raises the top of its line by about 0.8pt, and the second annotated row ends up taller than a plain row.
60+
- `quarto-circled-number` draws the circle. It sits inside a `math.equation` that carries the text alternative "Annotation N", because `box`, `text` and `link` do not accept `alt`. The circle sits in a zero-height box, so it overflows its row and adds no height. That box needs `baseline: 0.55em` with a `move(dy: -0.63em)`, which centres the circle on the cap height of the text. With the default baseline, a zero-height box still raises the top of its line by about 0.8pt, and the second annotated row ends up taller than a plain row.
6161
- `quarto-annote-link` links only when the target label exists, so a missing list degrades to an unlinked circle.
6262
- `quarto-code-annotation` is the native-mode renderer. The Skylighting patch contains its own per-line copy of the same layout. Change both together.
6363
- With `.number-lines`, annotated rows use `width: 100% - annote-ln-width` so the circle stays on the code line.

‎src/resources/formats/typst/pandoc/quarto/definitions.typ‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// A zero-height box lets the circle overflow instead of making its row taller.
3131
// The 0.55em baseline offset, undone by the move, stops the box from raising its line.
3232
// The equation wrapper carries the text alternative.
33-
box(height: 0pt, baseline: 0.55em, move(dy: -0.55em, math.equation(alt: "Annotation " + str(n), block: false, circle(
33+
box(height: 0pt, baseline: 0.55em, move(dy: -0.63em, math.equation(alt: "Annotation " + str(n), block: false, circle(
3434
radius: 0.55em,
3535
stroke: 0.5pt + c,
3636
)[#set text(size: 0.7em, fill: c); #align(center + horizon, str(n))])))

‎tests/docs/smoke-all/typst/code-annotations/code-annotations-alt.qmd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ _quarto:
99
typst:
1010
ensureTypstFileRegexMatches:
1111
-
12-
- 'box\(height: 0pt, baseline: 0\.55em, move\(dy: -0\.55em, math\.equation\(alt: "Annotation " \+ str\(n\)'
12+
- 'box\(height: 0pt, baseline: 0\.55em, move\(dy: -0\.63em, math\.equation\(alt: "Annotation " \+ str\(n\)'
1313
- 'annotations: \("1": 1\)'
1414
- 'quarto-annotation-item\("annotated-cell-1", 1, \['
1515
- []

0 commit comments

Comments
 (0)