sumatrapdfreader / sumatrapdf

SumatraPDF reader
http://www.sumatrapdfreader.org
GNU General Public License v3.0
13.54k stars 1.72k forks source link

Inverse searching in gVim (Windows) and accents in filenames #1140

Open MeisterLLD opened 5 years ago

MeisterLLD commented 5 years ago

Hello, Inverse searching forks fine on my setup (gVim, Windows) with the command "C:\Program Files (x86)\Vim\vim81\gvim.exe" -c ":RemoteOpen +%l %f" even when filenames have spaces or commas etc.

But for some reason, accented characters break it. For instance if I try it on a file called DM12 - Séries.tex, it launches gVim but on the file "DM12 - Sées.tex" so I guess when it tries to escape the é, some characters are eaten up. Is there a way to change the %f or something to escape more properly ?

Thank you,

GitHubRulesOK commented 5 years ago

Traditionally synctex the core engine of the forward / inverse index did not like spaces or punctuation that affected pathnames it was written initially for mac users and worked well on nix but often broke on windows LFNs rather than older short 8.3 syntax it was based on a limited range of acceptable latin characters and modern utf-8 names and directories may need some form of escape characters. It has been overhauled and updated and the file is built by the editor so a lot of the compatability rests there (some editors are better at parsing than others) SumatraPDF is using Version: 1.16 which was the most stable for a long time and is still the version given on the "official" page at http://itexmac.sourceforge.net/SyncTeX.html however it was "branched" by the author in 2017 and is now at version 1.21 It would require someone well versed in the changes to check if it can be pull requested into current SumatraPDF

The only "user" control is avoiding characters that are known to cause issues and when passing the filenames use "quoted paths" possibly relative to reduce the number of "bumps" in the path.

your call "C:\Program Files (x86)\Vim\vim81\gvim.exe" -c ":RemoteOpen +%l %f" is correct (the %f is inside "-" 's and without seeing the header of your .synctex file I am unsure if it is the editor or compiler at fault I tested using DM12 - Séries.tex compiled using the default editor (TeXworks provided by MiKTeX) and SumatraPDF correctly opened that file on an inverse search both with and without using "quotes" on a long path with only hyphens and no spaces Opening the header of the expanded synctex I see latex-examples-master\vector-graphics\test2\DM12 - Séries.tex and that is what sumatraPDF will use for the reverse search thus in my test it is functioning correctly with that accent (not to say other filenames may cause issues) however in my case é is not a problem.

GitHubRulesOK commented 5 years ago

@MeisterLLD I would like to get to the bottom of your issue since the only known reason for your problem is the possibility you are using DDE (a potential reason for lack of Unicode characters). How are you calling SumatraPDF with the filenames in gVim ? there are several potential ways this can be affected since a call to dvi may include -src-specials which is NOT needed for PDF which does require -synctex=1 (or simpler for testing -synctex=-1 since you can more easily open the non-compressed.synctex in notepad) There are various methods for calling the server and others have proposed switching to "C:\Program Files (x86)\Vim\vim80\gvim" --remote-silent +%l %f HOWEVER that is supposed to limit functionality to the main.tex file i.e. not access the \include{s} etc see https://github.com/vim-latex/vim-latex/issues/91

MeisterLLD commented 5 years ago

Thanks for your help. My call from gVim to Sumatra is let g:Tex_ViewRule_pdf = 'C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe -reuse-instance -inverse-search "\"C:\Program Files (x86)\Vim\vim81\gvim.exe\" -c \":RemoteOpen +\%l \%f\"" '

GitHubRulesOK commented 5 years ago

first off there is no longer a need to have such a complex call once inverse is in the SumatraPDF-settings.txt set it does not need to be reset on every view of the pdf (failures waiting to happen) In sumatraPDF advanced settings adjust the InverseSearchCmdLine entry once and forever (do not have any space or $ at the end of the line) back-up the .txt file just in-case it gets zeroed by a system failure. Check EnableTeXEnhancements = true go back to Settings> Options and check the inverse search entry is exactly in agreement (it is important there is no space at the very end of the line). The same for -reuse-instance it is not needed ONCE UseTabs = true and ReuseInstance = true NOW in the editor the call to SumatraPDF (if its on path is simply SumatraPDF such that the editor adds -forward-search current.tex line# main.pdf IF your path is not set correctly then the view rule simply needs to start with "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" in your example I do not see the -forward-search components

MeisterLLD commented 5 years ago

Yes, this is not for forward search but just to open the file with Sumatra and have inverse search working. Forward search call is carried by another plugin of gVim and works fine but I'd have to go through the plugin files to check. Nonetheless for the moment, only this simple call still does not work. I'll try to put all options in the Sumatra config file so that I have a lighter view rule and I'll try again.

GitHubRulesOK commented 5 years ago

If you find your entry for -synctex=1 change it to -synctex=-1 that will remove the.gz extension and you can open yourfile.synctex in notepad where looking at the first enries you should see the tex path\filename which seems to be the cause of your issues I found using your example filename it was correct (no missing characters after the accent)

MeisterLLD commented 5 years ago

I did that. The synctex file is ok, it shows indeed "....\DM12 - Séries.tex" at line 2. I simplified my view rule in gVim to only

let g:Tex_ViewRule_pdf = 'C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe'

but nothing changed. Viewing works fine, inverse searching works fine in files without accents in the filename, but in my case gVim tries to open "DM12 - Sées.tex"

By the way, if I open a completely different pdf file in Sumatra and double click, the inverse search works in gVim : gVim is opened from scratch with the correct tex file. So I guess this is all between Windows and Sumatra and this %f thing...

GitHubRulesOK commented 5 years ago

I have a bare gvim81 so need to ask which plugins you are using (I guess a form of vim-latex) and what customisation you are using such as fileformat (Dos?) and startup ~_vimrc (mine is empty)

MeisterLLD commented 5 years ago

Ok I found the problem ! It's that I forced UTF-8 encoding in my vimrc.

set encoding=utf-8 set fileencoding=utf-8

If I comment these it works just fine ! Trouble is : I always want to work with UTF-8 so I don't know what to do.

GitHubRulesOK commented 5 years ago

Ok that's great news for me then as it seems it is rooted in vim/vim-latex so I suggest you could raise an issue at https://github.com/vim-latex/vim-latex/issues and keep us posted on any solution

MeisterLLD commented 5 years ago

Weirdly enough replacing these lines by

set fileencodings=utf-8

works fine : files are opened in utf-8 and the correct file name is passed from Sumatra to gVim. I don't understand the difference but it works !

GitHubRulesOK commented 5 years ago

great for what its worth the call back from SumatraPDF in my case to gVim shows correctly without vim-latex

Error detected while processing command line: E492: Not an editor command: :RemoteOpen +8 ...\vector-graphics\test2\DM12 - Séries.tex

Note that SumatraPDF gave the editor the correct filename so it is down to the plugin translation

GitHubRulesOK commented 5 years ago

If you are going to raise an issue with vim-latex then leave this thread open until you have a response from them otherwise I suggest this issue is resolved as far as SumatraPDF is concerned.

MeisterLLD commented 5 years ago

Update : I think it all came from my Windows, sorry ! It appeared that I did not set UTF-8 as a locale in Windows 10. (Region settings : check "beta : use unicode UTF-8 ..."). Now that I did it, file name is passed in a correct way.

GitHubRulesOK commented 4 years ago

@kjk I suggest that since a solution was found in windows and vim settings this issue is no longer classed as the SumatraPDF use of older Synctex.

GitHubRulesOK commented 4 years ago

@kjk unclear why this one was reopened since it seemed to be down purely to a windows OS setting messing with the 3rd party SyncTeX code and updating that is covered by SyncTeX 2017 update (#841)