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: Support customizing citation syntax #1

Closed
1 task done
wenlzhang opened this issue Mar 15, 2022 · 18 comments
Closed
1 task done

Feature Request: Support customizing citation syntax #1

wenlzhang opened this issue Mar 15, 2022 · 18 comments
Labels
enhancement New feature or request

Comments

@wenlzhang
Copy link

Feature Requested

Currently, the default citation syntax is [@citekey], for use with pandoc. In my workflow, there are also two other use cases.

  • In Obsidian notes, sometimes I would like to insert the citation key as tags, e.g. #citekey. This way, I can easily see where a paper is referenced from the tag pane and graph view.
  • When writing in LaTeX, I may use the citation key in the format \cite{citekey}.

Therefore, it would be great if one can customize the citation syntax to use. For instance, one can set a default format and a few other formats. When inserting the citation key, the default format would be used, unless specified otherwise.

Relevant Screenshot

No response

Checklist

  • The feature would be useful to more users than just me.
@wenlzhang wenlzhang added the enhancement New feature or request label Mar 15, 2022
@noirchen
Copy link

I agree. This can be implemented as an option choosing between @, # or bare key.

@owlasea
Copy link

owlasea commented May 5, 2022

Seconded. This would be super useful! Thanks!

@stravers56
Copy link

I would like this feature for latex as well.

@chrisgrieser
Copy link
Owner

Can anyone refer me to some documentation for Latex citations? Specifically, I need information on how citations look like for various cases?

  • single citation with page numbers
  • multiple citations without page numbers
  • multiple citations with page numbers

@owlasea
Copy link

owlasea commented May 19, 2022

These are the ones that work for bibtex. Not sure if it works for other settings/packages (e.g., Natbib, apacite).

  • Single citation with page numbers: \cite[pageNumber]{citekey}
  • Multiple citations without page numbers: \cite{citekey1, citekey2, citekey3}
  • Multiple citations with page numbers: \citetext{\citealp[pageNumber1]{citekey1}; \citealp[pageNumber2]{citekey2}.....}

I also found these on Overleaf for your reference:
https://www.overleaf.com/learn/latex/Biblatex_citation_styles

https://www.overleaf.com/learn/latex/Natbib_citation_styles

@chrisgrieser
Copy link
Owner

chrisgrieser commented May 19, 2022

so instead of hardcoding a citation syntax format, I have simply turned all of them into variables, so it should cover everything form tags in Obsidian to other citation formats. However I am not totally certain, that I "get" this weird Latex citation syntax – I am writing in markdown since I wanted to avoid all the hassle of Latex, after all 😅

Would this suffice? (the screenshot contains the values for Pandoc citations) You can try it out in release 9.0.0.

Pasted image 2022-05-19 19 56 20

@owlasea
Copy link

owlasea commented May 20, 2022

Thanks for the great work Chris! Everything works except the _format_citekey_prefix though. When I set it to empty instead of @, the "@" still appears anyway. If I change it to other values, @ remains and the newly set value is not reflected. Wonder if there is anything I am doing wrong? Should I be tweaking something else? Thank you again!

@noirchen
Copy link

Thanks for the new version! Everything works like a charm. I did not meet the persisting @ issue.

@owlasea
Copy link

owlasea commented May 20, 2022

Ah I reloaded the buffer and now everything works!

@chrisgrieser
Copy link
Owner

Could you show me what values you have all set for _format... ?

That way, I can add some presets, which not only make it easier to switch, but also automatically reload the buffer

@chrisgrieser
Copy link
Owner

also, I noticed that with certain citation styles, you put the page number before the citekey. So I have added the following two options to version 9.1.0 to account for that possibility.

Could you give it a try and see whether you can cover all cases (multiple citations, with/without page numbers) by having these variables? If those are enough, and you can give me the values for the _format... variables, then I can set presets so the user doesn't have to fiddle too much with the formatting.

image

@owlasea
Copy link

owlasea commented May 20, 2022

Hi @chrisgrieser , here is the values I set for _format...:
Screen Shot 2022-05-20 at 15 09 13

I also noticed that the reason that reloading the buffer solves the issue with persistent @ is that I have set the prefix to empty in the first place, but this creates another problem that, if I want to insert something like [[@citekey]] and the prefix is set to empty, it will give me [[citekey]] without the @. In other words, it seems if I set the prefix and reload the buffer, it will always come up with prefix+citekey as the {query} variable. Is there a way for me to set the {query} as only the citekeys without the prefixes? Thanks!

@chrisgrieser
Copy link
Owner

if I want to insert something like [[@citekey]] and the prefix is set to empty, it will give me [[citekey]] without the @

@owlasea I am not entirely sure that I understand what you mean. Like, how is set prefix → get prefix not the intended behavior? 🤨

If this is about the need for reloading, I just pushed an update (9.1.2) which removes the prefix from the query, so that you can change the formatting without reloading the buffer.

@chrisgrieser
Copy link
Owner

with 9.2.0, one can now more conveniently change the citation format via scp. You can add citations formats, e.g. for all the Latex variants, via PR to this file.

Pasted image 2022-05-20 12 02 32

Pasted image 2022-05-20 12 02 54

@owlasea
Copy link

owlasea commented May 20, 2022

This is awesome! Thanks Chris!

By the way is the multiple citation working properly? I am getting something like this:
Screen Shot 2022-05-20 at 21 17 33

The only citation that gets the prefix is the one that I select last? Was not a problem in some earlier versions.

@chrisgrieser
Copy link
Owner

thanks, is fixed

@chrisgrieser
Copy link
Owner

well, I guess this issue can be regarded as closed then?

@chrisgrieser
Copy link
Owner

just for reference: I also added a bare citekey option.

With the irregularity of Latex citations, I'd probably need some advice on how to properly format that. In case someone is interested in that, please open a new issue for the Latex citation format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants