czm-tex-jump.el: Jump to references in a TeX buffer using avy

Overview

This package provides a command czm-tex-jump that supports following references in a TeX buffer using avy. The functionality is roughly similar to that of reftex-view-crossref, but useful in situations where reftex doesn’t work (e.g., indirect buffers and org latex src blocks), and it’s implemented using avy, so you don’t have to spend keystrokes on navigation.

Here’s how it looks in action (using czm-preview.el and czm-tex-fold.el to display label numbers in the buffer):

./img/both.gif

Configuration

This package requires czm-tex-util.el, so install that first.

Download this repository, install using M-x package-install-file (or package-vc-install, straight, elpaca, …), and add something like the following to your init file:

(use-package czm-tex-jump
  :bind
  (:map LaTeX-mode-map
	("s-r" . czm-tex-jump)))

Replace “s-r” with your preferred key binding.

Usage

When you run czm-tex-jump, you will be prompted avy-style to select a reference to follow. By supplying one or more prefix arguments to this command, you can change the behavior: see the documentation (C-h f czm-tex-jump) for details.

Issues

If \ref{…} appears at the beginning of a line, then the avy anchor will appear at the end of the previous line, which may be slightly counterintuitive. (This is because I use the character before the backslash in “\ref{…}” as the anchor for avy. It would be natural to anchor instead on the backslash itself, but I’m in the habit of folding the full string “\ref{…}” using czm-tex-fold.el, and avy doesn’t cooperate with folds.) A workaround is to avoid putting \ref{…} at the beginning of a line.