lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.5k stars 389 forks source link

jump to line number from PDF? #3012

Closed brotherJ4mes closed 1 week ago

brotherJ4mes commented 2 weeks ago

This is probably a stretch ask (so no worries if it's not feasible) but I'm wondering if it might be possible to jump to a specific line in a tex file that corresponds to the numbered line in the PDF output.

Use case: upon reviewing manuscripts, it seems like feedback is often provided like: "line 452: awkward sentence, consider rewording"

Where the line number comes from the PDF output. I can fairly easily navigate to the line in MuPDF by searching for that string (assuming the PDF isn't full of random numbers in the text!) and then I can use the really great \lr feature to jump to the approximate location in vim that I'm viewing in MuPDF

This is a pretty great solution as is but it does involve an extra step so I was just curious if there was someway to jump to the PDF line number directly.

lervag commented 2 weeks ago

You know about synctex and reverse search? It does not work as well with MuPDF, but it should work well with several other viewers.

But if you want a tool that, given a different PDF than the one you are producing with LaTeX - e.g. a copy that someone else has modified by adding comments and whatnot, then no - I don't think what you want here is possible.

user202729 commented 1 week ago
  1. Actually I think synctex tool doesn't read the PDF file at all, all it needs is the pixel height/width coordinate.
  2. That said, it looks like \lr already work for @brotherJ4mes , so that is not an issue here.

So I don't think there's anything that can be done by vimtex directly here, you (@lervag ) can just close the issue.

(though it may be interesting for vimtex to somehow find where is the search highlight in mupdf and pass that to synctex… I doubt it's possible though.)

brotherJ4mes commented 1 week ago

Sorry for necroposting but I didn't have a chance to respond earlier and I hoped to at least clarify what I was looking for...

My question about jumping to a specific line number should be independent of the pdf viewer I believe. I was asking about jumping to the the line number in the PDF output (which is presumably handled by the latex compiler) when \linenumbers is used.

To elaborate on the use case:

  1. I use vimtex (or any tex compiler) to compile a pdf of a manuscript that has line numbers embedded in it.
  2. I send this pdf to some reviewers, co-authors, etc.
  3. They read the pdf and respond with "change such and such on line 452"
  4. [This part was the feature request:] Ideally, I'd like to be able to jump to line 452 directly from vim.
    this is line 452 in the pdf file that vimtex/latexmk produced, which is obviously different than line 452 in the tex file

(Right now, my workaround is to navigate to line 452 in a pdf viewer, which is a little awkward and involves searching for number strings, and then using \lr to jump to that approximate location within vim.)

It would definitely a big improvement to have vim jump directly to that line given the PDF line number but I understand that it may not be possible. (and if not, I'll totally shut up about this ;) ....I just wanted to explain to make sure I was understood in case it was easy to implement or perhaps already possible but something I had overlooked.)


As a sidenote, it seems like synctex is more focussed on mouse location in a pdf viewer but I did tinker with synctex on the command line to see if perhaps I could enter a bunch of PDF line numbers and output all the corrseponding tex line numbers.

I tried: synctex view -i 452:1:file.tex -o file.pdf
(I think this does the opposite of what I want, so then I looked at the edit subcommand which unfortunately doesn't have any sort of line number input)

Guessing if synctex can't access those PDF line numbers then vimtex can't either.

lervag commented 1 week ago

Sorry for necroposting but I didn't have a chance to respond earlier and I hoped to at least clarify what I was looking for...

No need to be sorry; I only closed it because I didn't see this leading to any necessary action. But closing the issue doesn't mean we can't continue the discussion.

My question about jumping to a specific line number should be independent of the pdf viewer I believe. I was asking about jumping to the the line number in the PDF output (which is presumably handled by the latex compiler) when \linenumbers is used. … It would definitely a big improvement to have vim jump directly to that line given the PDF line number but I understand that it may not be possible. (and if not, I'll totally shut up about this ;) ....I just wanted to explain to make sure I was understood in case it was easy to implement or perhaps already possible but something I had overlooked.)

Ah, I see. You would like something like :VimtexMoveToOutputLine 452. I don't really see any way to implement this, sorry. I don't think it is impossible, but it is surely hard and would likely require some hacks to pull off.

As a sidenote, it seems like synctex is more focussed on mouse location in a pdf viewer but I did tinker with synctex on the command line to see if perhaps I could enter a bunch of PDF line numbers and output all the corrseponding tex line numbers.

I tried: synctex view -i 452:1:file.tex -o file.pdf (I think this does the opposite of what I want, so then I looked at the edit subcommand which unfortunately doesn't have any sort of line number input)

Guessing if synctex can't access those PDF line numbers then vimtex can't either.

Precisely; the problem here is to figure out the position of these line numbers in a robust manner. And that's definitely hard. E.g., most documents don't even have these line numbers.

So I'm sorry to say that you will most likely have to live with the slightly less convenient workaround.

brotherJ4mes commented 1 week ago

No problem at all. Thanks for the quick response.

If I ever stumble upon a solution I'll let you know!

lervag commented 1 week ago

Great, and yes, please do!

user202729 commented 1 week ago

This is of course possible but may require some hooks into lineno package. I recommend asking for help on https://tex.stackexchange.com/ .