emacs-citar / citar

Emacs package to quickly find and act on bibliographic references, and edit org, markdown, and latex academic documents.
GNU General Public License v3.0
502 stars 54 forks source link

Show "open pdf" and other bibtex-specific things in embark actions #389

Closed notuntoward closed 2 years ago

notuntoward commented 2 years ago

When I type C-o on a cite link, I'm brought to an embark act menu, but it's not the one I see in the documentation here. Instead, it's the one in the screenshot below. In the one I see, there's a lot of stuff I'm not sure to do with, for example, "delete-region".

Could the actions instead to be only things specific to the bibtex entry pointed to by the link? I'd especially like to see the an "open-pdf," option, which is missing.

Also, what do I type and where to see the embark actions menu shown in the documentation?

image

bdarcus commented 2 years ago

See the discussion on #374. We'll figure something out.

Try citar-open-library-files (f); it's a more general open-pdf.

I need to update the screenshots.

Also, what do I type and where to see the embark actions menu shown in the documentation?

I'm not sure I understand. Those use the which-key embark indicator, which I don't necessarily recommend. But it's handled by the embark configuration.

notuntoward commented 2 years ago

Thanks, but when I tried (f) on an example entry (pasted below), emacs crashed (screenshot).

image

What's in the bibtex entry is enough for JabRef or the org-ref-bibtex-hydra to open a pdf in my default pdf reader. But maybe I've misconfigured citar?

About my "what to type" question, I have the feeling that it will be answered by the updated screenshot.

My citar config

(use-package citar
  :defer t
  :bind (("C-c b" . citar-insert-citation)
         :map minibuffer-local-map
         ("M-b" . citar-insert-preset))
  :custom
  (citar-bibliography '("~/OneDrive/share/ref/energy.bib"))
  (citar-library-paths '("~/OneDrive/share/ref/papers")))

;; needed?
;; (setq citar-file-parser-functions
;;   '(citar-file-parser-default
;;     citar-file-parser-triplet)

;; use consult-completing-read for enhanced interface
;; From: https://github.com/bdarcus/citar
(with-eval-after-load 'embark
  (advice-add #'completing-read-multiple :override
              #'consult-completing-read-multiple))

;; org native citations
;; From: https://github.com/bdarcus/citar
(use-package citar-org
  :no-require
  :ensure nil
  ; citar-org is in citar: https://github.com/bdarcus/citar/issues/380
  :straight citar  
  :bind
 :bind
  (:map org-mode-map :package org ("C-c b" . #'org-cite-insert)) ; also  C-c C-x C-@
  :custom
  (org-cite-global-bibliography '("~/OneDrive/share/ref/energy.bib"))
  (org-cite-insert-processor 'citar)
  (org-cite-follow-processor 'citar)
  (org-cite-activate-processor 'citar)
  (citar-at-point-function 'embark-act)
  :init
  (citar-filenotify-setup '(LaTeX-mode-hook org-mode-hook)))

An example bibtex entry:

@Article{Stuart09missDatLargeDat,
  author    = {Stuart, Elizabeth A. and Azur, Melissa and Frangakis, Constantine and Leaf, Philip},
  title     = {Multiple Imputation With Large Data Sets: A Case Study of the Children's Mental Health Initiative},
  journal   = {American Journal of Epidemiology},
  year      = {2009},
  volume    = {169},
  number    = {9},
  pages     = {1133--1139},
  abstract  = {Multiple imputation is an effective method for dealing with missing data, and it is becoming increasingly common in many fields. However, the method is still relatively rarely used in epidemiology, perhaps in part because relatively few studies have looked at practical questions about how to implement multiple imputation in large data sets used for diverse purposes. This paper addresses this gap by focusing on the practicalities and diagnostics for multiple imputation in large data sets. It primarily discusses the method of multiple imputation by chained equations, which iterates through the data, imputing one variable at a time conditional on the others. Illustrative data were derived from 9,186 youths participating in the national evaluation of the Community Mental Health Services for Children and Their Families Program, a US federally funded program designed to develop and enhance community-based systems of care to meet the needs of children with serious emotional disturbances and their families. Multiple imputation was used to ensure that data analysis samples reflect the full population of youth participating in this program. This case study provides an illustration to assist researchers in implementing multiple imputation in their own data.},
  comment   = {How to use R package "mice" for multiple imputation on large datasets},
  doi       = {10.1093/aje/kwp026},
  eprint    = {http://aje.oxfordjournals.org/content/169/9/1133.full.pdf+html},
  file      = {Stuart09missDatLargeDat.pdf:Stuart09missDatLargeDat.pdf:PDF},
  owner     = {scot},
  timestamp = {2010.09.09},
  url       = {http://aje.oxfordjournals.org/content/169/9/1133.abstract},
}
bdarcus commented 2 years ago

;; needed? ;; (setq citar-file-parser-functions ;; '(citar-file-parser-default ;; citar-file-parser-triplet)

Yes, I think you need this.

What happens if you uncomment that?

Also, even so, I don't understand why emacs would freeze because of that. All those functions do is parse the field, and then throw out results that are not existing files.

Is it possible you have a corrupted file or something?

Possible to get debug output?

bdarcus commented 2 years ago

FYI, I just added the triplet parser to default, so you shouldn't need to configure it now.

notuntoward commented 2 years ago

Thanks for the modification. Using it, I still got an emacs crash, but this time, I'm sending you the backtrace

emacs_backtrace.txt

bdarcus commented 2 years ago

Thanks.

Alas, I have no idea how to read/interpret that. Do you?

I was just wondering on what it crashed.

notuntoward commented 2 years ago

Yeah, I don't know what to do with that file either.

But I'd love to get citar working -- do you have any other debugging tips, especially for someone who doesn't know much about elisp?

bdarcus commented 2 years ago

The classic approach is turning on toggle-debug-on-error, but I'm not sure if that'll work with a crash.

notuntoward commented 2 years ago

Tried that too...

The problem looks deep enough that it could be in the C libraries. That seems unlikely, but still I'm going to try this on a Mac, and with emacs 28.

On Wed, Nov 10, 2021 at 4:55 PM bdarcus @.***> wrote:

The classic approach is turning on toggle-debug-on-error, but I'm not sure if that'll work with a crash.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bdarcus/citar/issues/389#issuecomment-965896045, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5MM4ZC6G7KNKHYEHVIPQTULMIAJANCNFSM5HUTCSCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

notuntoward commented 2 years ago

On MacOS emacs, either v28 or v27, there is no crash when I try citar-open-library-files (f); the pdf opens up inside an emacs window with no problem. I think with a small change, citar could do the something equivalent on Windows.

Maybe the MacOS success has something to do with the fact that the emacs-plus homebrew package I installed, builds-in imagemagick. I've found that this is practically impossible to do on Windows but it's also become unnecessary. Since emacs 27.1, emacs can internally open pdfs with its own built-in JSON function. Although this hasn't been perfect, it usually works. Just not, apparently, when citar is trying to do it.

Hard to say what's going on here, but I bet that citar would work on Windows if it opened pdf files with the OS default pdf reader. I've already customized org-ref and plain bibtex mode to do this, borrowing a function from helm:

(bibtex-completion-pdf-open-function 'helm-open-file-with-default-tool)

Can citar be similarly configured?

bdarcus commented 2 years ago

So you ran into an Emacs bug basically.

Can citar be similarly configured?

Yes, you can do:

(setq citar-file-open-function 'citar-file-open-external)

This may or may not need refinement going forward; not sure. I think right now that will open all library files "externally."

notuntoward commented 2 years ago

That works for now. Thanks!