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

Fix handling of trailing whitespaces in initials' delimiters #257

Merged
merged 3 commits into from
Dec 9, 2024

Conversation

PgBiel
Copy link
Contributor

@PgBiel PgBiel commented Dec 8, 2024

Fixes #137

Some styles, such as vancouver, require there to be nothing between initials, so Astley, Rick Gavin would be formatted as Astley, RG instead of Astley, R. G. (more usual) or Astley, R G for example. However, even when setting initializer-with="" (empty delimiter), Hayagriva was still forcing whitespaces between initials.

It was thought that #150 would have fixed it by only adding whitespaces if a delimiter was indeed specified, but it actually didn't change anything as there is always a delimiter - however, it is sometimes an empty string. While adding an explicit check for empty strings would have fixed this specific problem, it turns out Hayagriva's behavior of forcing a whitespace to always be added after the delimiter, replacing any of its trailing whitespaces if there are any (otherwise, one is added anyways), is not consistent with other CSL processors. Indeed, several citeproc tests demonstrated that the expected way to add whitespaces between initials is through initializer-with=". " instead of initializer-with=".". So, I removed Hayagriva's automatic whitespace behavior, except when we're replacing hyphens (e.g. for initializer-with=". ", Aa-Bb should become A.-B. and not A. -B.).

It is, however, unfortunate that this seems to be somewhat inconsistent with a specific example given by the relevant section of the CSL 1.0.2 spec:

`initialize-with`
    When set, given names are converted to initials. The attribute value is added after each initial (“.” results in “J. J. Doe”).

...but most official styles I've seen appear to assume that whitespaces are preserved, using ". " instead of "." in that case. So this seems to be the way to go.

I've also added some tests. Two more citeproc tests are now passing as well.

I'll be keeping this as a draft as I still need to test the case with initialize="false", initialize-with=".", but in principle the code seems to preserve whitespace here as well, however whitespaces from the name itself are also kept, which is why initialize-with="." is used instead of initialize-with=". " by official styles in this case.

@reknih
Copy link
Member

reknih commented Dec 9, 2024

If the other implementations and styles assume/exhibit/rely on this behaviour, we should also add it, so I'm good with it from that perspective.

@PgBiel
Copy link
Contributor Author

PgBiel commented Dec 9, 2024

Taking a look here, it seems that automatic whitespaces should also be removed when initialize="false" but initialize-with is set, according to citeproc tests, whereas we currently always add whitespaces. But I'll leave that to a separate PR.

@PgBiel PgBiel marked this pull request as ready for review December 9, 2024 21:23
@PgBiel PgBiel merged commit 38a56c8 into main Dec 9, 2024
4 checks passed
@PgBiel PgBiel deleted the initial-whitespace branch December 9, 2024 21:50
danilasar pushed a commit to danilasar/hayagriva that referenced this pull request Dec 31, 2024
* keep whitespace at the end of initial delimiters

...when not adding hyphens

* add tests for person name retrieval order

* add missing test with empty delimiter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bibliography incorrectly adds a space between author initials
2 participants