Skip to content

Commit 8544e83

Browse files
claude: Preserve citation locators inline for margin citations
When citation-location: margin is set, locators (page numbers, chapters) now appear inline with the citation while full bibliographic entries appear in the margin: Inline: [1, p. 42] Margin: J. L. Borges, "La biblioteca de Babel"... 1941. The Cite handler keeps the original Pandoc Cite element (which renders as @key[locator] in Typst) and appends a margin note with the full citation via #cite(form: "full"). This replaces the column-margin-cite function which has been removed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 02f9f1d commit 8544e83

8 files changed

Lines changed: 89 additions & 31 deletions

File tree

‎src/resources/filters/quarto-post/typst.lua‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,22 @@ function render_typst()
120120
if marginCitations() then
121121
noteHasColumns() -- Activate margin layout
122122

123-
-- Build citation keys for Typst labels
124-
local keys = pandoc.List({})
123+
-- Build margin note content with full citations (no locators - those stay inline)
124+
local margin_entries = pandoc.List({})
125125
for _, c in ipairs(cite.citations) do
126-
keys:insert("<" .. c.id .. ">")
126+
margin_entries:insert("#cite(<" .. c.id .. ">, form: \"full\")")
127127
end
128-
local keyStr = table.concat(keys, ", ")
129128

130-
-- Emit: column-margin-cite which renders inline cite + full cite in margin
129+
-- Keep original Cite element (Pandoc renders it as Typst citation with locator inline)
130+
-- Append margin note with full bibliographic entries only
131131
local result = pandoc.Inlines({})
132-
result:insert(pandoc.RawInline("typst", "#column-margin-cite(" .. keyStr .. ")"))
132+
result:insert(cite) -- Original Cite element - Pandoc converts to @key[locator]
133+
result:insert(pandoc.RawInline("typst",
134+
"#note(alignment: \"baseline\", shift: auto, counter: none)[" ..
135+
"#set text(size: 0.85em)\n" ..
136+
table.concat(margin_entries, "\n") ..
137+
"]"
138+
))
133139
return result
134140
end
135141
end,

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,8 @@ $if(margin-geometry)$
206206
}
207207
}
208208

209-
// Margin citation - inline citation + full bibliographic entry in margin
210-
// Each citation key gets the inline citation, with full entry appearing in margin
211-
#let column-margin-cite(..labels) = {
212-
// Render inline citations
213-
for label in labels.pos() {
214-
cite(label)
215-
}
216-
// Full citation entries in margin
217-
note(
218-
alignment: "baseline",
219-
shift: auto,
220-
counter: none,
221-
)[
222-
#set text(size: 0.85em)
223-
#for label in labels.pos() [
224-
#cite(label, form: "full")
225-
]
226-
]
227-
}
209+
// Note: Margin citations are now emitted directly from Lua as #note() calls
210+
// with #cite(form: "full") + locator text, preserving citation locators.
228211

229212
// Utility: compute padding for each side based on side parameter
230213
#let side-pad(side, left-amount, right-amount) = {

‎tests/docs/smoke-all/typst/margin-layout/citation-margin-basic.qmd‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ _quarto:
1111
tests:
1212
typst:
1313
ensureTypstFileRegexMatches:
14-
- ['column-margin-cite', 'note\(', 'form: "full"']
14+
# Margin citations emit note() with cite(form: "full") directly
15+
- ['#note\(', 'form: "full"']
1516
- []
1617
ensurePdfRegexMatches:
1718
- ['Library', 'Borges', 'hexagon', 'infinite']

‎tests/docs/smoke-all/typst/margin-layout/citation-margin-elaborate.qmd‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ _quarto:
1313
tests:
1414
typst:
1515
ensureTypstFileRegexMatches:
16-
- ['column-margin-cite', 'note\(']
16+
# Margin citations emit note() with cite(form: "full") directly
17+
- ['#note\(', 'form: "full"']
1718
- []
1819
ensurePdfRegexMatches:
1920
- ['Universe', 'Library', 'hexagon', 'Vindication', 'Borges']
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "Margin Citation with Locators"
3+
papersize: us-letter
4+
citation-location: margin
5+
bibliography: borges-refs.bib
6+
format:
7+
html: default
8+
typst:
9+
keep-typ: true
10+
_quarto:
11+
tests:
12+
typst:
13+
ensureTypstFileRegexMatches:
14+
# Margin citations use direct note() calls with cite(form: "full")
15+
- ['#note\(', 'form: "full"']
16+
- []
17+
ensurePdfRegexMatches:
18+
- - 'LOCATOR-MARKER'
19+
- 'Borges'
20+
- 'Quain'
21+
# Locators appear INLINE after citation number [N, locator]
22+
- '\[1,\s*p\.\s*42\]' # borges1941library, p. 42
23+
- '\[2,\s*pp\.\s*100' # borges1944ficciones, pp. 100-115
24+
- '\[3,\s*ch\.\s*3\]' # quain1936labyrinth, ch. 3
25+
- '\[4,\s*p\.\s*200' # eco1980name, p. 200, fig. 5
26+
- []
27+
ensurePdfTextPositions:
28+
- # Full citation in margin - "bifurcan" is unique to borges1941library booktitle
29+
- subject: "bifurcan"
30+
relation: rightOf
31+
object: "LOCATOR-MARKER"
32+
# Locator appears inline (left of margin content)
33+
- subject: "p. 42"
34+
relation: leftOf
35+
object: "bifurcan"
36+
- []
37+
noErrors: default
38+
---
39+
40+
# Testing Citation Locators in Margins
41+
42+
LOCATOR-MARKER: The Library was first described with specific page references [@borges1941library, p. 42].
43+
44+
The expanded edition contains more details [@borges1944ficciones, pp. 100-115].
45+
46+
Chapter-specific references also work [@quain1936labyrinth, ch. 3].
47+
48+
Multiple locator types: see [@eco1980name, p. 200, fig. 5] for the library map.

‎tests/docs/smoke-all/typst/margin-layout/citation-margin-multiple.qmd‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ _quarto:
1111
tests:
1212
typst:
1313
ensureTypstFileRegexMatches:
14-
- ['column-margin-cite']
14+
# Margin citations emit note() with cite(form: "full") directly
15+
- ['#note\(', 'form: "full"']
1516
- []
1617
ensurePdfRegexMatches:
1718
- ['FIRST-CITE-MARKER', 'SECOND-CITE-MARKER', 'MULTI-CITE-MARKER', 'Vindication']

‎tests/docs/smoke-all/typst/typst-citeproc.qmd‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ format:
66
bibliography: refs.bib
77
citeproc: true
88
_quarto:
9-
tests:
9+
tests:
1010
typst:
1111
ensureTypstFileRegexMatches:
1212
- ['<refs>', '<ref-Cronbach_1951>']
1313
- ['\#bibliography\([^)]*\)']
14+
ensurePdfRegexMatches:
15+
# Locators appear inline after author-date (citeproc drops "p." prefix)
16+
- ['\(Cronbach 1951a, 42\)', '\(1951b, 100']
17+
- []
18+
noErrors: default
1419
---
1520

1621
Hello [@Cronbach_1951, @Cronbach_1952]
1722

23+
With locator: [@Cronbach_1951, p. 42]
24+
25+
Bare with locator: @Cronbach_1952[pp. 100-115]
26+
1827
# References

‎tests/docs/smoke-all/typst/typst-no-citeproc.qmd‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ format:
66
bibliography: refs.bib
77
bibliographystyle: "chicago-author-date"
88
_quarto:
9-
tests:
9+
tests:
1010
typst:
1111
ensureTypstFileRegexMatches:
1212
- ['\#set bibliography\(style\: [^)]*\)', '\#bibliography\([^)]*\)', '\#cite\([^)]*\)']
1313
- ['<refs>', '<ref-Cronbach_1951>']
14+
ensurePdfRegexMatches:
15+
# Locators appear inline after author-date: (Author Year, locator)
16+
- ['\(Cronbach 1951a, p\. 42\)', '\(1951b, pp\. 100']
17+
- []
18+
noErrors: default
1419
---
1520

1621
Hello @Cronbach_1951
1722

18-
Hello [@Cronbach_1951; @Cronbach_1952]
23+
Hello [@Cronbach_1951; @Cronbach_1952]
24+
25+
With locator: [@Cronbach_1951, p. 42]
26+
27+
Bare with locator: @Cronbach_1952[pp. 100-115]

0 commit comments

Comments
 (0)