jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.36k stars 242 forks source link

Cannot reference an equation using org-ref-insert-ref-link #828

Closed cemeroncel closed 3 years ago

cemeroncel commented 3 years ago

Hello,

I have the following org document:

#+Title: An org file to test features of the org-ref
Consider the following table

#+caption: Table, label:tbl-test
| Name   | Score |
|--------+-------|
| Alex   |    89 |
| Philip |    68 |
| Ben    |    85 |

and the following equation

\begin{equation}
x^2 + y^2 = z^2 \label{eq:1}
\end{equation}

I can reference the table tbl-test via org-ref-insert-ref-link without an issue. But when I try to reference the equation, I get the following error:

org-ref-infer-ref-type: Symbol’s function definition is void: return

I can enter the reference manually as eqref:eq:1. The same problem appears when I use the menu item Org -> org-ref -> Insert ref. I am using the following minimal init.el:

(require 'package)
(add-to-list 'package-archives
         '("melpa" . "http://melpa.org/packages/") t)
(when (< emacs-major-version 24)
  ;; For compatibility
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)

(setq reftex-default-bibliography '("~/Dropbox/Org/bibliography/references.bib"))

;; see org-ref for use of these variables
(setq org-ref-bibliography-notes "~/Dropbox/Org/bibliography/notes.org"
      org-ref-default-bibliography '("~/Dropbox/Org/bibliography/references.bib")
      org-ref-pdf-directory "~/Dropbox/Org/bibliography/pdfs/")

(require 'org-ref)

Any help is appreciated.

Emacs version : 27.1 on Ubuntu 20.04 Org version : 9.3 (which comes default with Emacs) Org-ref version : 1.1.1 (installed from Melpa)

jkitchin commented 3 years ago

That was a bug indeed, thanks for reporting it. I have pushed a fix that should work on melpa in a few hours.

cemeroncel commented 3 years ago

Thank you for the quick response. Unfortunately, now I get the following message when I start emacs.

Eager macro-expansion failure: (error "Expected a cl-loop keyword, found cl-return") [2 times]

Now if I use org-ref-insert-ref-link to refer to an equation I get

progn: No catch for tag: --cl-block-nil--, "eqref"
jkitchin commented 3 years ago

I think I have pushed some fixes for this. it will be later this evening before I can verify it works with the MELPA version.

jkitchin commented 3 years ago

ok, I just tested the latest melpa version, and I am pretty sure it finally works!

cemeroncel commented 3 years ago

After the latest update, the first problem, with the error Eager macro-expansion failure:... is fixed, but I still get the error

progn: No catch for tag: --cl-block-nil--, "eqref"

when I try to reference an equation with org-ref-insert-ref-link. I tried with a fresh Emacs directory, and also by cloning org-ref directly from Github.

Is there an alternative way to reference an equation? I can do it manually but it would really be helpful to see a list of equations.

jkitchin commented 3 years ago

I don't know what could be wrong here, these both work fine for me (git and Melpa).

Can you run M-x org-ref and paste the contents here?

jkitchin commented 3 years ago

If you add this block to your file and run it:

#+BEGIN_SRC emacs-lisp
(org-ref-get-labels)
#+END_SRC

Does it trigger the error?

cemeroncel commented 3 years ago

By running M-x org-ref I get

#+title: org-ref report on [[/home/dreameat/temp.org][temp.org]]

org-ref called from /home/dreameat/temp.org
* Unreferenced label links
- [[elisp:(progn (switch-to-buffer "temp.org") (goto-char 307)(org-show-entry))][eq:1]]

* Bibliography
- No bibliography style found. This may be ok, if your latex class style sets that up, but if not this is an error. Try adding something like:
    bibliographystyle:unsrt
    at the end of your file.
- [[~/Dropbox/Org/bibliography/references.bib]] (dialect = BibTeX)

* Miscellaneous
- org-latex-prefer-user-labels = nil
- bibtex-dialect = BibTeX
- biblatex is not required.
- biblatex is not used.
- emacs-version = GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2020-09-19
- org-version = 9.3
- org-ref: Version 1.1.1 (git-commit a5dfb7c820012b702b161596831dfbef1e3958fa)
- org-ref.el installed at /home/dreameat/.emacs.d/lisp/org-ref/org-ref.el
- completion backend = org-ref-helm-bibtex
- org-ref-default-bibliography = ("~/Dropbox/Org/bibliography/references.bib")
- org-ref-default-bibliography is a list = t
- org-latex-pdf-process is defined as (%latex -interaction nonstopmode -output-directory %o %f %latex -interaction nonstopmode -output-directory %o %f %latex -interaction nonstopmode -output-directory %o %f)
- natbib is not required.
- natbib is not in org-latex-default-packages-alist or org-latex-packages-alist.
- cleveref is not required.
- cleveref is not in org-latex-default-packages-alist or org-latex-packages-alist.
- org-latex-default-packages-alist
  ("AUTO" "inputenc" t ("pdflatex"))
  ("T1" "fontenc" t ("pdflatex"))
  ("" "graphicx" t)
  ("" "grffile" t)
  ("" "longtable" nil)
  ("" "wrapfig" nil)
  ("" "rotating" nil)
  ("normalem" "ulem" t)
  ("" "amsmath" t)
  ("" "textcomp" t)
  ("" "amssymb" t)
  ("" "capt-of" nil)
  ("" "hyperref" nil)
-  org-latex-packages-alist is nil

* Utilities

- [[elisp:(progn (find-file "/home/dreameat/temp.org") (ispell))][Spell check document]]
- [[elisp:(progn (find-file "/home/dreameat/temp.org") (org-ref))][recheck document with org-ref]]

org-ref-get-labels seems to work correctly. It returns

("tbl-test" "eq:1")
jkitchin commented 3 years ago

I suppose (org-ref-infer-ref-type "eq:1") in that buffer is triggering the issue then?

cemeroncel commented 3 years ago

Yes. If I evaluate that code I got the following response in the messages buffer:

Debugger entered--Lisp error: (no-catch --cl-block-nil-- "eqref")
  throw(--cl-block-nil-- "eqref")
  (progn (throw '--cl-block-nil-- (eval (cdr pred-pair))))
  (if (funcall (car pred-pair) label) (progn (throw '--cl-block-nil-- (eval (cdr pred-pair)))))
  (while --dolist-tail-- (setq pred-pair (car --dolist-tail--)) (if (funcall (car pred-pair) label) (progn (throw '--cl-block-nil-- (eval (cdr pred-pair))))) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (let ((--dolist-tail-- org-ref-ref-type-inference-alist) pred-pair) (while --dolist-tail-- (setq pred-pair (car --dolist-tail--)) (if (funcall (car pred-pair) label) (progn (throw '--cl-block-nil-- (eval (cdr pred-pair))))) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (or (let ((--dolist-tail-- org-ref-ref-type-inference-alist) pred-pair) (while --dolist-tail-- (setq pred-pair (car --dolist-tail--)) (if (funcall (car pred-pair) label) (progn (throw '--cl-block-nil-- (eval (cdr pred-pair))))) (setq --dolist-tail-- (cdr --dolist-tail--)))) org-ref-default-ref-type)
  org-ref-infer-ref-type("eq:1")
  eval((org-ref-infer-ref-type "eq:1") t)
  eval-expression((org-ref-infer-ref-type "eq:1") nil nil 127)
  funcall-interactively(eval-expression (org-ref-infer-ref-type "eq:1") nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)
jkitchin commented 3 years ago

ok. Thanks much for the patience in debugging this! I don't understand why it has been working for me, and not for you. I guess it has to do with some incantation of (require 'cl) here and there. fe792be might be the solution for you, where I hopefully use the right version of dolist (cl-dolist) here.

jkitchin commented 3 years ago

@cemeroncel does it work now?

cemeroncel commented 3 years ago

Now it works! Thank you very much for your help and this excellent package.