Skip to content

Commit 25ab09d

Browse files
claude: Add minimal test for code listing alignment verification
Add code-listing-alignment.qmd test that documents proper usage of ensurePdfTextPositions for code blocks. Key finding: the subject text must be the FIRST token in the code block because pdftotext extracts words separately and reports their individual positions. Also update orange-book test to use ALIGNTEST_MARKER as first token. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 37ce214 commit 25ab09d

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Code Listing Alignment Test
3+
format: typst
4+
_quarto:
5+
tests:
6+
typst:
7+
ensurePdfTextPositions:
8+
- # Code listing should be left-aligned with body text
9+
# IMPORTANT: The subject must be the FIRST token in the code block.
10+
# pdftotext extracts words separately, so subsequent words appear
11+
# offset by their position within the line, not aligned with margin.
12+
- subject: "CODESTART_func():"
13+
relation: leftAligned
14+
object: "BODYTEXT_ALIGN_MARKER"
15+
tolerance: 5
16+
---
17+
18+
BODYTEXT_ALIGN_MARKER is body text that should left-align with code listings.
19+
20+
```{#lst-test .python lst-cap="Test Listing"}
21+
CODESTART_func():
22+
print("Hello, World!")
23+
```
24+
25+
See @lst-test for the test listing.

‎tests/docs/smoke-all/typst/orange-book/chapter1.qmd‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ See @lem-triangle for the inequality.
9191
LISTING_BODY_ALIGN_TEST is body text that should left-align with code listings.
9292
9393
```{#lst-hello .python lst-cap="Hello World in Python"}
94+
# ALIGNTEST_MARKER
9495
def hello():
9596
print("Hello, World!")
9697

‎tests/docs/smoke-all/typst/orange-book/index.qmd‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ _quarto:
250250
- "Lamport \\(1978\\) for temporal considerations"
251251
ensurePdfTextPositions:
252252
- # Code listings should be left-aligned with body text, not centered
253-
- subject: "hello():"
253+
- subject: "ALIGNTEST_MARKER"
254254
relation: leftAligned
255255
object: "LISTING_BODY_ALIGN_TEST"
256-
tolerance: 25
256+
tolerance: 15
257257
---
258258

259259
# Preface {.unnumbered}

0 commit comments

Comments
 (0)