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

Prevent duplicate labels in :alpha style #31

Merged
merged 1 commit into from
Sep 12, 2023
Merged

Prevent duplicate labels in :alpha style #31

merged 1 commit into from
Sep 12, 2023

Conversation

goerz
Copy link
Member

@goerz goerz commented Jul 29, 2023

This implements a stateful AlphaStyle that disambiguates the labels for the bibliography by appending a suffix "a", "b", etc. This emulates the behavior of the numeric citation style in LaTeX.

The existing :alpha style is automatically upgraded to the new AlphaStyle. It's a lot easier for users to pass style=:alpha than to instantiate the full AlphaStyle, in particular because AlphaStyle needs access to all the entries of the .bib file (so instantiating in manually would end up reading the .bib file twice). Moreover, there's no reason anyone would ever want to use the old "dumb" :alpha style.

In addition to the new AlphaStyle, this also fixes some inconsistencies relative to the alphabetic citation style in LaTeX:

  • Up to four names are included in the label, not 3 (but 5 or more names results in 3 names and "+")
  • The first letter of a "particle" of the name is included in the label, e.g. "vWB08" for a first author "von Winckel"

Closes #26

@goerz
Copy link
Member Author

goerz commented Jul 31, 2023

@goerz goerz marked this pull request as draft August 1, 2023 17:33
@goerz
Copy link
Member Author

goerz commented Aug 1, 2023

I'm going to mark this as "Draft" for now, since #29 convinced me that I'll probably want to tweak the arguments for the internal functions a little bit, and pass around the full CitationBibliography object (the instantiated plugin). The plugin object contains lots of state: all entries in the .bib file, all citations, which order they were cited in. The lack of access to this state in the various format_* routines already made AlphaStyle a little cumbersome, and implementing #29 or the most general version of #13 would likely be even more cumbersome.

So I'll probably make the changes to the internals and rebase this PR on top of that.

This implements a stateful `AlphaStyle` that disambiguates the labels
for the bibliography by appending a suffix "a", "b", etc. This emulates
the behavior of the numeric citation style in LaTeX.

To enable the generating of unique labels, there is a new internal
`init_bibliography!` function that is called at the beginning of the
`ExpandBibliography` pipeline step.

The existing `:alpha` style is automatically upgraded to the new
`AlphaStyle`. It's just easier for users to pass `style=:alpha` than to
instantiate the full `AlphaStyle`. Moreover, there's no reason anyone
would ever want to use the old "dumb" `:alpha` style.

In addition to the new `AlphaStyle`, this also fixes some
inconsistencies relative to the alphabetic citation style in LaTeX:

* Up to four names are included in the label, not 3 (but 5 or more names
  results in 3 names and "+")
* The first letter of a "particle" of the name is included in the label,
  e.g. "vWB08" for a first author "von Winckel"
@goerz
Copy link
Member Author

goerz commented Sep 4, 2023

#29 convinced me that I'll probably want to tweak the arguments for the internal functions a little bit, and pass around the full CitationBibliography object (the instantiated plugin).

It turns out there's a more elegant solution that doesn't require breaking backwards compatibility at all (not that the internal functions are part of the stable API; but I'd still rather not change them unless absolutely necessary):

I've added a new internal function init_bibliography!(style, bib) that is called at the beginning of the ExpandBibliography pipeline step. For the default :numeric style, this function does nothing, but for the revised :alpha/AlphaStyle(), this is where the unique keys for all entries in the .bib file are calculated and cached in an internal attribute of AlphaStyle.

It's a much cleaner implementation for the "smart" :alpha style than the previous iteration, and it also addresses #29.

This should now be ready for a final review and merge, and then I'll follow up with #32

@goerz goerz marked this pull request as ready for review September 4, 2023 16:36
Copy link
Contributor

@kellertuer kellertuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks good to me, though I can not for a 100% review the internal code – the functionality seems to work very nicely.

@goerz
Copy link
Member Author

goerz commented Sep 9, 2023

@fredrikekre Can I go ahead and merge, or did you want to further review this?

Also, since we didn't explicitly talk about this when QuantumCitations got merged back into DocumenterCitations and moved here: Should I still consider myself the primary maintainer of this project, as a direct continuation of QuantumCitations?

If yes, I would be a bit more direct in pushing the further development:

  • I'll make general design decisions if they come up while dealing with PRs. I'll review and merge PRs.
  • I'll organize tooling and CI mostly according to my needs and may push trivial and tooling-related commits directly to master
  • I'll make any non-trivial changes via PRs and give people at least a week for review, but I'll ultimately merge my own PRs if there's no feedback. For any major changes or if I'm responding to feature requests, I'll actively solicit reviews/approval.
  • I'll tag new releases and manage release notes, following semver.

None of this precludes any co-maintainers, i.e. you/anyone with push access to the repo from also doing any of those same things. In any case, especially with the transition to Documenter 1.0, I'll be coordinating with you and @mortenpi via comments here or on the #Documentation Slack channel.

@goerz
Copy link
Member Author

goerz commented Sep 11, 2023

If there are no further comments, I will merge this tomorrow

@goerz goerz merged commit 0706596 into master Sep 12, 2023
13 of 14 checks passed
@goerz goerz deleted the mg/alphastyle branch September 12, 2023 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate keys in :alphabetic style
2 participants