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
479 stars 53 forks source link

`citar-open-entry` receives wrong citekey #822

Open pgoelz opened 4 months ago

pgoelz commented 4 months ago

Describe the bug I set up citar with embark. All actions work, but citar-open-entry is called with a spurious citekey.

To Reproduce Steps to reproduce the behavior:

  1. Place cursor on citation key. (E.g., the citation is [cite:@NW06] and citar knows about it: hovering over it gives me the full citation. My cursor is on the “N”, but the result is the same if it is on the cite: part.)
  2. Call embark-act, either explicitly or through C-c C-o.
  3. Press e to call citar-open-entry.

Expected behavior I would expect citar-open-entry to be called with the argument "NW06". Instead, it gets called with the first reference in my bib file, "AAA+18".

Screenshots

image

Note that embark is aware of the correct citar-key, NW06.

Emacs version: 29.1. I installed citar and embark using straight, so I’m up to date with their respective main/master branches.

Additional context To better understand this issue, I set citar-open-entry-function to a function that prints its argument, which indeed gets called with the argument AAAI+18. I also verified that running (citar-open-entry "NW06") would indeed open the entry for NW06. What I am most confused by is that the other options in embark-act (say, r for citar-copy-reference) receive the correct reference when selected.

bdarcus commented 4 months ago

Hi @pgoelz - I can't reproduce that. On my end, it works as expected.

pgoelz commented 4 months ago

Thanks for trying, Bruce! Do you have any advice for how to narrow it down on my side? I’m stuck because I’m not familiar with embark and so don’t understand where embark calls citar-open-entry. Do you see any reason why citar-open-entry might receive something different than citar-copy-reference? FWIW, my citar-config is very vanilla and I haven’t changed anything in the package.

pgoelz commented 4 months ago

I’ve been able to reproduce the error when starting from a fresh spacemacs configuration file and a minimal bibliography.

Bibliography, to be placed in /tmp/bib.bib:

@techreport{AAA+18,
  title = {Market Failure in Kidney Exchange},
  author = {Agarwal, Nikhil and Ashlagi, Itai and Azevedo, Eduardo and Featherstone, Clayton R. and Karaduman, {\"O}mer},
  year = {2018},
  institution = {{National Bureau of Economic Research}}
}

@book{NW06,
  title = {Numerical Optimization},
  author = {Nocedal, Jorge and Wright, Stephen J.},
  year = {2006},
  series = {Springer Series in Operations Research},
  edition = {2nd ed},
  publisher = {{Springer}},
  address = {{New York}}
}

Org-file in which the problem occurs:

[cite:@NW06]

The .spacemacs file is unchanged except for the following additions to user-config:

(defun dotspacemacs/user-config ()
  "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer
configuration.
Put your configuration code here, except for variables that should be set
before packages are loaded."
    ;; install the straight package manager
    (defvar bootstrap-version)
    (let ((bootstrap-file
           (expand-file-name
            "straight/repos/straight.el/bootstrap.el"
            (or (bound-and-true-p straight-base-dir)
                user-emacs-directory)))
          (bootstrap-version 7))
      (unless (file-exists-p bootstrap-file)
        (with-current-buffer
            (url-retrieve-synchronously
             "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
             'silent 'inhibit-cookies)
          (goto-char (point-max))
          (eval-print-last-sexp)))
      (load bootstrap-file nil 'nomessage))
    (straight-use-package 'org)

    (setq org-cite-global-bibliography '("/tmp/bib.bib"))

    (straight-use-package 'embark)
    (straight-use-package 'citar)
    (straight-use-package 'citar-embark)
    (setq citar-bibliography '("/tmp/bib.bib"))
    (defun debugging-log (citekey)
      (switch-to-buffer-other-window "*log*")
      (erase-buffer)
      (insert citekey)
      (other-window 1)
    )
    (setq citar-open-entry-function 'debugging-log)
    (citar-embark-mode)
)

I’m also attaching the full .spacemacs file: spacemacs.txt.

With this, I can reproduce the problem: calling embark-act and pressing e logs "AAA+18" into the *log* buffer rather than the expected "NW06". (Note that embark-act must be called manually, since I haven’t set citar-at-point-function.)

@bdarcus, does anything in the above look problematic to you?

bdarcus commented 4 months ago

I think the + in that first key may be invalid?

❯ bibcop /tmp/test.bib
It is impossible to parse the .bib file, because I do not know what to do with '+' at line no.0 (s=tag)

What happens if you change it?

As a general rule, it's often the case when something unexpected like this, there's an issue with the input file.

pgoelz commented 4 months ago

Thanks, Bruce! The issue persists when I delete the + from the citation key, and even when I reduce the bibliography to

@book{A,
    title = {A},
    author = {Anderson, Anthony},
    year = {2000}
}

@book{B,
    title = {B},
    author = {Baker, Bessie},
    year = {2001}
}
bdarcus commented 4 months ago

Seems pretty likely there's something wrong on your local system.

I note that you don't really configure Embark, but I doubt that would matter in this case.

Maybe try rebuilding your packages??

PS - there's a little test script in the repo test/manual directory. If I run (run.sh) that, it works as expected again.