Repository navigation
Conversation
f9ad72e to
f92d4f1
Compare
laurmaedje
left a comment
There was a problem hiding this comment.
I didn't yet have a chance to do a proper full review, but I have a few initial comments already. Feel free to act on these already, but of course you can also wait for the full review (will get to that next week).
| /// When using multiple bibliographies in a single document, indicates | ||
| /// whether this bibliography should start numbering its citations after | ||
| /// the ones from previous bibliographies (`shared`) or start at 1 (`standalone`). | ||
| #[default("shared".into())] |
There was a problem hiding this comment.
I'd have imagined kind to default to auto as well. And standalone wouldn't mean start at 1, but rather "count together with all bibliographies that also have kind: "standalone". Basically each key is one counting track and auto is just the default track.
It still doesn't feel 100% great though as auto implies some extra smartness compared to a string, but there wouldn't be any.
There was a problem hiding this comment.
Thanks for your work, this is going into a good direction! :)
I left some comments. Besides that, it would be good if you could add some tests for the new functionality. Currently, CI is failing because of the missing hayagriva change. I'd like to wait with merging this until this PR is merge-ready. Until then, you could point from Cargo.toml to your hayagriva fork with the relevant change.
The PR will also need a merge or rebase because it has some conflicts with the introspection warnings changes.
| // 2. First preceding auto bibliography containing the label | ||
| let citations_and_bib = introspector | ||
| .query(&Selector::Or(eco_vec![CiteElem::ELEM.select(), Self::ELEM.select()])); | ||
| for (i, citation) in citations_and_bib.iter().enumerate() { |
There was a problem hiding this comment.
This is a bit problematic as the linear scans for the prev/following bibliography result in overall quadratic complexity. It would be good if we could get this down to
There was a problem hiding this comment.
For now I changed it so that it scans only the bibliography elements
| else if let Some(prev_bib) = citations_and_bib[..i] | ||
| .iter() | ||
| .rev() | ||
| .filter_map(|content| { | ||
| if content.elem() == Self::ELEM { | ||
| Some(content.to_packed::<Self>().unwrap().clone()) | ||
| } | ||
| else { | ||
| None | ||
| } | ||
| }) | ||
| .filter(|bibliography| { | ||
| bibliography.target.get_ref(StyleChain::default()).is_auto() | ||
| && bibliography.sources.derived.has(citation_key) | ||
| }) | ||
| .next() |
There was a problem hiding this comment.
The code duplication with the previous branch would ideally be avoided.
There was a problem hiding this comment.
I tried to factorize the code a bit, not completely happy about it but there is no more duplication.
| self.references | ||
| self.works | ||
| .get(&elem.location().unwrap()) | ||
| .unwrap() |
There was a problem hiding this comment.
these unwraps are not ideal. I think they maybe (?) could panic if a bibliography appears in the very last introspection iteration (see the added tests from #7364)
There was a problem hiding this comment.
I removed the unwrap there and returned the error instead
| if content.elem() == Self::ELEM { | ||
| Some(content.to_packed::<Self>().unwrap().clone()) | ||
| } | ||
| else { |
There was a problem hiding this comment.
The formatting is a bit off here. Could you format the files with rustfmt?
|
I looked into the span situation. In
In
This should at least work and unblock the PR. The overhead might be a bit higher than before, but the core logic could stay memoized. I might look into perf impact separately and would potentially adjust queries to return prehashed results to reduce hashing overhead at the memoization boundary, but that's not in scope for the PR. |
|
Hi, sorry I have been a bit out of touch these past few weeks. I am ok with making these changes; I think there are other instances that should be moved upwards outside of the memoization? E.g. calling |
|
I did what seemed best; not entirely sure about the correct span to give when calling |
|
It's great to see that this is being worked on again! The authors may already be aware of this: but since bundling was merged there is a new urgency for this, because AFAIK this extends to Typst documents that are being exported to the bundle format. This means that sites like this one, which has per-page bibliographies, cannot be created with the Typst bundle format currently. (This site was produced with Rheo.) |
|
@breezykermo This is mostly blocked on me right now, but it's a priority for 0.15 and it's still in my plans to get this in. |
|
Hi! I've opened #8307 to complete this. The design is still mostly the same, but I wanted to do some refactoring first and also change up how the citation grouping and assignment interacts, so in the end it made more sense to open a new PR. Thank you for your work nonetheless! It was quite useful to build upon and the design idea with having a selector that |
Hi Laurenz! Makes sense to me; glad that a similar design was retained. Looking forward to see the feature implemented in the next version! |
This implements support for multiple bibliographies, as wanted in #1097 and discussed on the Discord.
It introduces two new parameters to the
#bibliographyelement:targetindicates what is covered by the bibliography. It can either be a selector ofciteelements, or auto (default case). In the latter case, priority is given to the bibliographies with selectors; then, each citation is assigned to the next auto bibliography which contains the citation, or the previous one if it cannot be found.kindcan be either "shared" or "standalone" (actually anything other than "shared" right now); in the first case, the numbering will keep across bibliographies, in the second one the bibliography will start from one.This requires typst/hayagriva#409 to be merged in order for the numbering to work correctly.