Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synctex fails on windows #78

Closed
t-makaro opened this issue May 3, 2018 · 24 comments
Closed

Synctex fails on windows #78

t-makaro opened this issue May 3, 2018 · 24 comments

Comments

@t-makaro
Copy link

t-makaro commented May 3, 2018

Jupyterlab 0.32.1
jupyterlab_latex 0.3.0
MikTex 2.9.6500

It appears that it is searching for files in the wrong location. (note the 'uri' in the traceback)

From the server console after clicking "scroll pdf to cursor" on the .tex fail:

Uncaught exception GET /latex/synctex/gryoscope.pdf?page=1#x=0&y=0&1525389931568 (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/latex/synctex/gryoscope.pdf?page=1&x=0&y=0&1525389931568', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1543, in _execute
        result = yield result
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1107, in run
        yielded = self.gen.throw(*exc_info)
      File "E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 189, in get
        out = yield self.run_synctex(cmd)
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1107, in run
        yielded = self.gen.throw(*exc_info)
      File "E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 143, in run_synctex
        code, output = yield run_command(cmd)
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 296, in wrapper
        result = func(*args, **kwargs)
      File "E:\ProgramData\Anaconda3\lib\types.py", line 248, in wrapped
        coro = func(*args, **kwargs)
      File "E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_latex\util.py", line 25, in run_command_sync
        process = subprocess.run(cmd, stdout=subprocess.PIPE)
      File "E:\ProgramData\Anaconda3\lib\subprocess.py", line 403, in run
        with Popen(*popenargs, **kwargs) as process:
      File "E:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "E:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] The system cannot find the file specified

gyroscope.(tex/pdf/synctex.gz) are all in the same folder (at the base of the directories accessible given where I started the server)

@ian-r-rose
Copy link
Member

I am puzzled by the uri of the GET request: /latex/synctex/gryoscope.pdf?page=1#x=0&y=0&1525389931568.

This looks like a request for the reverse operation (scrolling the editor to the PDF location). Can you confirm that you are trying which direction of synchronization is failing?

@t-makaro
Copy link
Author

t-makaro commented May 4, 2018

You're right. That traceback was for "scroll editor to page". But I get an almost identical error for both operations (scroll pdf to cursor AND scroll editor to page).

I must have pulled the wrong traceback from the server console. I got lots of errors trying to figure this out.

For a "scroll pdf to cursor" I get:

Uncaught exception GET /latex/synctex/gryoscope.tex?line=84&column=202&1525452980826 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/latex/synctex/gryoscope.tex?line=84&column=202&1525452980826', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\web.py", line 1543, in _execute
        result = yield result
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1107, in run
        yielded = self.gen.throw(*exc_info)
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 189, in get
        out = yield self.run_synctex(cmd)
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1107, in run
        yielded = self.gen.throw(*exc_info)
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 143, in run_synctex
        code, output = yield run_command(cmd)
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 296, in wrapper
        result = func(*args, **kwargs)
      File "C:\Users\TMOko\Miniconda3\lib\types.py", line 248, in wrapped
        coro = func(*args, **kwargs)
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\jupyterlab_latex\util.py", line 25, in run_command_sync
        process = subprocess.run(cmd, stdout=subprocess.PIPE)
      File "C:\Users\TMOko\Miniconda3\lib\subprocess.py", line 403, in run
        with Popen(*popenargs, **kwargs) as process:
      File "C:\Users\TMOko\Miniconda3\lib\subprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "C:\Users\TMOko\Miniconda3\lib\subprocess.py", line 997, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] The system cannot find the file specified
[W 09:56:20.898 LabApp] Unhandled error
[E 09:56:20.900 LabApp] {
      "Referer": "http://localhost:8888/lab",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134",
      "Authorization": "token 44070f6dbc90faa963d917945790083527c7e461ebf1b9cd",
      "Content-Type": "application/json",
      "Accept": "*/*",
      "Accept-Language": "en-CA",
      "Accept-Encoding": "gzip, deflate",
      "Host": "localhost:8888",
      "Dnt": "1",
      "Connection": "Keep-Alive",
      "Cache-Control": "no-cache",
      "Cookie": "_xsrf=2|617ab23d|032ccab3f61936a9d95b51efd3880b5a|1525206032; username-localhost-8888=\"2|1:0|10:1525452980|23:username-localhost-8888|44:YzMwZDUwZjU0N2NlNDY2NDgwNTk2NTFiNGNlMzYyM2M=|3e3c267c42e4ceae12545ce9bf53409937499b42007e9d4bd3a2875c8a3a47bf\""
    }
[E 09:56:20.903 LabApp] 500 GET /latex/synctex/gryoscope.tex?line=84&column=202&1525452980826 (::1) 63.14ms referer=http://localhost:8888/lab

@ian-r-rose
Copy link
Member

And there is a .synctex.gz file being created? I am not sure whether MiKTeX is distributed with a synctex binary. Does running synctex in a terminal produce any output?

@t-makaro
Copy link
Author

t-makaro commented May 4, 2018

I deleted both the pdf and the synctex.gz. The synctex file is created with the pdf when I click "show LaTeX preview". MikTeX definitely has synctex support. I've used it for years in TeXStudio, but typing "synctex" into cmd is not recognized as a command.

@ian-r-rose
Copy link
Member

Okay, good to know that MikTeX supports synctex. It seems like the issue is that the synctex binary is not available in your path as sycntex. Might it be synctex.exe? If not can you do some poking around in your environment to see how to invoke it from the command line?

If it is available in your PATH, you can add it to your jupyter_notebook_config.py as c.LatexConfig.synctex_command.

@t-makaro
Copy link
Author

t-makaro commented May 4, 2018

Progress. Synctex consists of 2 parts. The part that makes the file is a part of latex. The part that reads the synctex file is not. It is usually embedded into a viewer like TeXStudio, but TeXLive offers a binary for synctex.

I've managed to install a synctex binary separately using chocolatey (like apt-get but for windows). More info

Synctex is now in my path.

I now get the following error:

 Uncaught exception GET /latex/synctex/gryoscope.pdf?page=1&x=0&y=0&1525465191661 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/latex/synctex/gryoscope.pdf?page=1&x=0&y=0&1525465191661', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\web.py", line 1543, in _execute
        result = yield result
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\tornado\gen.py", line 1113, in run
        yielded = self.gen.send(value)
      File "C:\Users\TMOko\Miniconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 190, in get
        out = json.dumps(parse_synctex_response(out.decode('utf-8'), pos))
    AttributeError: 'str' object has no attribute 'decode'
[W 13:19:51.778 LabApp] Unhandled error
[E 13:19:51.778 LabApp] {
      "Referer": "http://localhost:8888/lab",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134",
      "Authorization": "token 0b383feaf1e787e1fb18c2c68154851def7446090f5b7e2c",
      "Content-Type": "application/json",
      "Accept": "*/*",
      "Accept-Language": "en-CA",
      "Accept-Encoding": "gzip, deflate",
      "Host": "localhost:8888",
      "Dnt": "1",
      "Connection": "Keep-Alive",
      "Cache-Control": "no-cache",
      "Cookie": "_xsrf=2|617ab23d|032ccab3f61936a9d95b51efd3880b5a|1525206032; username-localhost-8888=\"2|1:0|10:1525465185|23:username-localhost-8888|44:NzI0YjZlYmQ4YmY4NDMxMDhhYmI4Y2NmMDE0NzhlODY=|62b6864c766e1d0910b73bb325e862e3ca29f9b5cd3fbccbb1f0e59f71f5ad46\""
    }
[E 13:19:51.778 LabApp] 500 GET /latex/synctex/gryoscope.pdf?page=1&x=0&y=0&1525465191661 (::1) 100.32ms referer=http://localhost:8888/lab

@ian-r-rose
Copy link
Member

Glad we are making progress! The string decoding error looks like a bug. Let me look into it. It may be as simple as not decoding the output.

By the way, if you have any notes on how to smooth out the process for Windows, I would love to be able to put them in the README.

@ian-r-rose
Copy link
Member

Okay, I have confirmed the bug, and will have a fix shortly. Thanks for helping with this @t-makaro!

@ian-r-rose
Copy link
Member

Hi @t-makaro, I just released v0.3.1 with a fix for the synctex error. Can you check whether this fixes your problem?

@ian-r-rose ian-r-rose reopened this May 4, 2018
@t-makaro
Copy link
Author

t-makaro commented May 4, 2018

Another error:

Uncaught exception GET /latex/synctex/gryoscope.tex?line=189&column=584&1525472333764 (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/latex/synctex/gryoscope.tex?line=189&column=584&1525472333764', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1543, in _execute
        result = yield result
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1099, in run
        value = future.result()
      File "E:\ProgramData\Anaconda3\lib\site-packages\tornado\gen.py", line 1113, in run
        yielded = self.gen.send(value)
      File "E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 190, in get
        out = json.dumps(parse_synctex_response(out, pos))
      File "E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab_latex\synctex.py", line 214, in parse_synctex_response
        raise Exception('Unable to parse SyncTeX response')
    Exception: Unable to parse SyncTeX response

@ian-r-rose
Copy link
Member

Okay, I can reproduce this on Windows, but not on Linux. It seems the issue is with the SyncTex being extremely picky about absolute vs relative paths in the file names passed to it, and some versions of synctex don't accept relative paths at all.

This discussion is helpful in working this out. It will be a pain, but I think it is fixable. I must say, SyncTeX's CLI is not very robust.

@t-makaro
Copy link
Author

t-makaro commented May 5, 2018

If it helps, the version that I get using chocolatey by

choco install synctex

is:

This is SyncTeX command line utility, version 1.5
usage: synctex <subcommand> [options] [args]
Synchronize TeXnology command-line client, version 1.21

It also appears that synctex is fairly new to the chocolatey repository.

@t-makaro
Copy link
Author

t-makaro commented Aug 10, 2018

This is relevant. It explains that synctex needs an absolute path, and why there is a strange /./ in the path. This gives 2 solutions. Attempt to replicate the paths by separating the absolute part and the relative part and join them with /./. Or, set some latex environment variables.

I'm too busy to attempt at the moment to implement either of these solutions (especially since I'm unfamiliar with the codebase), but it's worth it for someone to try.

@ian-r-rose
Copy link
Member

I'd like to take another crack at this, but I don't have easy access to a Windows setup. The last time I tried I wasn't able to get synctex working at all on Windows, with or without JupyterLab. If somebody has a set of instructions for how to get a working install of synctex from the windows shell, that would be helpful.

@t-makaro
Copy link
Author

t-makaro commented Aug 10, 2018

Easiest way to install synctex on windows is with chocolatey

To install chocolatey: From an administrative powershell run:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Then still from an admin shell run:

choco install synctex

Chocolatey will automatically shim synctex into the path.

In order to run chocolatey, you may need to set the execution policy with:

Set-ExecutionPolicy remotesigned -scope currentuser

Similarly MikTeX can be installed with:

choco install miktex

@ian-r-rose
Copy link
Member

I was able to install synctex, but not successfully run it on the command line. Do you have an example .tex-and-series-of-commands that works with it?

If we can come up with commands that work for Windows, we should be able to get it up and running. But last time I couldn't get it to produce useful results, even with messing around with /./ type paths. It was very frustrating!

@t-makaro
Copy link
Author

t-makaro commented Aug 10, 2018

Got it. Note, I use powershell for everything here (but it should work in cmd).

I have a test.tex file at C:\Users\TMOko\Downloads\scratch\test.tex with the contents

\documentclass{article}
 
\begin{document}
	Hello world
\end{document}

Then from the C:\Users\TMOko\Downloads\scratch\ directory to compile I run:

pdflatex -synctex=1 test.tex

Then I tried synctex with the following 3 commands:

relative path does not work:

> synctex view -i 3:1:test.tex -o test.pdf
This is SyncTeX command line utility, version 1.5
SyncTeX Warning: No tag for test.tex

absolute path does work:

> synctex view -i 3:1:C:\Users\TMOko\Downloads\scratch\test.tex -o test.pdf
This is SyncTeX command line utility, version 1.5
SyncTeX result begin
Output:test.pdf
Page:1
x:171.128296
y:134.764618
h:133.768356
v:134.764618
W:343.711060
H:6.918498
before:
offset:-1
middle:
after:
SyncTeX result end

absolute path with stupid \.\ does work too:

> synctex view -i 3:1:C:\Users\TMOko\Downloads\scratch\.\test.tex -o test.pdf
This is SyncTeX command line utility, version 1.5
SyncTeX result begin
Output:test.pdf
Page:1
x:171.128296
y:134.764618
h:133.768356
v:134.764618
W:343.711060
H:6.918498
before:
offset:-1
middle:
after:
SyncTeX result end

I tested using forward slashes as well. They work fine.

@ian-r-rose
Copy link
Member

Thanks for the information @t-makaro, that's very helpful. I'll see if I can reproduce that and maybe we can finally resolve the issue.

@t-makaro
Copy link
Author

t-makaro commented Aug 10, 2018

A little more testing. I decided to run synctex from one directory higher at C:\Users\TMOko\Downloads\. I just needed to modify the path to the output file.

> synctex view -i 3:1:C:\Users\.\TMOko\Downloads\scratch\test.tex -o .\scratch\.\test.pdf
This is SyncTeX command line utility, version 1.5
SyncTeX result begin
Output:.\scratch\.\test.pdf
Page:1
x:171.128296
y:134.764618
h:133.768356
v:134.764618
W:343.711060
H:6.918498
before:
offset:-1
middle:
after:
SyncTeX result end

Notice. I also through in \.\ all over the place. Works fine with and without.

@t-makaro
Copy link
Author

And one more because I didn't have an example of reverse synctex.

> synctex edit -o 1:133:702:test.pdf
This is SyncTeX command line utility, version 1.5
SyncTeX result begin
Output:test.pdf
Input:C:\Users\TMOko\Downloads\scratch\test.tex
Line:5
Column:-1
Offset:0
Context:
SyncTeX result end

@ian-r-rose
Copy link
Member

Huh, I just noticed that you didn't have the full path for the "synctex edit" case. Is it not necessary there? Does it still work if we include it?

@ian-r-rose
Copy link
Member

Hi @t-makaro, I've just published a new release of the python package (v0.4.0) which uses absolute paths for the SyncTeX requests. In my testing, this appears to resolve the issue. Let me know if that fixes things for you, and thanks for your patience!

@t-makaro
Copy link
Author

t-makaro commented Aug 20, 2018

Yes, synctex edit works with an absolute path.

It all works! Tested with jlab==0.33.11 + jlab-latex==0.4.0

@yyao22
Copy link

yyao22 commented Jun 8, 2023

I ran into the same error in m1 mac. I am using version 3.2.0 and jupyterlab 3.6.4.

[E 2023-06-08 15:46:23.014 ServerApp] SyncTex command 'synctex edit -o 1:0:0:/Dropbox/Apps/Overleaf/EF/ef_10152022.pdf' errored with code: 255 [E 2023-06-08 15:46:23.015 ServerApp] Uncaught exception GET /latex/synctex/Dropbox/Apps/Overleaf/EF/ef_10152022.pdf?page=1&x=0&y=0&1686253582973 (::1) HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/latex/synctex/Dropbox/Apps/Overleaf/EF/ef_10152022.pdf?page=1&x=0&y=0&1686253582973', version='HTTP/1.1', remote_ip='::1') Traceback (most recent call last): File "/Users/yuchiyao/opt/anaconda3/lib/python3.9/site-packages/tornado/web.py", line 1713, in _execute result = await result File "/Users/yuchiyao/opt/anaconda3/lib/python3.9/site-packages/tornado/gen.py", line 782, in run yielded = self.gen.send(value) File "/Users/yuchiyao/opt/anaconda3/lib/python3.9/site-packages/jupyterlab_latex/synctex.py", line 195, in get out = json.dumps(parse_synctex_response(out, pos)) File "/Users/yuchiyao/opt/anaconda3/lib/python3.9/site-packages/jupyterlab_latex/synctex.py", line 219, in parse_synctex_response raise Exception(f'Unable to parse SyncTeX response: {response}') Exception: Unable to parse SyncTeX response: This is SyncTeX command line utility, version 1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants