Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged citations aren't sorted in increasing order #115

Closed
1 task done
Enivex opened this issue Nov 30, 2023 · 3 comments · Fixed by #168
Closed
1 task done

Merged citations aren't sorted in increasing order #115

Enivex opened this issue Nov 30, 2023 · 3 comments · Fixed by #168
Labels
bug Something isn't working

Comments

@Enivex
Copy link

Enivex commented Nov 30, 2023

Description

At least when using the IEEE style, merged citations are not sorted in increasing order, unless that happens to be the first time they are cited. This means one might end up with something ugly like [48], [49], [35], [50] instead of the more compact [35], [48]-[50].

Reproduction URL

No response

Operating system

No response

Typst version

  • I am using the latest version of Typst
@Enivex Enivex added the bug Something isn't working label Nov 30, 2023
@zepinglee
Copy link
Contributor

The latest version of IEEE reference guide (V 11.29.2023, accessed from https://journals.ieeeauthorcenter.ieee.org/your-role-in-article-production/ieee-editorial-style-manual/) requires all citations written out without compressing.

Screenshot 2023-12-01 at 20 55 35

The citations are not sorted as specified in the CSL style. This can be reproduced with Typst v0.9.0 and the following MRE.

@ieee.a.1:01 @ieee.b.1:01 @ieee.k.1:01 @ieee.o.1:01

@ieee.b.1:01 @ieee.k.1:01 @ieee.a.1:01 @ieee.o.1:01

#cite(<ieee.b.1:01>) #cite(<ieee.k.1:01>) #cite(<ieee.a.1:01>) #cite(<ieee.o.1:01>)

#bibliography("test.bib", style: "ieee")
@book{ieee.a.1:01,
  title = {Robot Vision},
  author = {Klaus, B. and Horn, P.},
  year = {1986},
  publisher = {{MIT Press}},
  address = {{Cambridge, MA, USA}}
}

@inproceedings{ieee.b.1:01,
  title = {Analytical Placement Technique for Sparse Arrays},
  booktitle = {32nd {{ESA}} Antenna Workshop},
  author = {Caratelli, D. and Vigan{\'o}, M. C. and Toso, G. and Angeletti, P.},
  year = {2010},
  address = {{Noordwijk, The Netherlands}}
}

@article{ieee.k.1:01,
  title = {Induction of Electric Field in Human Bodies Moving near {{MRI}}: {{An}} Efficient {{BEM}} Computational Procedure},
  author = {Chiampi, M. M. and Zilberti, L. L.},
  year = {2011},
  month = oct,
  journal = {IEEE Trans. Biomed. Eng.},
  volume = {58},
  pages = {2787--2793},
  doi = {10.1109/TBME.2011.2158315}
}

@phdthesis{ieee.o.1:01,
  title = {Narrow-Band Analyzer},
  author = {Williams, J. O.},
  year = {1993},
  type = {Ph.D. dissertation},
  address = {{Cambridge, MA, USA}},
  school = {Dept. Elect. Eng., Harvard Univ.}
}
Screenshot 2023-12-01 at 20 58 44

@Enivex
Copy link
Author

Enivex commented Dec 1, 2023

The latest version of IEEE reference guide (V 11.29.2023, accessed from https://journals.ieeeauthorcenter.ieee.org/your-role-in-article-production/ieee-editorial-style-manual/) requires all citations written out without compressing.

That specific change would not be typst's responsibility though, but on https://github.com/citation-style-language/styles

The sorting merged citations I assume is not specific to IEEE.

@laurmaedje laurmaedje transferred this issue from typst/typst Dec 15, 2023
@jclederman
Copy link

jclederman commented Dec 23, 2023

Looks like sorting items within a citation by citation number has not been implemented yet. The key code is in csl/sort.rs:

pub fn sort<T: EntryLike>(
        &self,
        cites: &mut [CitationItem<T>],
        sort: Option<&Sort>,
        term_locale: Option<&LocaleCode>,
    ) {
        if let Some(sort) = sort {
            cites.sort_by(|a, b| {
                let mut ordering = Ordering::Equal;
                for key in &sort.keys {
                    ordering = self.cmp_entries(a, 0, b, 0, key, term_locale);
                    if ordering != Ordering::Equal {
                        break;
                    }
                }
                ordering
            });
        }
    }

cmp_entries is fed 0's for the citation numbers, rather than collecting them from the items. Item sorting within a citation never appears to happen within BibliographyDriver::finish, nor could it using the current sort function. I imagine sort may need to be adjusted to wire the citation numbers in after they are generated with the citation_number closure.

lluchs added a commit to lluchs/hayagriva that referenced this issue May 16, 2024
We need to defer sorting the citations until the citation numbers are
assigned.

Fixes typst#115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants