Due to the way cite references work, there is no way to distinguish between a bibliographic reference or a nonexisting ref. See below, lorem
being a reference to a bibliographic item.
ref(
target: <lorem>,
supplement: auto,
form: "normal",
citation: cite(key: <lorem>, supplement: none),
element: none,
)
ref(
target: <ref>,
supplement: auto,
form: "normal",
citation: cite(key: <ref>, supplement: none),
element: none,
)
Instead, you can adapt your show rule to read the bibliography file and compare the keys to the label target. That’s doable with simple parsing (as long as your file is formatted with the @
and the key
on the same line).
#bibliography("test.bib")
#show ref: it => {
let bibfile = read("test.bib")
let entries = bibfile.split("@")
entries.remove(0) // ""
let keys = for entry in entries {
(entry.slice(entry.position("{")+1, entry.position(",")),)
}
if str(it.target) not in keys and query(it.target).len() == 0 {
"[" + str(it.target) + "]"
} else {
it
}
}