Home > Net >  VSCode LaTeX pdf preview line finder?
VSCode LaTeX pdf preview line finder?

Time:12-03

I am switching over from Overleaf to VSCode for offline LaTeX.

Is there an extensions that lets you click on the pdf preview and highlights the line you clicked on in the .tex file? (just like the Overleaf feature)

CodePudding user response:

LaTex Workshop can do this.
SyncTex is explained here.

Note: you need Latex (e.g. MikTex) installed separatelly. It does not come with the extension.

CodePudding user response:

The Function is called inverse search (a.k.a. reverse search) you do not need an extension it is a PDF viewer function. For that matter you dont even need a TeX system as you could handball or program a suitable PDF(sync)TeX file without LaTeX but have only done that as a PoC, that its possible.

So how does that work?

PDF viewers that are PDF(sync)TeX aware can be primed in a PDF file by double click (easy) or some other key combination (often two handed shift key plus mouse). If the viewer spots there is an attendant pdfsync or synctex file alongside the compiled PDF they will launch a related call-back to the pre-configured text editor. That configuration only needs to be done ONCE not (as commonly done) every time :-( For example, in latex-workshop.view.pdf.external.synctex.args these two lines should NOT be needed if configured correctly

    "-reuse-instance",
    "-inverse-search",

So, for example, If I have output.pdf and output.synctex and input.txt A double click in SumatraPDF will look at the synctex block entry for that area in the PDF which might be page 42 line 42 and will launch MS notepad to open the attendant text file (NOTE it can be any suitably compiled source file not just .tex) with those requests.

Clearly MS Notepad would open the text file then grumble there is no such reference as it has no concept of pages or line numbers!! blithely would most likely try to open file 42.

However, if it was VSCode with LaTeX extension it could understand line numbers per page.

So standalone viewers that are synctex aware include Acrobat (Portable for Linux/Windows=R9), Linux/Windows Evince, Win? Foxit, GNOME/Document viewer, Mac LivePDF, Linux/Windows Okular, Mac Skim, Win/Wine SumatraPDF, Win? Tracker/X-change, plus unknown others.

  • Related