How to change the default PDF viewer to open an editor such as VS code

In Windows OS, it is possible to open a LaTeX-generated PDF file with TeXworks and when you press ctrl+click on the PDF file TeXworks editor is opened. I was wondering how we can make Visual Studio Code the default editor such that ctrl+click on the PDF file will open vscode instead. I think this question which tries to set WinEdt as the default editor is relevant, but I don't know how to set vscode as the opening editor.

user170109 asked Mar 18, 2019 at 7:31 135 1 1 silver badge 5 5 bronze badges Use another PDF viewer like sumatra and specify vscode for backward synchronization (synctex). Commented Mar 18, 2019 at 7:33 @TeXnician I have also asked a question here to see how vscode can be set to work with sumatra PDF. Commented Mar 18, 2019 at 7:38

1 Answer 1

Most PDF viewers that are aware of SyncTeX can be easily configured to reverse (inverse) sync. Such viewers are Evince, Okular, SumatraPDF etc. Some editors (not all) can be started from the PDF if the SyncTeX file is present alongside the PDF (one reason not to delete them) when the inverse command is triggered (double click for SumatraPDF or shift left click for Okular, and Control click for some others, it depends on the viewer).

For collaborative working it is possible to embed the SyncTeX file inside the portfolio PDF and SumatraPDF can readily extract it to the pdf folder in order to trigger any users editor not just the one used to compile. (NOTE compile would require 1 pass to build synctex then a second method to embed it, but that's a separate workflow question beyond this guide)

You asked elsewhere how you could to do that using SumatraPDF and for your VScode desire you will find in this guide the following command entry but you need to use the location of your VS code editor in place of \editor\code NOTE the last character is lower case L

Okular tends to share the same combination of tokens as SumatraPDF but Evince and others may be different.

Microsoft VS Code = "\editor\Code.exe" -g %f:%l 

you may need to try "%f:%l" or "%f":%l or even other escape chars depending on system

Why some other editors won't start that way easily is that they may require a "server" daemon to be active and running first in order to catch the tex file open command. Such examples that need some prior trigger are LyX (uses a pipe) TeXlipse (requires java service) several others that use DDE (TeXnicCenter) or d-bus etc.