In my LaTeX
code I have functions that generate hyperlinks in the PDF file. I have, e.g.:
\newcommand{\arXivid}[1]{\href{https://arxiv.org/abs/#1}{\tt arXiv:#1}}
So, in my LaTeX
code I have strings like \arXivid{1207.7235}
that points to https://arxiv.org/abs/1207.7235
.
I'd like to have these strings clickable in the emacs
' so I tried this function:
(defun my-follow-link ()
(interactive)
(require 'button)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp "\\\\arXivid{\\([^}]+\\)}" nil t)
(save-excursion
(let* ((b (copy-marker (match-beginning 0)))
(e (copy-marker (match-end 0)))
(ID (match-string-no-properties 1))
(URL (concat "https://arxiv.org/abs/" ID))
)
(make-button b e 'action (lambda(x) (browse-url URL)))
;; (let ((map (make-sparse-keymap)))
;; (define-key map [mouse-2] '(lambda(x) (browse-url URL)))
;; (put-text-property b e 'keymap map))
)))
)
)
I get this error message:
Symbol’s value as variable is void: URL
I understand that let-binding the
URL
variable was not a good idea. But I have no idea to fix my code.The
button
seems to respond only to theRETURN
key, not to mouse click.I tried also to use
text-property
(the commented code) as explained here: https://www.gnu.org/software/emacs/manual/html_node/elisp/Clickable-Text.html but the code didn't work (I didn't understand it completely).
Where did I go wrong?