Dear Dr. Lervag and VimTex,
This is a continuation of https://github.com/lervag/vimtex/issues/175. I am using MacVim on Yosemite.
I am trying to get Skim to work with vimtex, and have not succeeded. The documentation seems contradictory to some of the bug fix above, at least it appears that way to a new vim-user like myself.
In the docs, it suggests:
(1) To paste the code in the .vimrc:
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '@line @pdf @tex'`
(2) And add the following to the .latexmkrc:
$pdflatex = 'pdflatex -synctex=1 %O %S';
When I do this, the command <leader>ll does not open anything (normally preview is opened).
When I remove the above and include the following as suggested in #175:
let g:vimtex_view_general_viewer = 'open'
let g:vimtex_view_general_options = '-a Skim'
Preview opens upon hitting <leader>ll. I have been trying a bunch of different combinations of the above without any luck. I like this vim-tex extension because of the exceptional documentation. The site hosting vim-latex-suite was down yesterday, too.
I got this answer for the latex-suite:
map ,ls :w<CR>:silent !make <CR>:silent !/Applications/Skim.app/Contents/SharedSupport/displayline -r <C-r>=line('.')<CR> %<.pdf %<CR><CR>
and this always works. The above is courtesy of:
https://skyuuka.wordpress.com/2014/07/11/setup-synctex-with-vim-pdflatex-and-skim/
http://molecularclouds.blogspot.sg/2012/01/latex-vim-skim.html
I guess I could map <leader>ll to a combination of the above and it's current status, but thought I would let you know about the obstacle.
Any suggestions on how to fix it would be appreciated. Even tangential comments about the framework of this bundle would be awesome because I want to learn more about vim and how it works.
Dear @cmarshak,
Since #175, I've made some updates and simplifications to the viewer code. In particular, I've implemented a placeholder scheme where @pdf, @tex, and @line indicates that the viewer should insert the current pdf file name, tex file name and line number (respectively).
I would like you to try a couple of things:
vimL
let g:vimtex_view_general_options = '-r @line @pdf @tex'`
.latexmkrc file, in particular remove these: $pdf_previewer and pdf_update_method.If things still are not working, please do the following:
latexmkrc file.<leader>ll (if things are not working, then the viewer should not open now).<leader>li.<leader>lo.This will probably generate a lot of information, but that will help me to locate the problem. Unfortunately, I don't use OSX, and so it is difficult to debug such problems for me.
Edit: Fixed code tags. Apologies to @pdf for unexpected notification.
Working great now! Thank you.
Just to recap because I am still learning the Plugin's "intended" workflow. Once I save using :w, latexmk is by default in continuous mode and will automatically compile.
Then, to view the pdf, I type <leader>lv and the pdf is shown in skim highlighting and pointing where the current cursor is in the .tex file.
When I type <leader>ll, either it compiled successfully and read latexmk compile: success (FILENAME.tex). OR it read latexmk compile: stopped (FILENAME.tex). Either way Skim did _not_ open. If this is not intended then, I can give the requested information.
So far this is awesome and I am really thankful!
For others wishing to use this Plugin, my ~/.latexmkrc file has:
$pdflatex = 'pdflatex -synctex=1 %O %S';
And my .vimrc has:
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
let g:vimtex_fold_enabled = 0 "So large files can open more easily
Your recap of the work flow seems mostly good. Except for one thing: <leader>ll will first start background compilation with latexmk. When the document has successfully compiled once, latexmk will then automatically open the previewer for us. Note that this is NOT done by vimtex directly, although vimtex does pass some settings to latexmk for it to choose the correct pdf viewer.
If the document is already compiling, then <leader>ll will stop the compilation.
So, to investigate why the viewer is not automatically opening, could you please provide the output from <leader>li and <leader>lo after opening a document and after starting the compilation?
Thank you for all your help, Dr. Lerv氓g.


Thanks. Could you repeat <leader>li _after_ you have started compilation? (The output provided in the last post was before you started compilation, which I see because pid : 0 says that the PID for the latexmk process is 0, i.e., not existing.
No problem. The <leader>lo looks the same.

I can't see exactly what is wrong, but I see that start appears twice in the pdf_previewer setting (from the <leader>lo output). Could you try again with the latest patch?
Also, could you open a terminal and try to open the pdf directly with the command
start /Applications/Skim.app/Contents/SharedSupport/displayline "test.pdf"
This should open the pdf file.
I tried both start and without it.

This should help! The last command induces the behavior when I type <leader>lv, though the 10 is the line number, but the pointer is 7 lines after begin{document} in the .tex file. Not sure how the order works.

I think the start specifier is something from perl (I do not know perl myself). Thus I think the error 17:22: syntax error ... is the correct error here.
Perhaps the -r option is strictly necessary. In that case, you should try to change your settings to
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline -r'
let g:vimtex_view_general_options = '@line @pdf @tex'
Actually this gives an error with Mac. Specifically:
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline -r'
let g:vimtex_view_general_options = '@line @pdf @tex'
Here is the error:

However, putting the -r command in the second line as before does not have difficulty loading the /.vimrc:
let g:vimtex_view_general_options = '-r @line @pdf @tex'
So, it's working the same as before: perfectly with <leader>lv and no output <leader>ll.
Ah, yes. Try instead
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
let g:vimtex_view_general_options_latexmk = '-r'
I believe this working the same as before. What should I expect to see? Each time I hit :w the .tex file compiles and takes me to the .pdf?
ADDED: I just wanted to say it's working really well. Each time I :w, it compiles and I can view thew new changes in the skim app. I have found it's best not to have to many macvim windows open since inverse search is usually called on the first macvim window available. Anyways, wanted to thank you again for your help and hope you have a great vacation!
Thanks, @cmarshak. I'm glad to hear things are (mostly) working!
I've found some documentation on Skim. Here the -r option is explained, and I see here that it does not make sense to pass -r to Skim when it is opened by latexmk. Thus the g:vimtex_..._latexmk = '-r' is not necessary. I was hoping that the -r option was necessary.
Let's take a step back. If you clear all instances of MacVim and Skim and use the recommended options from the documentation, then both <leader>ll and <leader>lv does not work. If you prepend -r to the recommended options, the <leader>lv does work, but <leader>ll still does not work.
That is, start from a clean desktop (no MacVim or Skim running), open a LaTeX file in MacVim, then issue <leader>ll. The expected output is now:
But the Skim viewer is not opening for you. Is that right?
Yes, both 1. and 2. are what occurs. And then I just press <leader>lv and it goes to the correct page and line, which is great.
Good. Let's ignore <leader>lv for a while (it works, anyway). What we want now is to find why the viewer does not open automatically after the first successful compilation.
Let's consider a minimal example:
% Save as mwe.tex
\documentclass{minimal}
\begin{document}
Hello World
\end{document}
And a minimal vimrc file:
" Save as minivimrc
set nocompatible
" Ensure the path below is correct on your end
let &rtp = '~/.vim/bundle/vimtex,' . &rtp
filetype plugin indent on
syntax enable
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
Now open with mvim -u minivimrc mwe.tex. This should give you the most minimal setup I can think of. What happens when you now do <leader>ll: Does the viewer open?
Sorry this took so long to respond... still doesn't open Skim, Dr. Lervag.
But like I said, I really appreciate this work so far. The fact that it compiles latex _and_ bibtex upon <leader>ll is a big bump up from TexShop.
Still happy to do tests if you want to try to get this sorted out.
Good, now we are sure that no other setting or plugin is relevant. Could you try the example again, and this time provide some output. That is, after you have started compilation for the above minimal working example with mvim -u minivimrc mwe.tex, could you please copy and paste the output of <leader>lo and <leader>li? The first will provide the output from latexmk directly, which might provide some explanation for why the viewer does not open. The latter will show the command that was actually used to start latexmk.
The next step will be to start latexmk manually from the command line with only the relevant options.
<leader>lo:

<leader>li

Thank you!
Thanks. Could you give the <ledaer>lo again but this time with the option g:vimtex_latexmk_options = -verbose set? I think the syntax error is the problem, but I do not immediately understand what the error is.
Also, I understand it is easy to paste the screenshots, but if you are able, it would be better for me if you could simply copy the text directly. That makes it easy for me to copy the text and experiment a little bit with the commands.
I've studied the output, and there is one thing I can't understand: In the cmd_latexmk_compile string, the relevant option is the following:
-e ''$pdf_previewer = "start ... "''
Here the keyword start should not be present. When I search the source to find where this comes from, I can not see it. I am wondering if you might not be on the latest version. What is the output of running git show -q on the command line inside the vimtex folder? I suspect you are on an older version.
I see now that I removed the "start" keyword in a commit where I referenced this issue. I assumed you would automatically update vimtex. Sorry. Could you please get the latest version of vimtex and try again. I am still interested in the <leader>lo output.
Sorry for the wait! Won't happen again.
Here is the output of leader<lo> with:
(1) The option g:vimtex_latexmk_options = '-verbose' added to the minivimrc
(2) The latest vimtex update.
Latexmk: This is Latexmk, John Collins, 30 March 2012, version: 4.31.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Viewing dvi
Rule 'latex': Rules & subrules not known to be previously run:
latex
Rule 'latex': The following rules & subrules became out-of-date:
'latex'
------------
Run number 1 of rule 'latex'
------------
------------
Running 'latex -recorder "mwe.tex"'
------------
Latexmk: applying rule 'latex'...
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, german-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabic, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danish, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnish, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, hungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, slovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/minimal.cls
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
) (./mwe.aux) [1] (./mwe.aux) )
Output written on mwe.dvi (1 page, 216 bytes).
Transcript written on mwe.log.
Latexmk: Log file says output to 'mwe.dvi'
Rule 'latex': File changes, etc:
Changed files, or newly in use since previous run(s):
'mwe.aux'
------------
Run number 2 of rule 'latex'
------------
------------
Running 'latex -recorder "mwe.tex"'
------------
Latexmk: applying rule 'latex'...
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, german-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabic, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danish, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnish, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, hungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, slovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/minimal.cls
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
) (./mwe.aux) [1] (./mwe.aux) )
Output written on mwe.dvi (1 page, 216 bytes).
Transcript written on mwe.log.
Latexmk: Log file says output to 'mwe.dvi'
Latexmk: I have not found a previewer that is already running.
So I will start it for 'mwe.dvi'
------------
------------
Running 'NONE "mwe.dvi"'
------------
Latexmk: Program not implemented for this version. Command line:
'NONE "mwe.dvi"'
------------
Latexmk: I could not run previewer.
-- Use the -f option to force complete processing.
Latexmk: All targets (mwe.dvi) are up-to-date
For rule 'view', running '&if_source( )' ...
Could you repeat this, but use the following? (I'm sorry, I forgot to add the -pdf part in my last post.)
g:vimtex_latexmk_options = '-pdf -verbose'
Latexmk: This is Latexmk, John Collins, 30 March 2012, version: 4.31.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Viewing dvi
Latexmk: I have not found a previewer that is already running.
So I will start it for 'mwe.dvi'
------------
------------
Running 'NONE "mwe.dvi"'
------------
Latexmk: Program not implemented for this version. Command line:
'NONE "mwe.dvi"'
------------
Latexmk: I could not run previewer.
-- Use the -f option to force complete processing.
Latexmk: All targets (mwe.dvi) are up-to-date
For rule 'view', running '&if_source( )' ...
Does this help?
I'm running into the same issue. Perhaps you've discovered this already, but I've captured the command line calls to Skim's displayline, and it seems that even though <Leader>lv calls
<...>/displayline <line> <full pdf path> <full tex path>
like it's supposed to, <Leader>ll only results in a command line of
<...>/displayline <relative pdf path>
and no other parameters. This results in the error
17:21: syntax error: A unknown token can鈥檛 go after this identifier. (-2740)`
I think the problem is that displayline can only be used in conjunction with a line number and a source TeX. Whereas other viewers support forward search and a regular open on the same command with different parameters, Skim doesn't. A fix would be to have a different setting for a viewer command, for the <Leader>lv command to use. Alternatively, setting g:vimtex_view_general_viewer to an executable shell script with the following contents:
#!/bin/sh
if [ "$#" -gt 1 ]; then
/Applications/Skim.app/Contents/SharedSupport/displayline $*
else
/usr/bin/osascript <<EOF
set theFile to POSIX file "$1" as alias
tell application "Skim"
activate
set theDocs to get documents whose path is (get POSIX path of theFile)
if (count of theDocs) > 0 then revert theDocs
open theFile
end tell
EOF
fi
will also take care of it without modifying the source. (This is what Skim recommends for allowing reloads.)
Sorry for taking so damn long to answer! First, @cmarshak, I think the following might work (based on the elucidations by @abspoel):
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
let g:vimtex_view_general_options_latexmk = '-r 1'
It seems the point here is that the .../displayline program requires more than one argument, i.e. the line number first, then the pdf file name, and then optionally the tex source file.
To expand upon @abspoel's idea, you could create an executable script similar to the one suggested by @abspoel. Then you could use the following options:
let g:vimtex_view_general_viewer = '/path/to/my/script'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
This would use the Osascript for the <leader>ll command and the displayline for the <leader>lv command. I hope one of the above ideas will work and solve the issue.
I like to keep the list of issues as short as possible. Since this has not had any activity, and since my last post is a proposed fix for the problem, I'll take the liberty to close the issue. Feel free to reopen if the issue persists.
@lervag Hello,
I'm running into a very similar problem when compiling after setting let g:vimtex_view_method = 'skim' in the .vimrc or ftplugin/tex.vim:
Latexmk: This is Latexmk, John Collins, 19 Jan. 2017, version: 4.52c.
Viewing pdf
Latexmk: I have not found a previewer that is already running.
So I will start it for 'master.pdf'
------------
------------
Running 'start /Applications/Skim.app/Contents/SharedSupport/displayline "master.pdf"'
------------
Latexmk: All targets (master.pdf) are up-to-date
For rule 'view', running '&if_source( )' ...
------------
Running '/Applications/VimR.app/Contents/Frameworks/SwiftNeoVim.framework/Versions/A/PlugIns/NeoVimServer --servername /var/folders/76/w433cm8d655cznw1qmd866gc0000gn/T/nvimERy9GM/0 --remote-expr "vimtex#compiler#callback(1)"'
------------
17:24:
syntax error: A unknown token can鈥檛 go after this identifier. (-2740)
This happens with and without my .latexmkrc. Curiously, I can use Skim via \lv just fine.
Do you have any suggestions what could be the problem here?
@tnull This issue is very old, so I would be glad if you could open a new issue with a full description and preferably a minimal example. Then it will be easier for me to understand the problem and perhaps find a solution. I hope that's OK.
I was trying to get this in order before my thesis, but was unsuccessful despite Dr. Lervag's very helpful discussions. I hope to revisit on the new issue thread.
@lervag
Dear Dr. Lerv氓g,
Just to give you some feedback, your suggestion in https://github.com/lervag/vimtex/issues/204#issuecomment-144699878 works perfectly for me (opens Skim on <leader>ll and points with a red dot).
Thank you for creating Vimtex!
I'm happy you like it and that it works! :)
However, it should also work with simply
let g:vimtex_view_method = 'skim'
This _should_ even be better, I think.
Thank you, this is better, since it's one line instead of three!
Most helpful comment
However, it should also work with simply
This _should_ even be better, I think.