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

feature request: Markdown [@key] cite command #10133

Closed
AdamWysokinski opened this issue Jul 31, 2023 · 11 comments · Fixed by #10303
Closed

feature request: Markdown [@key] cite command #10133

AdamWysokinski opened this issue Jul 31, 2023 · 11 comments · Fixed by #10303
Assignees
Labels
good first issue An issue intended for project-newcomers. Varies in difficulty. type: enhancement

Comments

@AdamWysokinski
Copy link
Contributor

I use Pandoc for processing Markdown manuscripts to ODT format. Markdown cite command is [@key] instead of LaTeX \cite{key}. In case of multiple citations this is [@key1; @key2]. Currently the preference for cite command does not include the { and } characters, making it impossible to change it to another cite command that does not use curly brackets. Also, the separating character (,) cannot be modified.

It would be great if this was more configurable:

  1. cite command
  2. surrounding characters
  3. separating character
@github-project-automation github-project-automation bot moved this to Normal priority in Features & Enhancements Jul 31, 2023
@Siedlerchr Siedlerchr added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Aug 2, 2023
@Brandon-z-lu
Copy link

Brandon-z-lu commented Aug 7, 2023

Hi Adam,

Do you mind providing a quick Minimum Working Example please?

To be honest, I'm on this page now.
image
And I can't seem to find any settings button cmd + , whatsoever?

Thanks a lot!

@AdamWysokinski
Copy link
Contributor Author

Hi Branon,
Here's one:

  1. Go to menu: File -> Preferences
  2. In the JabRef preferences window select "External programs" tab
  3. There is "Cite command" preference with default value \cite

When you push citation(s) to an external application (e.g. Emacs/Vim/Sublime Text) it is being send as:
\cite{wysokinski_2023} if a single entry is selected or \cite{wysokinski_2023,wysokinski_2022} if two or more entries are selected.

The {, }, , characters that are used in the exported citation are hard-coded in the program and cannot be modified in Preferences.
For Markdown/Pandoc compatible citation the entries should be: [@wysokinski_2023] and [@wysokinski_2023; @wysokinski_2022], respectively. The \cite is not used at all, curly brackets are replaced with [ and ] and the separating characters are ; . All these parameters should be available in "Cite command" preferences to be modified by a user.

Hope this helps.
Adam

@Brandon-z-lu
Copy link

Brandon-z-lu commented Aug 7, 2023

Hi Adam,

I can understand your problem now. Honestly, this is one of my first few PRs, and I'm a little bit confused about how to set the cite command. I know

protected String getCiteCommand() {
        return preferencesService.getExternalApplicationsPreferences().getCiteCommand();
}

And

    //*************************************************************************************************************
    // ExternalApplicationsPreferences
    //*************************************************************************************************************

    @Override
    public PushToApplicationPreferences getPushToApplicationPreferences() {
        if (Objects.nonNull(pushToApplicationPreferences)) {
            return pushToApplicationPreferences;
        }

        Map<String, String> applicationCommands = new HashMap<>();
        applicationCommands.put(PushToApplications.EMACS, get(PUSH_EMACS_PATH));
        applicationCommands.put(PushToApplications.LYX, get(PUSH_LYXPIPE));
        applicationCommands.put(PushToApplications.TEXMAKER, get(PUSH_TEXMAKER_PATH));
        applicationCommands.put(PushToApplications.TEXSTUDIO, get(PUSH_TEXSTUDIO_PATH));
        applicationCommands.put(PushToApplications.VIM, get(PUSH_VIM));
        applicationCommands.put(PushToApplications.WIN_EDT, get(PUSH_WINEDT_PATH));
        applicationCommands.put(PushToApplications.SUBLIME_TEXT, get(PUSH_SUBLIME_TEXT_PATH));

        pushToApplicationPreferences = new PushToApplicationPreferences(
                get(PUSH_TO_APPLICATION),
                applicationCommands,
                get(PUSH_EMACS_ADDITIONAL_PARAMETERS),
                get(PUSH_VIM_SERVER)
        );

        EasyBind.listen(pushToApplicationPreferences.activeApplicationNameProperty(), (obs, oldValue, newValue) -> put(PUSH_TO_APPLICATION, newValue));
        pushToApplicationPreferences.getCommandPaths().addListener((obs, oldValue, newValue) -> storePushToApplicationPath(newValue));
        EasyBind.listen(pushToApplicationPreferences.emacsArgumentsProperty(), (obs, oldValue, newValue) -> put(PUSH_EMACS_ADDITIONAL_PARAMETERS, newValue));
        EasyBind.listen(pushToApplicationPreferences.vimServerProperty(), (obs, oldValue, newValue) -> put(PUSH_VIM_SERVER, newValue));

        return pushToApplicationPreferences;
    }

    private void storePushToApplicationPath(Map<String, String> commandPair) {
        commandPair.forEach((key, value) -> {
            switch (key) {
                case PushToApplications.EMACS ->
                        put(PUSH_EMACS_PATH, value);
                case PushToApplications.LYX ->
                        put(PUSH_LYXPIPE, value);
                case PushToApplications.TEXMAKER ->
                        put(PUSH_TEXMAKER_PATH, value);
                case PushToApplications.TEXSTUDIO ->
                        put(PUSH_TEXSTUDIO_PATH, value);
                case PushToApplications.VIM ->
                        put(PUSH_VIM, value);
                case PushToApplications.WIN_EDT ->
                        put(PUSH_WINEDT_PATH, value);
                case PushToApplications.SUBLIME_TEXT ->
                        put(PUSH_SUBLIME_TEXT_PATH, value);
            }
        });
    }

    @Override
    public ExternalApplicationsPreferences getExternalApplicationsPreferences() {
        if (Objects.nonNull(externalApplicationsPreferences)) {
            return externalApplicationsPreferences;
        }

        externalApplicationsPreferences = new ExternalApplicationsPreferences(
                get(EMAIL_SUBJECT),
                getBoolean(OPEN_FOLDERS_OF_ATTACHED_FILES),
                get(CITE_COMMAND),
                !getBoolean(USE_DEFAULT_CONSOLE_APPLICATION), // mind the !
                get(CONSOLE_COMMAND),
                !getBoolean(USE_DEFAULT_FILE_BROWSER_APPLICATION), // mind the !
                get(FILE_BROWSER_COMMAND),
                get(KINDLE_EMAIL));

        EasyBind.listen(externalApplicationsPreferences.eMailSubjectProperty(),
                (obs, oldValue, newValue) -> put(EMAIL_SUBJECT, newValue));
        EasyBind.listen(externalApplicationsPreferences.autoOpenEmailAttachmentsFolderProperty(),
                (obs, oldValue, newValue) -> putBoolean(OPEN_FOLDERS_OF_ATTACHED_FILES, newValue));
        EasyBind.listen(externalApplicationsPreferences.citeCommandProperty(),
                (obs, oldValue, newValue) -> put(CITE_COMMAND, newValue));
        EasyBind.listen(externalApplicationsPreferences.useCustomTerminalProperty(),
                (obs, oldValue, newValue) -> putBoolean(USE_DEFAULT_CONSOLE_APPLICATION, !newValue)); // mind the !
        EasyBind.listen(externalApplicationsPreferences.customTerminalCommandProperty(),
                (obs, oldValue, newValue) -> put(CONSOLE_COMMAND, newValue));
        EasyBind.listen(externalApplicationsPreferences.useCustomFileBrowserProperty(),
                (obs, oldValue, newValue) -> putBoolean(USE_DEFAULT_FILE_BROWSER_APPLICATION, !newValue)); // mind the !
        EasyBind.listen(externalApplicationsPreferences.customFileBrowserCommandProperty(),
                (obs, oldValue, newValue) -> put(FILE_BROWSER_COMMAND, newValue));
        EasyBind.listen(externalApplicationsPreferences.kindleEmailProperty(),
                (obs, oldValue, newValue) -> put(KINDLE_EMAIL, newValue));

        return externalApplicationsPreferences;
    }

==Just don't know how to set the cite command. I'm gonna ask someone for help==

I've looked at
src/main/java/org/jabref/preferences/JabRefPreferences.java;
src/main/java/org/jabref/gui/push/AbstractPushToApplication.java; and
src/main/java/org/jabref/gui/preferences/external/ExternalTab.java.

Thanks for the swift response, Adam.

Cheers,
Brandon

@Brandon-z-lu
Copy link

Could I be assigned to this issue, maybe?

@HoussemNasri
Copy link
Member

Sure

@Siedlerchr
Copy link
Member

@Brandon-Lu737 Okay:

  1. Add the new fields surroundingCharacters and separator in the UI and the viewModel
  2. Add those fields to the preferences as well (as default value in the prefs keep the curly braces
  3. Add methods for getting the surroundingCharacters and the separator in AbstractPushToApplication and the subclasses
  4. Build the new commands in getCommandLine in each class to use the values with getSurroundingCharacters and separator
  5. Test :)

A bit about the overall architecture:

All UI in JabRef follows MVVM (Model View ViewModel)
The settings tab UI:
ExternalTab.java + fxml - They define the UI, e.g what to show
ExternalViewModel - Contains logic that is bound to the UI (Bindings/Observables: Update the value
when it changes)
currently relevant: citeCommandProperty Holds the cite command input, e.g. the \cite
=> Here you need to add the extra input fields: surroundingCharacters and separator in the fxml and in the UI code and add the fields into the viewModel.

These need to be stored in the settings as well. Also happens via observables/Bindings so that changes are directly stored in the preferences.

We have an Abstract class containing the central method for building the string that gets pushed to the external application
Each Editor (Vim, Emacs, TexStudio etc) inherits from it and overrides it with their own implementation (getCommandLIne) .

Feel free to ask if you have more questions!

@ThiloteE ThiloteE moved this from Free to take to Reserved in Candidates for University Projects Aug 9, 2023
@ThiloteE
Copy link
Member

ThiloteE commented Aug 9, 2023

@HoussemNasri, when you assign somebody, please also set the corresponding status for the project pages. Unless there is a pull-request, the status is "reserved".

@Siedlerchr
Copy link
Member

@Brandon-Lu737 What is the status here? Are you still working on this?

@AdamWysokinski
Copy link
Contributor Author

Could someone tell me why it is not present in the most recent 5.11 release?

@Siedlerchr
Copy link
Member

@AdamWysokinski You can just modify the pattern to \cite[@key1;@key2} and it will work

@AdamWysokinski
Copy link
Contributor Author

It does, thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue An issue intended for project-newcomers. Varies in difficulty. type: enhancement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants