Skip to content

Conversation

Tushar2604
Copy link

@Tushar2604 Tushar2604 commented Aug 16, 2025

Closes #13578

This PR extends the Cite-As-You-Write (CAYW) feature in JabRef to fully comply with the formats supported by Better BibTeX.

New supported formats:

natbib
latex
citep
mmd
pandoc
typst

Steps to test

Start JabRef with the server enabled: "./gradlew clean run"
Run the tests : "./gradlew :jabsrv:test"
verify that the following formats are now supported in addition to the existing ones:

natbib → should return \citep{key} style output

latex → should return \cite{key} style output

citep → explicitly handled citation with \citep{key}

mmd (MultiMarkdown) → should return [#key] style citations

pandoc → should return [key] style citations

typst → should return [key] style citations

Confirm all tests pass and JabRef doesn’t throw any errors when these formats are requested

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [/] Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • [/] Screenshots added in PR description (if change is visible to the user)
  • [/] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [/] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

AI?

@subhramit subhramit requested a review from palukku August 16, 2025 14:29
@subhramit
Copy link
Member

PR description? steps to test?

@subhramit
Copy link
Member

Why is this not a draft pr if the build is failing?

@Tushar2604 Tushar2604 closed this Aug 16, 2025
@Tushar2604 Tushar2604 reopened this Aug 16, 2025
@Tushar2604
Copy link
Author

Tushar2604 commented Aug 16, 2025

Sorry it was mistake. I will be redoing this .Sorry for the inconvenience.

public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
String command = queryParams.getCommand();
if (command == null || command.isBlank()) {
command = "citep"; // default for citep
Copy link

Choose a reason for hiding this comment

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

The comment 'default for citep' is redundant and does not provide any additional information beyond what is clearly visible in the code itself.

@jabref-machine
Copy link
Collaborator

Your code currently does not meet JabRef's code guidelines. We use Checkstyle to identify issues. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Source Code Tests / Checkstyle (pull_request)" and click on it.

In case of issues with the import order, double check that you activated Auto Import. You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues, commit, and push.

@koppor
Copy link
Member

koppor commented Aug 16, 2025

Sorry it was mistake. I will be redoing this .Sorry for the inconvenience.

No need for re-do. Just edit PR description and push new commits. You can also change to draft at GitHub's UI.

@jabref-machine
Copy link
Collaborator

Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of [x] (done), [ ] (not done yet) or [/] (not applicable).

@jabref-machine
Copy link
Collaborator

JUnit tests of jabsrv are failing. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Source Code Tests / Unit tests (pull_request)" and click on it.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

.toList();
return "\\%s{%s}".formatted(command,
bibEntries.stream()
.map(entry -> entry.getCitationKey().orElse(""))
Copy link

Choose a reason for hiding this comment

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

Empty string is used as a fallback for missing citation keys, which could lead to invalid LaTeX syntax. Should handle this case more explicitly or throw an exception.

Comment on lines +28 to +30
List<BibEntry> bibEntries = caywEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();
Copy link

Choose a reason for hiding this comment

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

This intermediate list creation is unnecessary since the stream is used immediately after. The operations can be chained directly for better performance.

Comment on lines +31 to +32
// Handle "parencite" command with square brackets
if ("parencite".equalsIgnoreCase(command)) {
Copy link

Choose a reason for hiding this comment

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

The comment is trivial and only restates what is obvious from the code itself. Comments should add new information or reasoning that cannot be derived directly from the code.

.map(bibEntry -> "[@" + bibEntry.getCitationKey().orElse("") + "]")
.collect(Collectors.joining(""));
} else {
// Default: bare @key format with semicolon separator
Copy link

Choose a reason for hiding this comment

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

The comment merely describes what the code does without providing additional context or reasoning. Such trivial comments should be removed as they don't add value beyond what's visible in the code.

Comment on lines +28 to +30
List<BibEntry> bibEntries = caywEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();
Copy link

Choose a reason for hiding this comment

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

Intermediate list creation is unnecessary since the stream is used immediately after. The stream operations could be chained directly for better performance.

void testFormat() {
CitepFormatter f = new CitepFormatter();

CAYWQueryParams qp = mock(CAYWQueryParams.class); // command is ignored
Copy link

Choose a reason for hiding this comment

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

The comment provides no additional information beyond what is obvious from the code itself. Comments should add new information or reasoning, not restate what's visible.

void testFormat() {
CitepFormatter f = new CitepFormatter();

CAYWQueryParams qp = mock(CAYWQueryParams.class); // command is ignored
Copy link

Choose a reason for hiding this comment

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

Variable name 'qp' is too short and doesn't convey meaning. Variable names should be descriptive and include intention in their naming.

@Test
@DisplayName("getFormatNames() returns the two expected aliases in order")
void testGetFormatNames() {
CitepFormatter f = new CitepFormatter();
Copy link

Choose a reason for hiding this comment

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

Variable name 'f' is too short and doesn't convey meaning. Variable names should be descriptive and include intention in their naming.

@Test
void testGetFormatNamesNotEmpty() {
LatexFormatter f = new LatexFormatter();
assertFalse(f.getFormatNames().isEmpty(), "Format-name list must not be empty");
Copy link

Choose a reason for hiding this comment

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

Using assertFalse to check collection emptiness is less specific than directly asserting the contents. Use assertions that provide better failure messages and more precise validation.


@Test
void testHasAtLeastTwoAliases() {
assertTrue(new NatbibFormatter().getFormatNames().size() >= 2,
Copy link

Choose a reason for hiding this comment

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

Using assertTrue for size comparison is less descriptive than assertThat or assertEquals. The test should assert the actual contents of the collection rather than a boolean condition.


@Test
void testGetFormatNames() {
PandocFormatter f = new PandocFormatter();
Copy link

Choose a reason for hiding this comment

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

Variable name 'f' is too short and not descriptive. It should be named to reflect its purpose, such as 'formatter' or 'pandocFormatter'.

void testDefaultFormat() {
PandocFormatter f = new PandocFormatter();

CAYWQueryParams qp = mock(CAYWQueryParams.class);
Copy link

Choose a reason for hiding this comment

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

Variable name 'qp' is too short and not descriptive. It should be named to reflect its purpose, such as 'queryParams' or 'formatQueryParams'.

Comment on lines +1 to +2


Copy link
Member

Choose a reason for hiding this comment

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

Please set up your workspace with autoformatting and checkstyle according to our guide
https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html

Comment on lines -29 to +33

List<BibEntry> bibEntries = caywEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

.map(CAYWEntry::bibEntry)
.toList();
Copy link
Member

Choose a reason for hiding this comment

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

checkstyle
avoid removing newlines introduced to separate different thoughts

@Test
@DisplayName("parencite command ⇒ '[@k1][@k2]…'")
void testParenciteFormat() {
PandocFormatter f = new PandocFormatter();
Copy link
Member

Choose a reason for hiding this comment

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

do not use abbreviations

@calixtus calixtus added the component: cite-as-you-write cayw (similar to better-bibtex for Zotero) label Aug 20, 2025
Comment on lines +20 to +25
BibEntry bib = mock(BibEntry.class);
when(bib.getCitationKey()).thenReturn(Optional.of(key));

CAYWEntry cayw = mock(CAYWEntry.class);
when(cayw.bibEntry()).thenReturn(bib);
return cayw;
Copy link
Member

@subhramit subhramit Aug 20, 2025

Choose a reason for hiding this comment

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

From what can be gathered from your code, the impression is that you do not know what these formats are, what JabRef is or even what a Bibtex entry is.
The code is heavily AI-generated.

Furthermore, due to insincerity in marking the mandatory checks:
image

(None of the commits so far have a passing build check - so I don't know how you manually tested)
I am inclined to close the PR.
Please gather some context about the project you are contributing to, read the devdocs on setting up a local workspace, look at some existing tests and maybe then take up an issue.

@Siedlerchr
Copy link
Member

You don't seem to have any idea and just rely on AI. Thus closing

@Siedlerchr Siedlerchr closed this Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: cite-as-you-write cayw (similar to better-bibtex for Zotero)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add additional CAYW Formatters
6 participants