James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.55k stars 522 forks source link

SyncTex forward indicator not at the right place in web brower #4168

Closed pyk1998 closed 6 months ago

pyk1998 commented 6 months ago

Please fill the following fields with a star (*) and provide as much related information as possible.

Pre-checks*

Please change the following [ ] to [x] for confirmation.

  • [x] The issue has not been reported in this repository.
  • [x] The issue remains after disabling all other extensions and restarting Visual Studio Code.
  • [x] The FAQ cannot address the issue.
  • [x] The issue is not related to compiling a document, or the document can be successfully compiled in the OS terminal but not in Visual Studio Code with this extension.

Environment*

Please write exact version numbers instead of descriptors such as latest.

  • Operating System: Windows 10
  • Visual Studio Code Version: 1.86.2
  • LaTeX Workshop Version: 9.18.2
  • TeX Distribution Version: TeX Live 2021

Please list the environment and version number if you are using VSCodium, Snap or Flatpack versions of Visual Studio Code, and/or Visual Studio Code Remote Containers/SSH/WSL.

  • None

The Issue*

Please briefly describe the issue you come across.

  • The synctex forward indicator shows a random location of the sentence in the web browser.

Reproduction Steps

Please list out the steps to reproduce your bug. Include relevant environmental variables or any other configuration.

  1. select a sentence
  2. select "SyncTex from cursor"
  3. View the location of the indicator in the web browser

Expected Behavior

What were you expecting to see? Include any relevant examples or documentation links.

Logs

LaTeX Workshop Output*

Please paste the whole log messages below, not parts of ones. The log should start with New log placeholder %WS1% registered.


[16:26:03.942][Logger] New log placeholder %WS1% registered for e:\OneDrive - ****\Work2\writing .
[16:26:03.942][Extension] Initializing LaTeX Workshop.
[16:26:04.014][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[16:26:04.064][Server] Creating LaTeX Workshop http and websocket server.
[16:26:04.105][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[16:26:04.129][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":52488} .
[16:26:04.166][Extension] Extension root: c:\Users\****\.vscode\extensions\james-yu.latex-workshop-9.18.2
[16:26:04.166][Extension] $PATH: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\texlive\2021\bin\win32;C:\Program Files\dotnet\;E:\ProgramData\Miniconda3;E:\ProgramData\Miniconda3\Library\bin;E:\ProgramData\Miniconda3\Scripts;C:\Program Files\Git\cmd;D:\Program Files\Meld\;C:\Users\****\AppData\Local\Microsoft\WindowsApps;;E:\Fiddler
[16:26:04.166][Extension] $SHELL: undefined
[16:26:04.166][Extension] $LANG: undefined
[16:26:04.167][Extension] $LC_ALL: undefined
[16:26:04.167][Extension] process.platform: win32
[16:26:04.167][Extension] process.arch: x64
[16:26:04.167][Extension] vscode.env.appName: Visual Studio Code
[16:26:04.167][Extension] vscode.env.remoteName: undefined
[16:26:04.167][Extension] vscode.env.uiKind: 1
[16:26:04.170][Config] latex-workshop.latex.autoClean.run: "onSucceeded" .
[16:26:04.170][Config] latex-workshop.latex.clean.method: "glob" .
[16:26:04.171][Config] latex-workshop.view.pdf.viewer: "browser" .
[16:26:04.173][Config] latex-workshop.view.pdf.external.viewer.command: "C:/Program Files/SumatraPDF/SumatraPDF.exe" .
[16:26:04.174][Config] latex-workshop.view.pdf.external.synctex.command: "C:/Program Files/SumatraPDF/SumatraPDF.exe" .
[16:26:04.174][Config] latex-workshop.view.pdf.external.synctex.args: ["-forward-search","%TEX%","%LINE%","%PDF%"] .
[16:26:04.180][Config] latex-workshop.hover.preview.newcommand.parseTeXFile.enabled: false .
[16:26:04.185][Config] latex-workshop.mathpreviewpanel.editorGroup: "above" .
[16:26:04.188][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]
[16:26:04.189][Root] Current workspace folders: ["file:///e:/OneDrive - ****/Work2/writing"]
[16:26:04.189][Extension] LaTeX Workshop initialized.
[16:26:04.190][Root] Found root file from active editor: %WS1%\presubmit_tvt.tex
[16:26:04.190][Root] Root file changed: from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.tex, langID latex . Refresh dependencies
[16:26:04.190][Event] ROOT_FILE_CHANGED: "e:\\OneDrive - ****\\Work2\\writing\\presubmit_tvt.tex"
[16:26:04.190][Cacher][Watcher] Reset.
[16:26:04.190][Cacher][Watcher] Reset.
[16:26:04.190][Cacher][Watcher] Reset.
[16:26:04.191][Cacher] Adding %WS1%\presubmit_tvt.tex .
[16:26:04.192][Cacher][Watcher] Watched %WS1%\presubmit_tvt.tex with a new watcher on %WS1% .
[16:26:04.192][Event] FILE_WATCHED: "e:\\OneDrive - ****\\Work2\\writing\\presubmit_tvt.tex"
[16:26:04.192][Cacher] Caching %WS1%\presubmit_tvt.tex .
[16:26:04.193][Cacher] Updated inputs of %WS1%\presubmit_tvt.tex .
[16:26:04.193][Cacher] Parse LaTeX AST: %WS1%\presubmit_tvt.tex .
[16:26:04.193][Event] ROOT_FILE_SEARCHED
[16:26:04.198][Server] valdOrigin is http://127.0.0.1:52488
[16:26:04.425][Cacher] Parsed LaTeX AST: %WS1%\presubmit_tvt.tex .
[16:26:04.425][File] Calling kpsewhich to resolve IEEEtran.cls .
[16:26:04.793][Cacher] Bib %WS1%\aaaa.bib from %WS1%\presubmit_tvt.tex .
[16:26:04.794][Intelli][Citation] Parsing .bib entries from %WS1%\aaaa.bib
[16:26:04.794][Intelli][Citation] Parse BibTeX AST from %WS1%\aaaa.bib .
[16:26:04.795][Cacher][Watcher] Watched %WS1%\aaaa.bib with a new watcher on %WS1% .
[16:26:04.795][Event] FILE_WATCHED: "e:\\OneDrive - ****\\Work2\\writing\\aaaa.bib"
[16:26:04.795][Cacher] Updated elements in 369.51 ms: %WS1%\presubmit_tvt.tex .
[16:26:04.795][Event] FILE_PARSED: "e:\\OneDrive -****\\Work2\\writing\\presubmit_tvt.tex"
[16:26:04.797][Structure] Structure force updated with 0 root sections for %WS1%\presubmit_tvt.tex .
[16:26:04.797][Event] STRUCTURE_UPDATED
[16:26:04.803][Intelli][Citation] Parsed 34 bib entries from %WS1%\aaaa.bib .
[16:26:04.803][Event] FILE_PARSED: "e:\\OneDrive - ****\\Work2\\writing\\aaaa.bib"
[16:26:04.805][Structure] Structure force updated with 7 root sections for %WS1%\presubmit_tvt.tex .
[16:26:04.805][Event] STRUCTURE_UPDATED
[16:28:04.548][Commander] SYNCTEX command invoked.
[16:28:04.549][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:04.550][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:04.582][Viewer] PDF is not opened: %WS1%\presubmit_tvt.pdf , try opening.
[16:28:04.584][Cacher][Watcher] Watched %WS1%\presubmit_tvt.pdf with a new watcher on %WS1% .
[16:28:04.584][Event] FILE_WATCHED: "e:\\OneDrive - ****\\Work2\\writing\\presubmit_tvt.pdf"
[16:28:04.584][Viewer] Serving PDF file at http://127.0.0.1:52488/viewer.html?file=pdf..ZmlsZSUzQSUyRiUyRiUyRmUlM0ElMkZPbmVEcml2ZSUyMC0lMjBzdGQudWVzdGMuZWR1LmNuJTJGV29yazIlMkZ3cml0aW5nJTJGcHJlc3VibWl0X3R2dC5wZGY
[16:28:04.586][Viewer] Open PDF viewer for file:///e:/OneDrive - ****/Work2/writing/presubmit_tvt.pdf
[16:28:04.586][Viewer] PDF cannot be opened: %WS1%\presubmit_tvt.pdf .
[16:28:04.718][Viewer] Handle data type: open
[16:28:04.759][Server] Preview PDF file: file:///e:/OneDrive - ****/Work2/writing/presubmit_tvt.pdf
[16:28:04.866][Viewer] Handle data type: loaded
[16:28:04.867][Event] VIEWER_PAGE_LOADED
[16:28:10.409][Commander] SYNCTEX command invoked.
[16:28:10.409][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:10.410][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:10.432][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:11.192][Commander] SYNCTEX command invoked.
[16:28:11.193][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:11.194][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:11.213][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:12.169][Commander] SYNCTEX command invoked.
[16:28:12.170][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:12.170][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:12.188][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:14.274][Commander] SYNCTEX command invoked.
[16:28:14.275][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:14.275][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:14.292][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:14.984][Commander] SYNCTEX command invoked.
[16:28:14.985][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:14.986][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:15.002][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:17.425][Commander] SYNCTEX command invoked.
[16:28:17.425][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:17.426][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:17.442][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:18.025][Commander] SYNCTEX command invoked.
[16:28:18.026][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:18.026][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:18.042][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:19.265][Commander] SYNCTEX command invoked.
[16:28:19.266][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:19.266][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:19.282][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:21.992][Commander] SYNCTEX command invoked.
[16:28:21.993][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:21.994][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:22.009][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:23.040][Commander] SYNCTEX command invoked.
[16:28:23.041][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:23.041][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:23.058][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:25.825][Commander] SYNCTEX command invoked.
[16:28:25.825][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:25.826][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:25.843][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:26.648][Commander] SYNCTEX command invoked.
[16:28:26.649][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:26.649][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:26.665][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:27.769][Commander] SYNCTEX command invoked.
[16:28:27.769][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:27.770][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:27.787][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:29.120][Commander] SYNCTEX command invoked.
[16:28:29.121][Locator] Forward from %WS1%\presubmit_tvt.tex to %WS1%\presubmit_tvt.pdf on line 163.
[16:28:29.121][SyncTeX] Parsing .synctex.gz %WS1%\presubmit_tvt.synctex.gz .
[16:28:29.137][Viewer] Try to synctex %WS1%\presubmit_tvt.pdf
[16:28:34.328][Event] STRUCTURE_UPDATED
[16:28:37.560][Event] STRUCTURE_UPDATED
[16:32:09.368][Commander] SHOWLOG command invoked: default

### Developer Tools Console
> _Please paste the whole log messages below, not parts of ones. This console logs can sometimes be very important in many cases. To access the log, click `Help` -> `Toggle Developer Tools` -> `Console`._

INFO [perf] Render performance baseline is 15ms



## Anything Else?
> _Add any other context about the problem below._
- The file is written with “ \documentclass[journal]{IEEEtran}”
James-Yu commented 6 months ago

This is a limit by SyncTeX. You can try synctex.synctexjs.enabled: false without guarantee.

James-Yu commented 6 months ago

#4186

James-Yu commented 6 months ago

Confirmed that this is a synctex issue. The offset values passed from synctex (either binary or .js) is incorrect. I'm afraid we can't do simple calibrations from the extension side.

pyk1998 commented 6 months ago

Confirmed that this is a synctex issue. The offset values passed from synctex (either binary or .js) is incorrect. I'm afraid we can't do simple calibrations from the extension side.

@James-Yu Thank you for the inspection. I've also checked the results from synctex binary, and it contains a list of records. Follow the code handling the records, it uses the last one directly.

https://github.com/James-Yu/LaTeX-Workshop/blob/a5f20a908985276142b0c19fee277aad91cfb14b/src/locate/synctex.ts#L35-L56

However, the synctex commandline says (synctex view help):

The result is a list of records. In general the first one is the most accurate but
it is the responsibility of the client to decide which one best fits the user needs.

I have tried to change to use the first return record, but it is also inaccurate.

Are there any ideas (or references) of how to do calibration? I'm planning to reference the implementation of other opensource externel PDF viewers (e.g. Sumatra PDF) handling the synctex results?

James-Yu commented 6 months ago

I don't think a precise calibration would be possible without significantly tinkering synctex itself. That is way beyond the scope of this extension, though.