helm-bibtex icon indicating copy to clipboard operation
helm-bibtex copied to clipboard

Problem with postnotes on \cite

Open yandrot opened this issue 6 years ago • 7 comments

This is probably quite a simple problem, but I am not able to solve it and it is quite annoying. Whenever I try to include a citation in Latex, bibtex-completion ask for both, Prenote and Postnote. However, in the latex class I usually work, the cite command does not accept postnotes. Is there any way to avoid that bibtex-completion ask for the postnote? (I am still interested in the prenote).

It should exist a simple solution (and I am quite aware that I can make the trick in the Latex side), but I am not able to find it.

PS: First question on GitHub, so sorry if I state the issue mistakenly.

yandrot avatar Apr 13 '18 20:04 yandrot

Just to better understand the nature of the problem: Do you get an error message when you compile your LaTeX because there is an unlicensed postnote? Or is it just annoying for you to be asked for a postnote when you never need it? (Which would be a perfectly valid reason for posting an issue.)

tmalsburg avatar Apr 14 '18 08:04 tmalsburg

It is both actually. It is a little annoying and I have errors compiling. As I mention, the second problem can be solved by just "playing" with latex, but I would like to be able to remove the postnote option.

yandrot avatar Apr 14 '18 08:04 yandrot

You can advice bibtex-completion-format-citation-cite to remove empty postnote brackets. Let me know if that helps.

(advice-add 'bibtex-completion-format-citation-cite :filter-return
	    #'(lambda (citation)
		(replace-regexp-in-string (regexp-quote "[]{") "{" citation)))

jagrg avatar Apr 17 '18 02:04 jagrg

Thank you, Jonathan. If I understand correctly, this solves the immediate problem of non-compiling LaTeX. Beyond that we probably need to extend possible values for bibtex-completion-cite-prompt-for-optional-arguments. Currently, it's just nil or something non-nil, but perhaps we could also allow this to be a list of things that should be requested from the user with possible values cite-command, prenote, postnote.

One question, @yandrot, what is your cite command? Is it \cite or something else? If it's different from \cite, there might be an easier fix.

tmalsburg avatar Apr 18 '18 07:04 tmalsburg

@jagrg , it works perfectly! I have tried to take a look to the actual code in bibtex-completion.el, but I was unable to change such a behaviour (I must say that I have no idea of Lisp, even if it seems quite a regular code).

Yes, @tmalsburg , it is \cite.

yandrot avatar Apr 18 '18 11:04 yandrot

For possible values, I'd say nil (no prompt), prenote (prompt once) or t (prompt twice), unless we have specific cases for using postnote only.

jagrg avatar Apr 18 '18 14:04 jagrg

I'm not aware of cases where only postnotes are needed but we could add this later when necessary. Not sure when I will able to implement this, but for now I'm glad that the immediate problem is solved.

tmalsburg avatar Apr 21 '18 08:04 tmalsburg