0

Problem description:

I am working on a small notebook and often find myself reading pdf's on half the screen, which is even smaller. Sometimes I would like to be able to zoom into a pdf a tiny bit more, which I can, but then the pdf gets left aligned and the text to the right is cut off. With a more common pdf reader I would simply scroll a little to the right. The whole text would be visible and everyting would be fine. For some reason scrolling to the right/left does not work for me in emacs. Please look at the image to understand my predicament more clearly: enter image description here

I looked at the pdfview wiki and found that the key bindings:

C-f
C-b

or

C-x >
C-x <

should both do the trick. For some reason they do not scroll the pdf for me. I cross referenced the respective functions bound to the keys in emacs and found that they seem to be correctly bound to the keys. The functions are:

image-forward-hscroll
image-backward-hscroll

or

scroll-right
scroll-left

The key-bindings are part of the pdfview-mode-map, the image-mode-map and the doc-view-mode-map. I seem to be able to use the other bindings from the pdfview-mode-map.

I tried to fit the pdf to the buffer width with W (fit pdf to width) as a work around but this solution still does not zoom enough as it respects the white space beside the text.

Can someone give me a hint how to get the scrolling functions working?

Possibly helpful information:

I am on gnu Emacs 28.1.

The part of my config with pdf-tools:

;;////////////////////////PDF\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
(use-package pdf-tools
 :pin manual ;; manually update
 :config
 ;; initialise
 (pdf-tools-install)
 ;; open pdfs scaled to fit page
 (setq-default pdf-view-display-size 'fit-page)
 ;; automatically annotate highlights
 (setq pdf-annot-activate-created-annotations t)
 ;; use normal isearch
 (define-key pdf-view-mode-map (kbd "C-s") 'isearch-forward)
 ;; turn off cua so copy works
 (add-hook 'pdf-view-mode-hook (lambda () (cua-mode 0)))
 ;; more fine-grained zooming
 (setq pdf-view-resize-factor 1.1)
 ;; keyboard shortcuts
 (define-key pdf-view-mode-map (kbd "h") 'pdf-annot-add-highlight-markup-annotation)
 (define-key pdf-view-mode-map (kbd "t") 'pdf-annot-add-text-annotation)
 (define-key pdf-view-mode-map (kbd "D") 'pdf-annot-delete))

(use-package org-noter
  :config
  ;; Your org-noter config ........
  (require 'org-noter-pdftools))

(use-package org-pdftools
  :hook (org-mode . org-pdftools-setup-link))

(use-package org-noter-pdftools
  :after org-noter
  :config
  ;; Add a function to ensure precise note is inserted
  (defun org-noter-pdftools-insert-precise-note (&optional toggle-no-questions)
    (interactive "P")
    (org-noter--with-valid-session
     (let ((org-noter-insert-note-no-questions (if toggle-no-questions
                                                   (not org-noter-insert-note-no-questions)
                                             org-noter-insert-note-no-questions))
           (org-pdftools-use-isearch-link t)
           (org-pdftools-use-freestyle-annot t))
       (org-noter-insert-note (org-noter--get-precise-info)))))

  ;; Set key for quick access to working environments
 (global-set-key (kbd "C-d") 'desktop-change-dir)
   ;; fix https://github.com/weirdNox/org-noter/pull/93/commits/f8349ae7575e599f375de1be6be2d0d5de4e6cbf
  (defun org-noter-set-start-location (&optional arg)
    "When opening a session with this document, go to the current location.
With a prefix ARG, remove start location."
    (interactive "P")
    (org-noter--with-valid-session
     (let ((inhibit-read-only t)
           (ast (org-noter--parse-root))
           (location (org-noter--doc-approx-location (when (called-interactively-p 'any) 'interactive))))
       (with-current-buffer (org-noter--session-notes-buffer session)
         (org-with-wide-buffer
          (goto-char (org-element-property :begin ast))
          (if arg
              (org-entry-delete nil org-noter-property-note-location)
            (org-entry-put nil org-noter-property-note-location
                           (org-noter--pretty-print-location location))))))))
  (with-eval-after-load 'pdf-annot
    (add-hook 'pdf-annot-activate-handler-functions #'org-noter-pdftools-jump-to-note)))
;; I installed pdf-tools, org-pdf-tools and org-noter manually
;; makes org-mode open pdf-links with pdfview
(add-to-list 'org-file-apps 
             '("\\.pdf\\'" . pdfview))
6
  • Try using M-x image-forward-hscroll within the pdf-view buffer, it might also inform you about the actual keybinding. Otherwise, you could also do M-x toggle-horizontal-scroll-bar to scroll via the scroll-bar. Oct 29, 2022 at 6:57
  • Thank you for your suggestions! I didn't know about the horizontal scroll bar. Unfortunately the scroll bar appears but does nothing when dragged.
    – pana pana
    Oct 29, 2022 at 8:55
  • Ah too bad... but does the first suggestion work (scroll a tiny bit) at least? Oct 29, 2022 at 10:34
  • No, I didn't write that but I had tried that before. When I have some time I will simply try different emacs versions. Hopefully the problem is connected to 28.1 somehow.
    – pana pana
    Oct 29, 2022 at 10:43
  • 2
    Testing the config part by part revealed that setting global-display-line-numbers-mode active breaks horizontal scrolling. Deactivating it was sufficient to get it working again.
    – pana pana
    Oct 29, 2022 at 18:15

1 Answer 1

3

I had the same problem and I also discovered the hard way that global-display-line-numbers-mode breaks image-forward-hscroll.

I have the following workaround:

(defun bugfix-display-line-numbers--turn-on (fun &rest args)
  "Avoid `display-line-numbers-mode' in `image-mode' and related.
Around advice for FUN with ARGS."
  (unless (derived-mode-p 'image-mode 'docview-mode 'pdf-view-mode)
    (apply fun args)))

(advice-add 'display-line-numbers--turn-on :around #'bugfix-display-line-numbers--turn-on)

I already filed a bug report: https://lists.gnu.org/archive/html/bug-gnu-emacs/2022-12/msg02439.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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