I’m writing an academic paper using Typst and need to add “cf.” (compare) to citations, both in-text and in footnotes. For example, instead of:
(Smith 2020, p. 15)
I’d like it to appear as:
(cf. Smith 2020, p. 15)
Or, if using a footnote:
Cf. Smith 2020, p. 15.
Is there a way to achieve this in Typst, either by modifying the citation style or using a custom function? Ideally, I’d like a flexible approach that works for different citation formats. Any help would be greatly appreciated!
You can use show rules to add the “cf.” in front of citations and footnotes. I am not sure whether you want to modify the footnote (in the text) or the footnote entry (in the page footer)? The show rule below works either way, just change the targeted function.
You could certainly create your own CSL style or modify an existing one. But I think the show rule should be flexible enough to cover most built-in citation styles.
// Replace "(" and ")" by "[" and "]" if your citation style uses square brackets
#show cite: it => [
(cf.
#{
show "(": none
show ")": none
it
})
]
// Use #show footnote instead if you want to modify the element in the text
#show footnote.entry: it => {
[Cf. ]
it
}
Thank you for your response! Using show rules is a great idea, but I need a way to decide when to use “cf.” and when not to.
Is there a way to make this optional—so I can enable or disable it for specific citations? Maybe through a custom function or an argument within the citation command?
I’d really appreciate any suggestions! Thanks again!
You can wrap cite() in a function that takes an additional boolean parameter cf. The show rule to add the “cf.” is then conditional.
#let my-cite(label, cf: false, supplement: none, form: "normal", style: auto) = {
show cite: it => if (cf) [
(cf.
#{
show "(": none
show ")": none
it
})
] else { it }
cite(label, supplement: supplement, form: form, style: style)
}
Alternatively you could also define a function cf-cite() that includes the show rule and use that whenever you want to include the “cf.” with a citation. Citations without “cf.” would then work with the regular function cite() or the shortcut @....
#let pre-foot-data = state("pre-foots", (foots: (), prefixes: ()))
// NOTE: This show rule has to go at the top of the document, before any content / text.
#show footnote.entry: it => context {
let foot-data = pre-foot-data.final()
let foot-num = counter(footnote).at(it.note.location()).first()
let foot-num-pos = foot-data.foots.position(s => s == foot-num)
if foot-num-pos != none {
let prefix = foot-data.prefixes.at(foot-num-pos)
show super: it => it + prefix + sym.wj
it
} else {
it
}
}
#let pre-cite(..args, prefix: none) = {
if prefix != none {
context {
let foot-num = counter(footnote).get().first() + 1
pre-foot-data.update(s => {
s.foots.push(foot-num)
s.prefixes.push(prefix)
s
})
}
}
cite(..args)
}
// Demo
#let cite-cf = pre-cite.with(prefix: "cf. ")
#let cite-see = pre-cite.with(prefix: "see ")
#set page(height: auto)
Citing @first and #cite-cf(<first>). Also#cite-see(<first>)
#bibliography("bibliography.bib", style: "chicago-notes")