Giter Site home page Giter Site logo

Comments (19)

politza avatar politza commented on August 22, 2024

I'm unable to reproduce this. Are you shure the locations in the
source are different (comparing sliced to non-sliced) ?

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

I'll try to explain better what is going on. I've also made a short video that will be available for couple of days here [1]. The files used in the video are there too.

Going from tex to pdf with C-c C-g works fine no matter what slice size is set. However the double click on the pdf takes me to a proper position in tex only if there is no slice set. I often work with slice set to boundingbox which saves some screen real estate, but after hitting s b the double click on pdf takes me only approximately to where I want in the tex file.

[1] https://www.dropbox.com/sh/4sql1ije579veev/AAAcaSJslOC2SGRAbvteA9apa?dl=0

from pdf-tools.

politza avatar politza commented on August 22, 2024

No, I understand the problem. It's just that I don't have it.

Are you by any change using some older version of pdf-tools ?

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

I'm running 19fb029 from Jan 13. I'll update later today, check if it helps and report back. Should have started with updating as now I see that a lot has happened since Jan 13.

from pdf-tools.

politza avatar politza commented on August 22, 2024

There don't appear to be any relevant changes since this commit. So it
should be OK. I figure something out, later...

from pdf-tools.

politza avatar politza commented on August 22, 2024

Can you execute this function in some pdf buffer and post the result ?

(defun pdf-sync-test ()
  (interactive)
  (pdf-view-reset-slice)
  (pdf-view-fit-height-to-window)
  (image-bob)
  (let* ((pos1 (posn-object-x-y
                (event-start (read-event "Click on a spot"))))
         (size1 (pdf-view-image-size))
         (rpos1 (cons (/ (car pos1)
                         (float (car size1)))
                      (/ (cdr pos1)
                         (float (cdr size1))))))
    (pdf-view-set-slice-from-bounding-box)
    (read-event)
    (let* ((pos2 (posn-object-x-y
                  (event-start (read-event "Click on the same spot"))))
           (size2 (pdf-view-image-size))
           (rpos2 (cons (/ (car pos2)
                           (float (car size2)))
                        (/ (cdr pos2)
                           (float (cdr size2))))))
      (read-event)
      (message "dx=%.2f dy=%.2f pos=[(%d, %d), (%d, %d)] size=[(%d, %d), (%d, %d)]"
               (abs (- (car rpos1) (car rpos2)))
               (abs (- (cdr rpos1) (cdr rpos2)))
               (car pos1) (cdr pos1)
               (car pos2) (cdr pos2)
               (car size1) (cdr size1)
               (car size2) (cdr size2)))))

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

Here are 3 runs on one file:

dx=0.09 dy=0.07 pos=[(393, 541), (354, 521)] size=[(778, 1007), (856, 1108)]
dx=0.09 dy=0.06 pos=[(134, 581), (69, 569)] size=[(778, 1007), (857, 1109)]
dx=0.09 dy=0.07 pos=[(276, 780), (227, 786)] size=[(778, 1007), (860, 1113)]

and here are 3 runs on another file

dx=0.00 dy=0.08 pos=[(103, 501), (116, 480)] size=[(711, 1006), (808, 1143)]
dx=0.05 dy=0.07 pos=[(279, 375), (272, 340)] size=[(711, 1006), (804, 1137)]
dx=0.00 dy=0.08 pos=[(371, 578), (425, 567)] size=[(711, 1006), (809, 1144)]

Let me know if you need more.

from pdf-tools.

politza avatar politza commented on August 22, 2024

Can you repeat it with this function, please ?

(defun pdf-sync-test ()
  (interactive)
  (pdf-view-reset-slice)
  (setq pdf-view-display-size 1)
  (image-bob)
  (let* ((pos1 (posn-object-x-y
                (event-start (read-event "Click on the R of Richard"))))
         (size1 (pdf-view-image-size))
         (rpos1 (cons (/ (car pos1)
                         (float (car size1)))
                      (/ (cdr pos1)
                         (float (cdr size1))))))
    (pdf-view-set-slice-from-bounding-box)
    (read-event)
    (let* ((pos2 (posn-object-x-y
                  (event-start (read-event "Click on the same spot again"))))
           (size2 (pdf-view-image-size))
           (rpos2 (cons (/ (car pos2)
                           (float (car size2)))
                        (/ (cdr pos2)
                           (float (cdr size2))))))
      (read-event)
      (message "dx=%.2f dy=%.2f pos=[(%d, %d), (%d, %d)] size=[(%d, %d), (%d, %d)]"
               (abs (- (car rpos1) (car rpos2)))
               (abs (- (cdr rpos1) (cdr rpos2)))
               (car pos1) (cdr pos1)
               (car pos2) (cdr pos2)
               (car size1) (cdr size1)
               (car size2) (cdr size2)))))

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

From the (event-start (read-event "Click on the R of Richard")))) I gathered that I should run it on the test.pdf file I uploaded earlier. Here is the result of running pdf-view-fit-height-to-window followed by pdf-sync-test:

dx=0.20 dy=0.13 pos=[(181, 324), (32, 165)] size=[(711, 1006), (595, 841)]

And here is the result of pdf-view-fit-width-to-window followed by pdf-sync-test:

dx=0.20 dy=0.13 pos=[(265, 484), (32, 166)] size=[(1048, 1482), (595, 841)]

Both of course are the result of clicking on the R of Richard :).

from pdf-tools.

politza avatar politza commented on August 22, 2024

Yes, Richard. I added it in case it wasn't clear that it should be the
same text position.

Sorry, I messed up. Please do it again. The initial state (fit height
or width) doesn't matter. (Also, I'm just poking with a stick in a
hole, because I have no clue what's going on.)

(defun pdf-sync-test ()
  (interactive)
  (pdf-view-reset-slice)
  (setq pdf-view-display-size 1)
  (pdf-view-redisplay)
  (image-bob)
  (let* ((pos1 (posn-object-x-y
                (event-start (read-event "Click on the R of Richard"))))
         (size1 (pdf-view-image-size))
         (rpos1 (cons (/ (car pos1)
                         (float (car size1)))
                      (/ (cdr pos1)
                         (float (cdr size1))))))
    (pdf-view-set-slice-from-bounding-box)
    (read-event)
    (let* ((pos2 (posn-object-x-y
                  (event-start (read-event "Click on the same spot again"))))
           (size2 (pdf-view-image-size))
           (rpos2 (cons (/ (car pos2)
                           (float (car size2)))
                        (/ (cdr pos2)
                           (float (cdr size2))))))
      (read-event)
      (message "dx=%.2f dy=%.2f pos=[(%d, %d), (%d, %d)] size=[(%d, %d), (%d, %d)]"
               (abs (- (car rpos1) (car rpos2)))
               (abs (- (cdr rpos1) (cdr rpos2)))
               (car pos1) (cdr pos1)
               (car pos2) (cdr pos2)
               (car size1) (cdr size1)
               (car size2) (cdr size2)))))

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

Here it is

dx=0.20 dy=0.12 pos=[(151, 273), (32, 168)] size=[(595, 841), (595, 841)]

I got that it has to be on the same spot. In the first report I just did it for 2 files in 3 places in case you needed more data.

from pdf-tools.

politza avatar politza commented on August 22, 2024

I got that it has to be on the same spot.

Thought you might.

dx=0.20 dy=0.12 pos=[(151, 273), (32, 168)] size=[(595, 841), (595, 841)]

These
tuple should be equal ---^----------^

At least they are in my Emacs. This looks to me like in yours posn-object-x-y does not respect the image's slice, while in mine it does. Maybe they changed it upstream ? Though, I can't find anything recent. What Emacs version are you running ?

Maybe I'm missing something obvious. I'll give it another shot later this week.

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

Emacs version: 24.4.1

BTW I just noticed pdf-tools on MELPA. If I wanted to install it from there should I remove the manually installed package first or is it safe to just update? And what about restarting emacs? Also, the homepage variable for pdf-tools in MELPA is currently nil.

from pdf-tools.

politza avatar politza commented on August 22, 2024

Updating should work, though the variable pdf-info-epdfinfo-program will probably point to the wrong executable.

from pdf-tools.

politza avatar politza commented on August 22, 2024

What is the homepage variable ?

Sorry, I don't know how to fix this. It looks to me like posn-object-x-y ignores the image's slice, when it shouldn't.

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

In paradox-list-packages I can hit v to visit the homepage of the package. It was not set on your package however it is set now. I might have looked at the wrong line, i.e. the manually installed one and not the MELPA provided one.

No worries. I'll just reset the slice before jumping to tex. It is only really annoying when there are floats that are far away in pdf from their tex position.

I have one more question (maybe I should open a new issue for this if so let me know). Is this a plausible scenario:

  1. I do isearch-forward in the pdf,
  2. I find what I'm looking for and press some key, say C-c
  3. I'm taken to the tex file to a place corresponding to what was currently highlighted search match.

from pdf-tools.

politza avatar politza commented on August 22, 2024

Try this as a workaround:

--- a/lisp/pdf-sync.el
+++ b/lisp/pdf-sync.el
@@ -145,7 +145,7 @@ with AUCTeX."
 Returns a list \(SOURCE LINE COLUMN\)."

   (pdf-util-assert-pdf-window)
-  (let ((size (pdf-view-image-size))
+  (let ((size (pdf-view-image-size t))
         (page (pdf-view-current-page)))
     (setq x (/ x (float (car size)))
           y (/ y (float (cdr size))))

The variable pdf-isearch-current-match contains the image-edges of,well, the current match.

from pdf-tools.

szozda avatar szozda commented on August 22, 2024

If the diff in your last message was supposed to help with going to a proper line in tex when double-clicking on a pdf with restricted slice, then it didn't. I still have some randomness in going to tex from slice restricted view of a pdf.

Thanks for pointing me to the pdf-isearch-current-match variable. It worked like a charm. I have this in my init.el now

(defun pdf-sync-isearch-goto-tex ()
  "Go to the source corresponding to the current isearch match."
  (interactive)
    (pdf-util-assert-pdf-window)
    (unless pdf-isearch-current-match
      (error "No recent search"))

    (let ((left  (car   pdf-isearch-current-match))
      (top   (nth 1 pdf-isearch-current-match))
      (right (nth 2 pdf-isearch-current-match))
      (bot   (nth 3 pdf-isearch-current-match)))
      (pdf-sync-goto-tex (/ (+ left right) 2)
             (/ (+ top bot) 2))))

(define-key pdf-view-mode-map (kbd "C-c C-g") 'pdf-sync-isearch-goto-tex)

from pdf-tools.

politza avatar politza commented on August 22, 2024

This seems to have resolved itself, or noone else has this problem.

from pdf-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.