Skip to content

Commit

Permalink
Allow - in citaton keys
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Nov 3, 2024
1 parent cd332b4 commit 23739a0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- When importing a file using "Find Unlinked Files", when one or more file directories are available, the file path will be relativized where possible [koppor#549](https://github.com/koppor/jabref/issues/549)
- We added minimum window sizing for windows dedicated to creating new entries [#11944](https://github.com/JabRef/jabref/issues/11944)
- We changed the name of the library-based file directory from 'General File Directory' to 'Library-specific File Directory' per issue. [#571](https://github.com/koppor/jabref/issues/571)
- We allow a dash (`-`) being part in a citation key.
- The CitationKey column is now a default shown column for the entry table. [#10510](https://github.com/JabRef/jabref/issues/10510)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class CitationKeyGenerator extends BracketedPattern {
*/
public static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz";

/**
* List of unwanted characters. These will be removed at the end.
* Note that <code>+</code> is a wanted character to indicate "et al." in authorsAlpha.
* Example: "ABC+". See {@link org.jabref.logic.citationkeypattern.BracketedPatternTest#authorsAlpha()} for examples.
*/
public static final String DEFAULT_UNWANTED_CHARACTERS = "-`ʹ:!;?^";
/// List of unwanted characters. These will be removed at the end.
/// Note that `+` is a wanted character to indicate "et al." in authorsAlpha.
/// Example: `ABC+`. See {@link org.jabref.logic.citationkeypattern.BracketedPatternTest#authorsAlpha()} for examples.
///
/// Source: <https://tex.stackexchange.com/questions/408530/what-characters-are-allowed-to-use-as-delimiters-for-bibtex-keys
public static final String DEFAULT_UNWANTED_CHARACTERS = "`ʹ:!;?^";

private static final Logger LOGGER = LoggerFactory.getLogger(CitationKeyGenerator.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class CitationKeyGeneratorTest {
private static final String AUTHNOFMTH = "[auth%d_%d]";
private static final String AUTHFOREINI = "[authForeIni]";
private static final String AUTHFIRSTFULL = "[authFirstFull]";
private static final String AUTHORS = "[authors]";
private static final String AUTHORSALPHA = "[authorsAlpha]";
private static final String AUTHORLAST = "[authorLast]";
private static final String AUTHORLASTFOREINI = "[authorLastForeIni]";
Expand Down Expand Up @@ -493,14 +492,26 @@ void firstAuthorVonAndLastNoVonInName() {
assertEquals("Newton", generateKey(AUTHOR_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, AUTHFIRSTFULL));
}

/**
* Tests [authors]
*/
@ParameterizedTest
@MethodSource
void authors(String expectedKey, BibEntry entry, String pattern) {
assertEquals(expectedKey, generateKey(entry, pattern));
}

static Stream<Arguments> authors() {
return Stream.of(
Arguments.of("Newton", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, "[authors]"),
Arguments.of("NewtonMaxwell", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, "[authors]"),
Arguments.of("NewtonMaxwellEinstein", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, "[authors]"),
Arguments.of("Newton-Maxwell-Einstein", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, "[authors:regex(\"(.)([A-Z])\",\"$1-$2\")]")
);
}

@Test
void allAuthors() {
assertEquals("Newton", generateKey(AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, AUTHORS));
assertEquals("NewtonMaxwell", generateKey(AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, AUTHORS));
assertEquals("NewtonMaxwellEinstein", generateKey(AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, AUTHORS));
assertEquals("Newton", generateKey(AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, "[authors]"));
assertEquals("NewtonMaxwell", generateKey(AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, "[authors]"));
assertEquals("NewtonMaxwellEinstein", generateKey(AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, "[authors]"));
}

static Stream<Arguments> authorsAlpha() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ void extractFirstWord() {
formatter = new RegexFormatter("(\"(\\w+).*\", \"$1\")");
assertEquals("First", formatter.format("First Second Third"));
}

@Test
void addDash() {
formatter = new RegexFormatter("(\"(.)([A-Z])\", \"$1-$2\")");
assertEquals("First-Second-Third", formatter.format("FirstSecondThird"));
}
}

0 comments on commit 23739a0

Please sign in to comment.