Forum moved here!

Home / Inverse search not performed for VS code.exe

David

Hello!
Recently I couldn’t get back through SumatraPDF to VScode. I found that inverse search didn’t work, but forward search still did.
The inverse search is also valid before this, but will not be valid after VScode updates around November 10th. I didn’t change any configuration, it came to a sudden failure.

Here is my option settings in SumatraPDF:

“D:\Code\VS code\Microsoft VS Code\Code.exe” “D:\Code\VS code\Microsoft VS Code\resources\app\out\cli.js” -g “%f”:"%l"

And the settings in VScode are:

“latex-workshop.view.pdf.viewer”: “external”,
“latex-workshop.view.pdf.external.viewer.command”: “D:/Code/SumatraPDF/SumatraPDF.exe”,
“latex-workshop.view.pdf.external.viewer.args”: [
“%PDF%”
],
“latex-workshop.view.pdf.external.synctex.command”: “D:/Code/SumatraPDF/SumatraPDF.exe”,
“latex-workshop.view.pdf.external.synctex.args”: [
“-forward-search”,
“%TEX%”,
“%LINE%”,
“-reuse-instance”,
“-inverse-search”,
““D:/Code/VS code/Microsoft VS Code/Code.exe” “D:/Code/VS code/Microsoft VS Code/resources/app/out/cli.js” -g “%f”:”%l"",
“%PDF%”,
],

I would appreciate it if you could provide a solution. Thanks a lot.

David

When I double click the PDF file, nothing happens and there is no warning. I tried to Google the results, but there was no solution can help me. :confounded:

GitHubRulesOK

those are not normal it is unusual to include a JS file it would normally be a .tex (which is the %f).

“-reuse-instance”,
should be
ReuseInstance = true
in SumatraPDF-settings.txt

““D:/Code/VS code/Microsoft VS Code/Code.exe” “D:/Code/VS code/Microsoft VS Code/resources/app/out/cli.js” -g “%f”:”%l"",

Should also be a setting ONCE in SumatraPDF-settings.txt it can be done ONCE via CLI but should not be repeated every single call it can cause problems if its repeated time after time. It would normally look like

InverseSearchCmdLine = "D:/Code/VS code/Microsoft VS Code/Code.exe"  -g "%f":%l
EnableTeXEnhancements = true

NOTE
InverseSearchCmdLine = "D:/Code/VS code/Microsoft VS Code/Code.exe" -g "%f:%l" should also work
however see also

The main reasons it wont work are that exe call is not correct OR the pdf does not see the current correct synctex file alongside the .pdf, which can happen if the PDF compilation did not complete correctly

David

Thanks for your apply.
I have modified the code as what you said.
But the inverse search still doesn’t work. When I double click the PDF, nothing happends.
(The forward search still work when I use “ctrl” + “alt” + “J”).


I wonder if you have a more detailed solution.
Thanks again!

Here is SumatraPDF-settings.txt

MainWindowBackground = #80fff200
EscToExit = false
ReuseInstance = true
UseSysColors = false
RestoreSession = true
TabWidth = 300

FixedPageUI [
	TextColor = #000000
	BackgroundColor = #ffffff
	SelectionColor = #f5fc0c
	WindowMargin = 2 4 2 4
	PageSpacing = 4 4
	HideScrollbars = false
]
EbookUI [
	FontName = Georgia
	FontSize = 12.5
	TextColor = #5f4b32
	BackgroundColor = #fbf0d9
	UseFixedPageUI = false
]
ComicBookUI [
	WindowMargin = 0 0 0 0
	PageSpacing = 4 4
	CbxMangaMode = false
]
ChmUI [
	UseFixedPageUI = false
]
ExternalViewers [
]
ShowMenubar = true
ReloadModifiedDocuments = true
FullPathInTitle = false
ZoomLevels = 8.33 12.5 18 25 33.33 50 66.67 75 100 125 150 200 300 400 600 800 1000 1200 1600 2000 2400 3200 4800 6400
ZoomIncrement = 0

PrinterDefaults [
	PrintScale = shrink
]
ForwardSearch [
	HighlightOffset = 0
	HighlightWidth = 15
	HighlightColor = #6581ff
	HighlightPermanent = false
]
Annotations [
	HighlightColor = #ffff00
]
CustomScreenDPI = 0

RememberStatePerDocument = true
UiLanguage = cn
ShowToolbar = true
ShowFavorites = false
AssociateSilently = false
CheckForUpdates = false
RememberOpenedFiles = true
InverseSearchCmdLine = "D:\Code\VS code\Microsoft VS Code\Code.exe"  -g "%f":%l
EnableTeXEnhancements = true
DefaultDisplayMode = single page
DefaultZoom = fit page
WindowState = 1
WindowPos = 1488 -12 1524 1954
ShowToc = false
SidebarDx = 746
TocDy = 0
TreeFontSize = 0
ShowStartPage = true
UseTabs = true

Here is settings.json for VS code

    "latex-workshop.view.pdf.viewer": "external",  
    "latex-workshop.view.pdf.external.viewer.command": "D:/Code/SumatraPDF/SumatraPDF.exe", 
    "latex-workshop.view.pdf.external.viewer.args": [
        "%PDF%"
    ],
    "latex-workshop.view.pdf.external.synctex.command": "D:/Code/SumatraPDF/SumatraPDF.exe",
   "latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "%PDF%",
  ],
David

I have found a strange solution:
If I open VScode and SumatraPDF(doestn’t from VScode), the inverse search works perfectly.

But if I open SumatraPDF from VScode (use “ctrl” + “alt” + “v”), the inverse search can’t work.

The thing that confused me the most was that I could do reverse search in this way before, but now it’s not possible

GitHubRulesOK

There are a few reasons it may not be working in such an odd way you describe

Is it the same type of version e.g. are they both 32bit or both 64bit as a crossed mix of one of each can have problems

Take a pdf and synctex that are known to work from https://github.com/GitHubRulesOK/MyNotes/raw/master/AppNotes/SumatraPDF/LATeX%20and%20Reverse-Search.zip unpack/right click to EXTRACT ALL into a fresh folder.

Only open Sync.pdf with SumatraPDF
Double Click the “1 ABC” and IF your reverse editor is correct it will call the editor to open Sync.tex at line 21 (in this case “wherever\LATeX and Reverse-Search\sync.tex:21”)
If that works then SumatraPDF and its settings are correct.

If it does not work then recheck the values in SumatraPDF-settings.txt

Try not to rewrite the tex or synctex by recompiling but make a copy of the tex file (call it test.tex) and see if in editor you can compile a similar synctex that behaves to and fro between the editor and SumatraPDF

David

Thank you for replying to me again.Both my computer and sumatraPDF are 64bit.

And I followed the steps you provided. Inverse search does work perfectly.

Only open Sync.pdf with SumatraPDF
Double Click the “1 ABC” and IF your reverse editor is correct it will call the editor to open Sync.tex at line 21 (in this case “wherever\LATeX and Reverse-Search\sync.tex:21”)

But when I open Sync.tex in Visual Studio code (I don’t run the .tex) → use the shortcut key “ctrl” + “alt” + “v” to open SumatraPDF → Double click the Sync.pdf → the inverse search still can’t work.

Anyway, I found a solution, even if it made me feel a little uncomfortable. I couldn’t open sumatraPDF from vscode, although it did work successfully a few days ago. I have to open the sumatraPDF independently. Maybe this is a bug caused by the vscode update, at least there are many people around me who have the same problem as me.

GitHubRulesOK

One way that calling SumatraPDF may behave different from an app or command line, is usually there are two sumatrapdf.exe s each with their own settings OR the calls are passing different settings locations to start in.
Can you be sure it not two different invocations, so starting SumatraPDF in both methods look where it wants to save settings>advanced options>save as (which folder is that?)

Normally calling SumatraPDF portable it will look for the settings in its own folder whereas an installed version will look in one of two users appdata folders. In either case you can force which settings it uses by adding a switch -appdata “location of folder” however I would only recommend that method if deliberately trying to run multiple profiles.

If running two copies the reverse call needs to be identical in both.

David

The save address for both methods is

C:\Users\CloudZ\AppData\Local\SumatraPDF

In fact, the SumatraPDF advance options are the same for both methods. And I didn’t have a portable version of SumatraPDF installed. The SumatraPDF version I am using is 3.3.3 64-bit.

I have also tried to uninstall SumatraPDF and reinstall it OR delete SumatraPDF-settings.txt and rewrite it. I also tried to uninstall VScode. But none of those worked.

GitHubRulesOK

ODD
so there is a common SumatraPDF which works on its own as it should, but when called via vscode something is either missing or added, but not directly changing the return value !
The best I can think of is to entrap the call by pointing the vscode call to a substitute for SumatraPDF that shows all the calling arguments.

Normally I use a small surrogate.exe that pops up a message box with all the arguments However if the pdf is opening that may not differ from what is expected and the missing link is the synctex is malformed which would be down to the pdflatex or similar compiler call (remember the sample has a known good pairing)

I think the problem must be the synctex building by latex and the proof would be to run a compile to trigger SumatraPDF, double click to test its NOT working with the fresh pdf file but use SumatraPDF file open the test/sample sync.pdf and if its synctex was not changed it should with a double click, open the sync.tex file thus its not VScode (on its own) or SumatraPDF failing it is the synctex (or synctex.gz) file that should have been constructed by LaTeX alongside your new pdf, that is missing or faulty.

David

Thank you very much for your reply. I’m sorry to bother you for so long.

When I open SumatraPDF separately, I can inverse search on any compiled PDF file. Even the sync.pdf you provide can also be inverse-searched (whether I compile it or not).

But if I open SumatraPDF from VS code, no matter what file, the inverse search is invalid.

octave

I have meet the same problem and solved it. Hope it can help.

  1. Downgrade the VScode to 1.61, because 1.62 not work.
  2. The related settings can be found in the Github of LaTeX-Workshop.
GitHubRulesOK

Thanks for the info
The version comment makes that a possibility as to part of the issue
However I see that the suggestion is that latex workshop is acting as middleman thus its the need to go back via synctex calling workshop rather than vscode.exe direct that seems to be the root cause

David

Thank you for helping me. The method you provided successfully solved my problem. When I downgrade the VS code to 1.61.2, my problem was completely disappear. The inverse search works whether I open sumatraPDF from VScode or not.


I’m not a programming major myself, so I don’t really understand how VScode works. I don’t know what VScode brings to synctex with this update (from 1.61 to 1.62). But downgrading vscode’s version did solve my problem. But there’s one more thing,

When I open SumatraPDF from VS code, inverse search does not seem to work in this setting.But when I changed it to the following Settings, the inverse search worked successfully.

InverseSearchCmdLine = "D:\Code\VS code\Microsoft VS Code\Code.exe" "D:\Code\VS code\Microsoft VS Code\resources\app\out\cli.js"  -g "%f":"%l"

Although the VScode update has changed almost nothing for me, I still want to know when should I update the VScode version.
At any rate, the problem has been solved, thank you for all the answers you have given me these days.

GitHubRulesOK

That’s the the newer bit I personally dont understand VScode called from SumatraPDF works well without it However it seems to be an additional requirement for enabling VScode to return whence it came from.

My comment still holds true, try not to -inverse-search in vscode settings by simply include ONCE in SumatraPDF-settings.txt as you are showing.

-forward-search and a filename should be ALL that SumatraPDF needs on each call

David

You are right. When I removed the following code from vscode, the inverse search still worked fine.

   "-reuse-instance",
   "-inverse-search",
   "code \"D:\\Code\\VS code\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"",
David

According to the author of LaTeX Workshop, the issue is mostly related to a change in VSCode.

GitHubRulesOK

David thanks for the assistance
so my understanding is the reverse command can be one of two routes (not both?)

without escape syntax or full path

"Microsoft VS Code\code.exe" -g "%f:%l"
or
"Microsoft VS Code\resources\app\out\cli.js" -r -g "%f:%l"

syehoonkim

Dear All,
I’ve found the solution.
It looks that “code.exe” doesn’t support cli arguments.
The solution is using “code.cmd” instead of “code.exe”,
In detail, I changed the inverse search command part in “settings.json” like as follows:
“code.cmd -r -g “%f:%l””,
Hope this helps you.
Thank you.

DigNative

Thank you for the hint!

However, doing so was opening a command window every time for me.

The solution which worked for me is the following (note the --ms-enable-electron-run-as-node as additional argument):

    "latex-workshop.view.pdf.viewer": "external",
    "latex-workshop.view.pdf.external.viewer.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe",
    "latex-workshop.view.pdf.external.viewer.args": [
        "-forward-search",
        "%TEX%",
        "%LINE%",
        "-reuse-instance",
        "-inverse-search",
        "\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"C:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" --ms-enable-electron-run-as-node -r -g \"%f:%l\"",
        "%PDF%"
    ],
    "latex-workshop.view.pdf.external.synctex.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe",
    "latex-workshop.view.pdf.external.synctex.args": [
        "-forward-search",
        "%TEX%",
        "%LINE%",
        "-reuse-instance",
        "-inverse-search",
        "\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"C:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" --ms-enable-electron-run-as-node -r -g \"%f:%l\"",
        "%PDF%"
    ],