Forum moved here!

Home / How to set up inverse search with VS Code as .tex editor

largecats

I’m using VS Code as .tex editor and I’m trying to set up inverse search with SumatraPDF. My setting for SumatraPDF is “C:\Program Files\Microsoft VS Code\Code.exe" "%f:%l"

When I double click on a pdf file, nothing happens. I would like the cursor to jump to the line in my .tex file corresponding to where I clicked on the pdf file. What should I do? Any help is much appreciated!

GitHubRulesOK

@largecats Inverse search and forward search require a synctex file for the two way indexing of locations, if you have one in the right place then you can first test call with a common system app such as notepad i.e. try

Untitled

however that is unlikely to produce a noticeable call since I suspect you are not using latex and thus probably don’t have a corresponding synctex file (if you do have a suitable file you should get a copy of notepad with untitled and a message such as “the system cannot find the path specified”)

You may need a more direct calling method. This is most easily achieved using the “external viewers” method
as an example try

ExternalViewers [
[
CommandLine = “C:\Windows\System32\cmd.exe” /k echo “%1” page=%p
Name = External command
Filter = *.*
]
]

once you see the effects of editing the variables you can pass the “%1” and %p to your own command in place of cmd.exe or use an intermediate batch file

largecats

@GitHubRulesOK Thank you for the reply and suggestion! I’m in fact using latex and I’ve successfully set up SumatraPDF with Sublime Text 3 before using "C:\Program Files\Sublime Text3\sublime_text.exe" "%f:%l". notepad %f also works fine. But I can’t seem to get VS Code to do the same even with the ExternalViewers method…

GitHubRulesOK

@largecats
I note from Microsoft VS Code\Code.exe CLI reference
it mentions a -g parameter I don’t know how that works but it seems relevant

file:line[:character] Used with the -g argument. Name of a file to open at the specified line and optional character position. You can specify multiple files in this manner, but you must use the -g argument (once) before using the file:line[:character] specifier.

[/quote]

largecats

@GitHubRulesOK Thank you! I will try and post the solution if it works :slight_smile:

LzyP4nd4

This worked for me :
“PathTOVSCode” -g %f:%l

See doc:
https://code.visualstudio.com/docs/editor/command-line