5

I run auctex with the latex source on the left half buffer and corresponding pdf on the right half (using C-x 3 to split the buffer). I then split the left half buffer into 2 so as two work on different parts of the latex source file. Similarly I split the right hand buffer into two so as to view the two corresponding pdf parts. Is there some way of doing forward/reverse search between the top left latex source and top right pdf; and a forward/reverse search between the bottom left latex source and bottom right pdf? This would help a lot when working on a large latex document. Right now, the top left and bottom left latex source do forward/backward search with the top right pdf; the bottom right pdf seems to be ignored.

3

You can set the preferred window via the ACTION for display-buffer, which see. That also works for commands that use display-buffer.

From all the possibilities for setting the ACTION the variable display-buffer-overriding-action has the highest priority.

The following code shows how to define the action you want and how to set display-buffer-overriding-action for the commands you need.

(defun display-buffer-beside-selected (buffer alist)
  "Try displaying BUFFER in a window beside the selected window.
If there is a window below the selected one and that window
already displays BUFFER, use that window.
If that attempt fails and there is a non-dedicated window
beside the selected one, use that window.
The left or right hand side is chosen if ALIST contains
the cons (side . left) or (side . right), respectively."
  (let (window)
    (or (and (setq window (window-in-direction (cdr (assq 'side alist))))
         (eq buffer (window-buffer window))
         (window--display-buffer buffer window 'reuse alist))
    (and (setq window (window-in-direction (cdr (assq 'side alist))))
         (not (window-dedicated-p window))
         (window--display-buffer
          buffer window 'reuse alist display-buffer-mark-dedicated)))))

(defun my-display-buffer-right (fun &rest args)
  "Use `display-buffer-in-side-window' as `display-buffer-overriding-action'.
Then run FUN with ARGS."
  (let ((display-buffer-overriding-action '(display-buffer-beside-selected (side . right))))
    (apply fun args)))

(defun my-display-buffer-left (fun &rest args)
  "Use `display-buffer-in-side-window' as `display-buffer-overriding-action'.
Then run FUN with ARGS."
  (let ((display-buffer-overriding-action '(display-buffer-beside-selected (side . left))))
    (apply fun args)))

(advice-add 'TeX-pdf-tools-sync-view :around #'my-display-buffer-right)
(advice-add 'pdf-sync-backward-search-mouse :around #'my-display-buffer-left)
| improve this answer | |
  • Thank you sir! That works perfectly! I have a related new question which I will post. – Vikram Feb 4 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.