jkitchin / org-ref-cite

An org-cite processor that is like org-ref.
42 stars 6 forks source link

`org-cite-insert` does not respect `bibtex-completion-display-formats` #19

Closed m4xxed closed 3 years ago

m4xxed commented 3 years ago

Hi, I cannot seem to pinpoint the issue, but, with my current configuration, calling org-cite-insert just looks weird...

screenshot-2021-08-13-13:32:11

... while it looks as expected when I call ivy-bibtex:

screenshot-2021-08-13-13:33:44

My configuration is:

(use-package! ivy-bibtex
  :after org-roam
  :init
  (setq bibtex-completion-notes-path org-roam-directory)
  (setq bibtex-completion-bibliography (concat org-roam-directory "master.bib"))
  (setq bibtex-completion-pdf-field "file")
  (setq bibtex-completion-additional-search-fields '(keywords))
  (setq bibtex-completion-display-formats
    '((article       . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} ${journal:40}")
      (inbook        . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} Chapter ${chapter:32}")
      (incollection  . "${=has-pdf=:1}${=has-note=:https://github.com/blaisewang/img2latex-mathpix1} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
      (inproceedings . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
      (t             . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*}")))
  :config
  (ivy-mode +1))

(use-package! org-ref-cite
  :after org-roam
  :config
  (add-to-list 'org-cite-global-bibliography bibtex-completion-bibliography)
  (setq org-cite-insert-processor 'org-ref-cite)
  (setq org-cite-follow-processor 'org-ref-cite)
  (setq org-cite-activate-processor 'org-ref-cite)
  (setq org-cite-export-processors '((latex org-ref-cite))))

Additionally, calling org-cite-insert with a prefix does not work at all, it gives me an empty menu to choose from:

screenshot-2021-08-13-13:36:26

I am very curious to find out where I screwed up this configuration and why it does not work. Maybe more experienced users can quickly spot this issue.

Additional Information:

jkitchin commented 3 years ago

The reason for that is due to completing read. For now, a way to get the same behavior as ivy-bibtex I think would be to add this code to your setup.

(ivy-set-display-transformer
 ' org-ref-cite-insert-processor
 'ivy-bibtex-display-transformer)
m4xxed commented 3 years ago

Sorry for the delayed reply. Your code snipped did indeed solve the second issue with the prefixed org-cite-insert, but the bibtex-completion-display-formats variable remains ineffective, it still looks like in the first screenshot of my initial post.

Thank you for clearing the second issue up though, now I am just curious about how to solve the first one.

jkitchin commented 3 years ago

If I had to guess, you are seeing a cached version of the first settings you used. There are a few ways you might update it.

  1. C-u M-x ivy-bibtex should clear the cache and regenerate it.
  2. type M-: and then type (bibtex-completion-clear-cache) and press return.
  3. Paste this link in an org buffer and click on it [[elisp:(bibtex-completion-clear-cache)]]

Any of these should update the candidate strings using those formats in the next time you insert a citation.

m4xxed commented 3 years ago

Thank you for these suggestions. I have tried them, however they did not work and org-cite-insert is still formatted as I have shown in my first post.

Here is my complete org-roam config including ivy-bibtex etc. from my config.el:

(use-package! org-roam-bibtex
  :after org-roam)

(after! org-roam (org-roam-bibtex-mode t))

(after! org-roam
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?"
           :if-new (file+head "${slug}.org" "#+TITLE: ${title}\n#+FILETAGS:\n\n")
           :unnarrowed t))))

(after! org-roam (setq orb-preformat-keywords '("citekey" "author" "date" "keywords"))
  (add-to-list 'org-roam-capture-templates
               '("r" "bibliography reference" plain "%?"
                 :if-new
                 (file+head "${citekey}.org" "#+TITLE: ${title}\n#+FILETAGS: ${keywords}\n\n* TODO Notes\n:PROPERTIES:\n:Custom_ID: ${citekey}\n:AUTHOR: ${author}\n:NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\")\n:END:\n\n")
                 :unnarrowed t)))

(use-package! ivy-bibtex
  :after org-roam
  :init
  (setq bibtex-completion-notes-path org-roam-directory)
  (setq bibtex-completion-bibliography (concat org-roam-directory "master.bib"))
  (setq bibtex-completion-pdf-field "file")
  (setq bibtex-completion-additional-search-fields '(keywords))
  (setq bibtex-completion-display-formats
        '((article       . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} ${journal:40}")
          (inbook        . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} Chapter ${chapter:32}")
          (incollection  . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
          (inproceedings . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
          (t             . "${=has-pdf=:1}${=has-note=:1} ${year:4} ${author:36} ${title:*}")))
  :config
  (ivy-mode +1)
  (ivy-set-display-transformer
   ' org-ref-cite-insert-processor
   'ivy-bibtex-display-transformer))

(use-package! org-ref-cite
  :after org-roam
  :config
  (add-to-list 'org-cite-global-bibliography bibtex-completion-bibliography)
  (setq org-cite-insert-processor 'org-ref-cite)
  (setq org-cite-follow-processor 'org-ref-cite)
  (setq org-cite-activate-processor 'org-ref-cite)
  (setq org-cite-export-processors '((latex org-ref-cite))))

(after! flyspell (setq  flyspell-duplicate-distance 0
                        flyspell-mark-duplications-flag nil
                        warning-minimum-level :error))

(after! flyspell
  (advice-remove 'org--flyspell-object-check-p 'org-ref-cite--flyspell-object-check-p))

And here is my packages.el entry:

(package! org-ref-cite-core :recipe (:host github :repo "jkitchin/org-ref-cite"))
(package! org-ref-cite :recipe (:host github :repo "jkitchin/org-ref-cite"))

I am very grateful that you even took time to suggest solutions the first two times! Thanks!

blester125 commented 2 years ago

I had the same issue, I fixed it by adding

(ivy-set-display-transformer
   'org-cite-insert
   'ivy-bibtex-display-transformer)

and also forking org-ref-cite-insert-processor to include :caller 'org-cite-insert to the (null arg) branch, just like the other branch