LaTeX-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
Developer Tools Console
How to reproduce
-
Get any .tex compiled to pdf with synctex enabled.
-
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%", ] }, -
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". -
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.
-
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 44 (10 by maintainers)
I can not start SumatraPDF by using
cmdand list the viewer as an arg. However, I found another workaround for this problem that I can callC:\Program Files\Microsoft VS Code\bin\code.cmdinstead ofC:\Program Files\Microsoft VS Code\Code.exefrom 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.cmdfor 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"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.
Well, I’ve fixed this by myself for the following settings:
-rflag here means “reusing last active window”. See here.I understand this is a messy task. I understand your philosophy as well. I am not complaining or anything, just really my honest opinion, that not having the option will become a problem in the long run. “ready-to-eat”, yes, it works right after installation. But does it still work great a few mins into actually using it for productive work? That’s when I ran into this issue.
ALso, “cmd.exe SumatraPDF.exe” doesn’t seem to work for me.
Oh Thanks. It worked strangely after I used Ctrl+Alt+J to open SumatraPDF instead of using the latex-workshop opening button.
@kman0 That works!!! I should have thought of this earlier. Thank you!!!
@James-Yu Am I correct to assume that inverse search without setting up a different PDF viewer like Sumatra will never be part of the roadmap here? It would be very nice but I don’t want to open a new issue if that’s infeasible. P.S. Thanks for this awesome extension!
Dear James,
Thanks for the reply. I respect your work and I like the extension, from the atom times till now. But, the internal pdf viewer does not work in the end. This is simply because VS Code doesn’t allow the pdf viewer tab to be placed in a separate window (
ctrl+k, odoesn’t work). In general, the font size of the pdf will NOT be suitable for reading in a tab size. There is no priori that the font size of your writing tab and the font size of the rendered pdf will happen to be the same for viewing. For example, if you write scientific paper, usually it’s two column, and the internal viewer is just too small.For this reason, I, and several of my colleges end up switching back to atom or st. Hope you can take this issue into consideration, and maybe come up with something ingenious. Thanks.