SolvedLaTeX Workshop Synctex inverse search doesn't work half the time (and How I got forward search to work for SumatraPDF)

Description

In SumatraPDF, double clicking should initiate a inverse search, but it doesn't work, IF the SumatraPDF instance is fired up by VS Code. If the SumatraPDF is opened independently, backward search will work.

LaTeX Workshop Output
Nothing here.
Developer Tools Console
Nothing here.

How to reproduce

  1. Get any .tex compiled to pdf with synctex enabled.

  2. Put this in user settings. Use "external" as pdf viewer.

     "latex-workshop.view.pdf.external.synctex": {
     "command": "SumatraPDF",
     "args": [
       "-forward-search",
       "%TEX%",
       "%LINE%",
       "-reuse-instance",
       "-inverse-search",
       "\"code.exe\" -g \"%f:%l\"",
       "%PDF%",
     ]
     },
    
  3. In VS Code, use 'Synctex from cursor', the forward search works. Inverse search doesn't. In the fired up SumatraPDF, with double clicking, nothing happens.

    If you check the fired up SumatraPDF, in settings - Options - Set inverse search command-line you will see "code.exe" -g "%f:%l".

  4. However, if you fire up SumatraPDF independently, and put this into settings - Options - Set inverse search command-line

     "code.exe" -g "%f:%l"
    

    The inverse search actually works. This just let SumatraPDF to execute the commandline with 'goto` command to code.

  5. I don't understand why the SumatraPDF instance initiated by VS Code can't perform inverse search, but the independent ones can. I also notice that, the SumatraPDF instance fired up by VS Code will also exit, if you close VS Code. Are they connected somehow? How to get around this problem?

Thank you.

Expected behavior

Described above.

Actual behavior

Described above.

Additional Information

I have read previous external pdf viewer issues, and I do understand the frustration of dealing with them. Here I would like to contribute a little bit by getting SumatraPDF to work.

I am using win7, VS Code 1.23.1 zip. Updated LW.

Synctex forward search with SumatraPDF

The default setting in LW doesn't work for SumatraPDF. To enable SumatraPDF with forward synctex search, put this in the user-settings:

"latex-workshop.view.pdf.external.synctex": {
"command": "SumatraPDF",
"args": [
  "-forward-search",
  "%TEX%",
  "%LINE%",
  "-reuse-instance",
  "-inverse-search",
  "\"code.exe\" -g \"%f:%l\"",
  "%PDF%",
]
},

This is assuming SumatraPDF and VS Code are in the system PATH.

45 Answers

✔️Accepted Answer

Yes browser works indeed. My apologies.
However, still this is a maybe good work-around, and not a solution. People perfer dedicated viewer to browser for a range of different reasons. Right now it really hurts that, with SumatraPDF for example, one simply can't have inverse-search.

Other Answers:

I can not start SumatraPDF by using cmd and list the viewer as an arg.
However, I found another workaround for this problem that I can call C:\Program Files\Microsoft VS Code\bin\code.cmd instead of C:\Program Files\Microsoft VS Code\Code.exe from SumatraPDF. Everything works now, except a black window flash around when doing the inverse search.

@qcts33 Black window occurs if you use C:\Program Files\Microsoft VS Code\bin\code.cmd for invoking reverse sync. It can be very slow and is annoying as the black window blocks the screen.

The code.cmd just makes a call to code.exe which can be directly used in SumatraPDF to circumvent the black box. Based on where your vscode is installed, your inverse search setting in SumatraPDF should look something like
"C:\Program Files\Microsoft VS Code\Code.exe" "C:\Program Files\Microsoft VS Code\resources\app\out\cli.js" -g "%f":"%l"

Related Issues:

13
LaTeX Workshop LaTeX toolchain terminated with error
I had to completely restart VS Code (quit all instances) before it was able to find latexmk. ...
9
LaTeX Workshop Cannot compile .tex files on MacOS
Here's mine: The key is that a) the first recipe listed is used by default; b) the recipe used has t...
8
LaTeX Workshop Formatting failed error
@thedadams can u format ur code? (Not saving after formatting) Or u already solved it? It seems it's...
3
LaTeX Workshop Synctex inverse search doesn't work half the time (and How I got forward search to work for SumatraPDF)
Yes browser works indeed My apologies However still this is a maybe good work-around and not a solut...