Highlight inverse search in Emacs + AUCTeX

by Massimo Lauria

I always lose track of the cursor when I use inverse search on LaTeX documents. This small hack will mitigate the pain.

One cool addition to Emacs, if you write papers using LaTeX1, is the powerful AUCTeX software. Among tons of useful features it gives the possibility to jump from any point in your LaTeX code to the corresponding point in the PDF document (this is called “forward search” in the lingo). If you have a proper PDF viewer (e.g. Evince on Linux or Skim on MacOSX) the target location will be highlighted.


But what about the opposite? If your setup is correct it is possible to click on the preview document, and Emacs will jump to the corresponding point in the appropriate LaTeX file.

If you are like me, you like low contrast themes a big Emacs windows (frames in Emacs parlance), so it is easy to lose track of the cursor, which can end up anywhere. With the following piece of code every time you use inverse search, the target location in the LaTex file will be highlighted as well.

(defadvice TeX-source-correlate-sync-source (after ad-TeX-correlate-center)
    "Center and highlight point after AUCTeX inverse-search."
    (pulse-momentary-highlight-one-line (point)))

Here’s the result.


This is of course useless if you use global-hl-line-mode, but I find quite annoying. The actual highlight style is due to the pulse.el package (included in recents GNU/Emacs versions).



which you should do, whatever some misinformed researchers say. At least if you are in Math, CS or Physics.