The standard way to define clickable text is explained in the manual.
- put an appropriate face, e.g.
link and the text property keymap on the link text.
- bind the
follow-link event in that keymap to a function, e.g. arXivid-follow, that transforms the text into a link
- the function gets an event that leads you to the click position where you can extract the id and transform it into a link
- follow the link with
browse-url
As lawlist indicated in his comment, you can let font-lock find and propertize the link text in the buffer.
The following code defines a minor mode arXivid-mode that adds the required keyword to font-lock-keywords.
(defun arXivid-link-at-point (&optional point)
"Return \\arXivid{ID} link at POINT or nil if there is none."
(save-excursion
(when point
(goto-char point))
(skip-chars-backward "^[:space:]\\\\")
(and
(eq (char-before) ?\\)
(looking-at "arXivid{\\([0-9.]+\\)}")
(concat "https://arxiv.org/abs/" (match-string 1)))))
(defun arXivid-follow (event)
"Follow \arXivid{ID} links."
(interactive "e")
(let ((window (posn-window (event-end event)))
(pos (posn-point (event-end event)))
link)
(if (not (windowp window))
(error "Something is very wrong..."))
(with-current-buffer (window-buffer window)
(goto-char pos)
(let ((link (arXivid-link-at-point)))
(when link
(browse-url link))))))
(defvar arXivid-keymap
(let ((map (make-sparse-keymap)))
(define-key map [follow-link] #'arXivid-follow)
map)
"Keymap for \arXivid{ID} links.")
(defvar arXivid-keywords
'(("\\arXivid{\([0-9.]+\)}"
(0 (face link keymap ,arXivid-keymap) prepend))) "Additional font lock keywords forarXivid-mode'.")
(define-minor-mode arXivid-mode
"Minor mode making \arXivid{ID} clickable."
:lighter " arX"
(if arXivid-mode
(font-lock-add-keywords
nil
arXivid-keywords
t)
(font-lock-remove-keywords
nil
arXivid-keywords))
(font-lock-flush)
(font-lock-ensure))
\arXivid{1602.00735}clickable? Also, are you seeking to incorporate this behavior into the AUCTeX library such that the text-properties are automatically laid; e.g., asfont-lockdoes its thing? – lawlist Jan 29 '21 at 22:27org-set-font-lock-defaultsand see how the links are activated as part offont-lock... You may wish to do something similar with the AUCTeX or other similar library that you are using to fontify the buffer text. The answer to this question, however, is non-trivial (in my opinion) but nevertheless completely doable. – lawlist Jan 29 '21 at 22:36