typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
31.4k stars 851 forks source link

Querying citation labels returns `()` #4524

Closed hbierlee closed 1 week ago

hbierlee commented 2 weeks ago

Description

Hi,

See here. I believe query should work for citation labels like for headings, but it always returns an empty list ():

#bibliography("works.bib")
A queried ref of @knuth returns #{ context query(<knuth>) }

#set heading(numbering: "1.")

= Heading
<sec1>

A queried ref of @sec1 returns #{ context query(<sec1>) }

Given:

@book{knuth,
author = {Knuth, Donald E.},
title = {The art of computer programming, volume 1 (3rd ed.): fundamental algorithms},
year = {1997},
isbn = {0201896834},
publisher = {Addison Wesley Longman Publishing Co., Inc.},
address = {USA}
}

Render:

image

Cheers,

Henk

Reproduction URL

https://typst.app/project/wDfVPd0Ej5rAl9xPsdIBzN

Operating system

Linux

Typst version

Enivex commented 2 weeks ago

What exactly do you expect it to return?

hbierlee commented 1 week ago

Since citations are references, and references are locatable, I'd expect it to return a reference to the citation.

The context is that I want to show undefined references as TODO's in the document like:

#show ref: it => {
  if query(it.target).len() > 0 {
    it
  } else {
    it.target
  }
}

As per the issue I linked above. I can't discern undefined references from citations at the moment.

laurmaedje commented 1 week ago

The thing is that your query searches for elements with the given label, but neither the citation nor the reference have that label attached to themselves, they just reference it.

I don't think discerning the two cases is currently possible, at least without parsing the bibliography file.

hbierlee commented 1 week ago

I see, thanks for your time. Feel free to close as not planned or keep open for a future feature.

laurmaedje commented 1 week ago

Since the query itself is working as intended, I'll close this for now.