Repository: lervag/vimtex

Issue #176: Latexmk Crashes After Loading the Second File in a Multi-File LaTeX Project
Created: 2015-06-01T22:32:21Z
Once again, thank you for your hard work in the vimtex plugin! I have used it in the past several months to write many papers using LaTeX and vim. Recently, I upgraded vimtex using vim-plug and found that some of the basic features on which I rely no longer work correctly.
Before I go into the details about the problem that I am facing, I will share some of the configurations of the environments in which I have noticed concerns. Currently, I am running Ubuntu 14.04 LTS and I can reproduce the problems described in this issue both with Ubuntu's standard version of vim and a new version of vim that I built from source a few days ago.
Here is the version of vim provided by Ubuntu:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:40:46)
Garbage after option argument: "-version"
More info with: "vim -h"

Here are some more details about this version of vim:
:version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:40:46)
Included patches: 1-52

Here is the version of vim that I recently compiled:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled May 31 2015 17:09:42)
Garbage after option argument: "-version"
More info with: "vim -h"

Here are some more details about this version of vim:
:version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled May 31 2015 17:09:42)
Included patches: 1-729

I have also created a minimal .vimrc file; you will notice that it is only slightly different than the one that people commonly use when reporting issues about vimtex.
set nocompatible
filetype plugin indent on
syntax enable
set iskeyword+=:
let maplocalleader=","
let mapleader=","

call plug#begin('~/.vim/bundle')
Plug 'https://github.com/lervag/vimtex.git', {'for': 'tex'}
call plug#end()

let g:vimtex_fold_enabled = 0
let g:vimtex_quickfix_mode = 2
let g:vimtex_quickfix_open_on_warning = 1
let g:vimtex_toc_resize = 0
let g:vimtex_toc_hide_help = 1
let g:vimtex_indent_enabled = 1
let g:vimtex_latexmk_enabled = 1
let g:vimtex_latexmk_callback = 0
let g:vimtex_complete_recursive_bib = 0

By default, this version will call xdg-open and this will lead to the loading of evince. I also have a .latexmkrc file that I took from @lervag's GitHub repository of configuration files and enhanced slightly with other configurations that I found in the discussion of issues for vimtex.
$print_type = 'pdf';
$pdf_mode = 1;
$bibtex_use = 2;
push @generated_exts, "cb";
push @generated_exts, "cb2";
push @generated_exts, "spl";
push @generated_exts, "nav";
push @generated_exts, "snm";
push @generated_exts, "tdo";
push @generated_exts, "nmo";
push @generated_exts, "brf";
push @generated_exts, "nlg";
push @generated_exts, "nlo";
push @generated_exts, "nls";
push @generated_exts, "synctex.gz";
push @generated_exts, "tex.latexmain";
push @generated_exts, "run.xml";
$latex = 'latex --src-specials %O %S';
$pdflatex = 'pdflatex -file-line-error -synctex=1 -interaction=nonstopmode -shell-escape %O %S';

$new_viewer_always = 0;
$pdf_update_method = 2;
$pdf_update_signal = 'SIGHUP';

add_cus_dep('nlo', 'nls', 0, 'nlo2nls');
sub nlo2nls {
  system("makeindex $_[0].nlo -s nomencl.ist -o $_[0].nls -t $_[0].nlg" );
}

# vim: ft=perl

The vast majority of the LaTeX documents that I write are divided into multiple files. I followed the vimtex guidelines to add headers to the top of a subfile so that it is clear which file is the main file. To reproduce the fault that I am having on complex LaTeX documents, I have produced the following minimal working example.
First, there is a file that is called minimal.tex:
\documentclass{minimal}
\begin{document}
Hello world first page!
\newpage
Hello world second page!
\newpage
\input{sections/first.tex}
\end{document}

Then, there is the file called first.tex that is in the sections directory:
% vim: ft=tex
% !TEX root = minimal.tex

Hello world third page!!

I am going to write a lot of content now. Does this work?

Now, if I load the minimal.tex file into vim and press <leader>ll to start the compilation of the paper in latexmk I would see the following debugging output, as an example:
b:vimtex
  id : 0


g:vimtex#data[0] : minimal
  root : '/home/gkapfham/working/writing/minimal'
  aux : '/home/gkapfham/working/writing/minimal/minimal.aux'
  log : '/home/gkapfham/working/writing/minimal/minimal.log'
  out : '/home/gkapfham/working/writing/minimal/minimal.pdf'
  tex : '/home/gkapfham/working/writing/minimal/minimal.tex'
  tmp : '/tmp/vFC1lkf/1'
  pid : '13489'
  cmd_latexmk_compile : 'cd ''/home/gkapfham/working/writing/minimal'' && max_print_line=2000 latexmk -pdf -e ''$pdflatex =~ s/ / -file-line-error /''
-pvc -e ''$new_viewer_always = "0"'' -e ''$pdf_update_method = "0"'' -e ''$pdf_previewer = "start xdg-open "'' ''minimal.tex'' >/tmp/vFC1lkf/1 2>&1'
  base : 'minimal.tex'
  viewer
    init : function('4')
    view : function('5')
    latexmk_append_argument : function('6')

Now, if I go into the buffer that contains the first.tex file and press <leader>li to get the debugging information again, then I would produce this output:
b:vimtex
  id : 0


g:vimtex#data[0] : minimal
  pid : 0
  root : '/home/gkapfham/working/writing/minimal'
  aux : '/home/gkapfham/working/writing/minimal/minimal.aux'
  log : '/home/gkapfham/working/writing/minimal/minimal.log'
  out : '/home/gkapfham/working/writing/minimal/minimal.pdf'
  tex : '/home/gkapfham/working/writing/minimal/minimal.tex'
  tmp : '/tmp/vFC1lkf/1'
  cmd_latexmk_compile : 'cd ''/home/gkapfham/working/writing/minimal'' && max_print_line=2000 latexmk -pdf -e ''$pdflatex =~ s/ / -file-line-error /''
-pvc -e ''$new_viewer_always = "0"'' -e ''$pdf_update_method = "0"'' -e ''$pdf_previewer = "start xdg-open "'' ''minimal.tex'' >/tmp/vFC1lkf/1 2>&1'
  base : 'minimal.tex'
  viewer
    init : function('4')
    view : function('5')
    latexmk_append_argument : function('6')

As you can see, latexmk has crashed and updates to this file will not be seen in the PDF that has already been loaded in evince. Typing the <leader>lg command also confirms that latexmk is no longer running correctly.
If I try to restart background compilation by going back to the main file and repeating the above steps, I find that the compiler starts running correctly for the minimal working example. However, when I try all of these steps with larger LaTeX papers that contain many files and many pages, then I have to restart latexmk every time I enter a new file in the sections directory (I could not discover the reason why this behavior is different and decided that the aforementioned issues were important enough that I would go ahead and submit the issue now).
Again, I should stress that this behavior only appeared after a recent update to vimtex. Before that point, I have been able to successfully work on many papers that are structured in the same way as the minimal working example.
Can you please advise on what I need to do to ensure that vimtex starts to work correctly again?

Duplicate issue #159: latexmk started multiple times - does not close upon closing vim
Created: 2015-04-26T21:30:53Z
Dear lervag,
Me and also my colleagues experienced the problem that the perl latexmk does not close upon closing vim and in order not to create buggy behavior we have to kill those instances individually, since they interfere with each other. Sometimes even the pdfviewer does not work anymore as long as not all instances of latexmk are killed and pdflatex is run. Latexmk can be revoked after being killed with vimtex and the normal behavior is recovered.
maybe you have an idea how to fix this problem?
with best regards

Closing comment (2015-06-05T20:41:25Z): I suspect this problem might be related to #176, which I just solved. It seems I pushed a bug in February. Please let me know if the problem persists. In the meantime, I take the liberty of closing this issue.