Unfortunately for a two column format pdf file, forward search only jumps to the corresponding left hand column line; even though the relevant latex text appears on the right hand column. Is there a way to fix this?
I think that this would be better as a separate question (for organisational purposes), but here's a hacky solution.
I'm going to override the definition of
TeX-pdf-tools-sync-view, with an "advice", to avoid having to play around with customizing
TeX-view-program-selection. Since it's not used elsewhere, this should be harmless. I'm not going to override
pdf-sync-forward-search (and will instead define
pdf-sync-forward-search-custom, based on them), in case they're referred to somewhere else.
(defun TeX-pdf-tools-sync-view-custom ()
"Focus the focused page/paragraph in `pdf-view-mode'.
If `TeX-source-correlate-mode' is disabled, only find and pop to
the output PDF file. Used by default for the PDF Tools viewer
entry in `TeX-view-program-list-builtin'."
;; Make sure `pdf-tools' is at least in the `load-path', but the user must
;; take care of properly loading and installing the package. We used to test
;; "(featurep 'pdf-tools)", but that doesn't play well with deferred loading.
(unless (fboundp 'pdf-tools-install)
(error "PDF Tools are not available"))
(error "PDF Tools only work with PDF output"))
(if (and TeX-source-correlate-mode
(with-current-buffer (or (when TeX-current-process-region-p
(get-file-buffer (TeX-region-file t)))
(let ((pdf (concat file "." (TeX-output-extension))))
(pop-to-buffer (or (find-buffer-visiting pdf)
(advice-add 'TeX-pdf-tools-sync-view :override #'TeX-pdf-tools-sync-view-custom)
(defun pdf-sync-forward-search-custom (&optional line column)
"Display the PDF location corresponding to LINE, COLUMN."
(cl-destructuring-bind (pdf page x1 y1 _x2 _y2)
(pdf-sync-forward-correlate line column)
(let ((buffer (or (find-buffer-visiting pdf)
(when (and y1 x1)
(let ((top (* y1 (cdr (pdf-view-image-size))))
(right (* x1 (car (pdf-view-image-size)))))
(pdf-util-tooltip-arrow-custom (round top) (round right))))))
(defun pdf-util-tooltip-arrow-custom (image-top image-right &optional timeout)
(when (floatp image-top)
(round (* image-top (cdr (pdf-view-image-size))))))
(when (floatp image-right)
(round (* image-right (car (pdf-view-image-size))))))
(let* (x-gtk-use-system-tooltips ;allow for display property in tooltip
(pos (list dx dy dx (+ dy (* 2 (frame-char-height)))))
`((border-width . 0)
(internal-border-width . 0)
(tooltip-hide-delay (or timeout 3)))
(setq dy (max 0 (- dy
(window-vscroll nil t)
(when (overlay-get (pdf-view-current-overlay) 'before-string)
(let* ((e (window-inside-pixel-edges))
(xw (pdf-util-with-edges (e) e-width)))
(cl-incf dx (/ (- xw (car (pdf-view-image-size t))) 2))))
" " 'display (propertize
"\u2192" ;;right arrow
'display '(height 2)
,(if (bound-and-true-p pdf-view-midnight-minor-mode)
You can also obviously play around with these definitions to better suit you (the original code is quite comprehensible).
Here are the original definitions of the functions, for comparison (the changes I've made are minor):
pdf-util-tooltip-arrow, pdf-sync-forward-search, TeX-pdf-tools-sync-view.
You can disable the new behaviour by removing the "advice":
(advice-remove 'TeX-pdf-tools-sync-view 'TeX-pdf-tools-sync-view-custom)