This is an extension of my previous question auctex and pdf-tools in 2 separate frames which was nicely answered by Tobias. I use auctex in one frame and pdftools in another frame. Forward and inverse search work perfectly between the two frames. The question I have is this: how to make forward and inverse search work when I split each frame into 2 buffers? That is, I have the latex source of a file in one frame split into 2 buffers (with C-x 2); lets call these buffers latex1 and latex2. Similarly I have the corresponding pdf frame split into two buffers - lets call them pdf1 and pdf2. My questions is: how to setup forward and inverse search between latex1 and pdf1, and also between latex2 and pdf2? This helps working on two parts of a large latex document.I need the above setup of two separate frames, one frame for latex (with 2 buffers) and one frame for pdf (with 2 buffers), due to eyesight problems.
The following code generalizes the answer to your other question about showing the pdf in another frame.
It requires a bit more interaction from your side.
I propose you set up your frame and window layout beforehand - two frames with two windows each. The windows do not need to show the right buffers yet. You certainly need the two windows with the LaTeX buffer since you need some starting point.
Select one of the LaTeX windows and call
TeX-View, e.g., via C-c C-a.
The first time you are prompted with
Associate window. Click in the pdf-window which you want to associate with the LaTeX window.
Do the same for the other TeX window.
Afterwards forwards and inverse search should just work as you want it.
(defun framesMenus-read-window (&optional prompt) "Prompt with PROMPT and read a window." (save-selected-window (let ((frame (selected-frame)) window ev) (while (progn (setq ev (read-event prompt)) (eq (event-basic-type ev) 'switch-frame)) (setq frame (cadr ev))) (with-selected-frame frame (and (window-live-p (setq window (posn-window (event-start ev)))) window ))))) (defvar-local framesMenus-associated-other-window nil "Alist of other windows associated with selected windows for a buffer.") (defun framesMenus-associated-other-window (&optional prompt force mutual) "Return the other window associated with the current buffer. PROMPT is forwarded to `framesMenus-read-window' when called. When FORCE is non-nil always prompt for the associated window. If MUTUAL is non-nil also associate other window with this one." (let* ((this-window (selected-window)) (assoc-window (assoc this-window framesMenus-associated-other-window)) (other-window (cdr assoc-window))) (unless (and (null force) (window-live-p other-window) other-window) (cl-pushnew (cons (selected-window) (setq other-window (framesMenus-read-window prompt))) framesMenus-associated-other-window :key #'car )) (when mutual (with-selected-window other-window (cl-pushnew (cons other-window this-window) framesMenus-associated-other-window :key #'car))) other-window)) (defun framesMenus-display-in-associated-window (buffer _action-list) "Display BUFFER in associated window." (let ((window (framesMenus-associated-other-window "Associate window." nil t))) (with-selected-window window (switch-to-buffer buffer)) window)) (defun framesMenus-display-buffer-use-associated-window (fun &rest args) "Use `display-buffer-use-some-frame' as `display-buffer-overriding-action'. Then run FUN with ARGS." (let ((display-buffer-overriding-action '(framesMenus-display-in-associated-window))) (apply fun args))) (advice-add 'TeX-pdf-tools-sync-view :around #'framesMenus-display-buffer-use-associated-window) (advice-add 'pdf-sync-backward-search-mouse :around #'framesMenus-display-buffer-use-associated-window)