‘The half minute which we daily devote to the winding-up of our watches is an exertion of labour almost insensible; yet, by the aid of a few wheels, its effect is spread over the whole twenty-four hours.’

Dynamically set pdf-tools annotation colours

Benjamin Slade

In Emacs, pdf-tools can be used to add annotations to a PDF document. It can be useful to have multiple annotation colours though, and be able to set these on the fly.

Here’s an example of how to do it with four colours:

;; annotation colours
(defun bms/pdf-annot-colour-blue ()
  (interactive)
  (setq pdf-annot-default-markup-annotation-properties
        '((label . "") (color . "blue") (popup-is-open)))
  (message "%s" (propertize "Annotation colour set to blue." 'face '(:foreground "blue"))))

(defun bms/pdf-annot-colour-yellow ()
  (interactive)
  (setq pdf-annot-default-markup-annotation-properties
        '((label . "") (color . "yellow") (popup-is-open)))
    (message "%s" (propertize "Annotation colour set to yellow." 'face '(:foreground "yellow"))))

(defun bms/pdf-annot-colour-red ()
  (interactive)
  (setq pdf-annot-default-markup-annotation-properties
        '((label . "") (color . "red") (popup-is-open)))
  (message "%s" (propertize "Annotation colour set to red." 'face '(:foreground "red"))))

(defun bms/pdf-annot-colour-orange ()
  (interactive)
  (setq pdf-annot-default-markup-annotation-properties
        '((label . "") (color . "orange") (popup-is-open)))
  (message "%s" (propertize "Annotation colour set to orange." 'face '(:foreground "orange"))))

;; rebind keys for pdf-tools
(defun bms/pdf-tools-mode-config ()
  "Set pdf-tools keybindings."
  (local-set-key (kbd "R") #'bms/pdf-annot-colour-red)
  (local-set-key (kbd "L") #'bms/pdf-annot-colour-blue)
  (local-set-key (kbd "O") #'bms/pdf-annot-colour-orange)
  (local-set-key (kbd "Y") #'bms/pdf-annot-colour-yellow))

;; add to pdf-view-mode-hook
(add-hook 'pdf-view-mode-hook #'bms/pdf-tools-mode-config)

Example in use (though some of the colours might be better chosen, e.g. a lighter shade of blue):

If you have written a response to this, enter your response post's URL below.

Or, you can send a "comment" webmention (it's OK if you don't know what that means). When asked about your website on an IndieAuth login screen, simply type https://commentpara.de.

Markdown Support**bold**, _italics_, ~~strikethrough~~, [descr](link), `monospace`, ```LANG\nline1\nline2\n``` (Yep, multi-line code blocks too, with syntax highlighting!), auto-hyperlinking.

Webmentions #