A Second MuPDF Window Opens When Viewing a Location in a Subfile of a Multi-File LaTeX Project #178

Closed
gkapfham opened this Issue Jun 2, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@gkapfham

gkapfham commented Jun 2, 2015

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. Although I have tried a wide number of different configurations in an attempt to get MuPDF integration to work with vimtex, I have never been able to successfully use forward searching from vim to MuPDF when dealing with papers that contain many files.

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 have focused on reproducing the problems described in this issue with a new version of vim that I built from source a few days ago. However, I should note that I was also not able to get MuPDF integration to work when I tried it with the standard version of vim that comes with Ubuntu 14.04.

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

Here is the version of the xdotool that comes pre-installed with Ubuntu 14.04 LTS:

xdotool version 3.20140217.1

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
let g:vimtex_view_method = 'mupdf'

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>lv to start the zooming in MuPDF on the first page of the file, it will load and work correctly. Then, I can go to the line on the second page and press <leader>lv again and it will also correctly zoom to the second page of the paper. Next, if I go to the line that has the input command on it, I will now correctly zoom to the third page of the paper. In summary, all of these features also work correctly. In summary, the integration between vim and MuPDF as provided by vimtex is working as expected.

Yet, if I change buffers to the first.tex file and then run the <leader>lv command again, it will load another mupdf window. Here is the output from running the <leader>li command in vim:

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'
  base : 'minimal.tex'
  viewer
    xwin_id : '104857719'
    page : '3'
    class : 'MuPDF'
    cmd_start : 'mupdf  ''/home/gkapfham/working/writing/minimal/minimal.pdf'''
    cmd_synctex_view : 'synctex view -i 6:2:''/home/gkapfham/working/writing/minimal/sections/first.tex'' -o ''/home/gkapfham/working/writing/minimal/m
inimal.pdf'' | grep -m1 ''Page:'' | sed ''s/Page://'' | tr -d ''
'''
    cmd_forward_search : 'xdotool type --window 104857719 "3g"'
    forward_search : function('10')
    reverse_search : function('11')
    latexmk_callback : function('12')
    latexmk_append_argument : function('13')
    init : function('7')
    view : function('8')
    start : function('9')
    focus_viewer : function('<SNR>39_focus_viewer')
    focus_vim : function('<SNR>39_focus_vim')
    xwin_exists : function('<SNR>39_xwin_exists')
    xwin_get_id : function('<SNR>39_xwin_get_id')
    xwin_send_keys : function('<SNR>39_xwin_send_keys')

If I run the command xdotool search --class MuPDF in a terminal window, I do find the xwin_id that was listed in the debugging output in vim. In fact, since there are now two mupdf windows open, I will actually see both of their ids inside of the output.

I would see worse types of behavior when I tried to get MuPDF to work with the older version of vim that is standard with Ubuntu 14.04. That is, vim would produce a eight to ten lines of error messages indicating that certain functions did not exist; as I recall, one of them was related to systemlist.

In summary, I have never been able to fully get MuPDF integration to work in vimtex and vim. It is worth noting that the use of MuPDF does not resolve any of the issues that I previously mentioned in issue #176. That is, I normally experience latexmk crashes when I am trying to edit a multi-file paper in vimtex.

Finally, I should note that MuPDF does not zoom to a specific line of the PDF, but rather just the page on which the content is located; since I assume that this is the default (although, not ideal) behavior of forward searching in MuPDF, I do not really consider this a defect in vimtex or any of the other supporting tools.

Can you please advise me on how I can get MuPDF integration fully working on vimtex on Ubuntu 14.04?

@lervag

This comment has been minimized.

Show comment
Hide comment
@lervag

lervag Jun 6, 2015

Owner

I think the main issue mentioned here was solved, as it was similar to the issues #176 and #177. Could you please confirm?

And yes, I think systemlist might be relatively new (as in available after some patch in vim 7.4). I've ended up using systemlist a couple of times, since the code is cleaner than the old workaround that splits the system output on line breaks.

And yes, MuPDF is not capable (unfortunately) to zoom to specific lines. I'm already using a hack to get it to zoom to a page. I think this is the best that is possible. I've also added a hack to get reverse search based on the current page number, but I am not really using that myself. It is mapped to \lr, and will move the cursor to the first line in vim for the current page in MuPDF.

Owner

lervag commented Jun 6, 2015

I think the main issue mentioned here was solved, as it was similar to the issues #176 and #177. Could you please confirm?

And yes, I think systemlist might be relatively new (as in available after some patch in vim 7.4). I've ended up using systemlist a couple of times, since the code is cleaner than the old workaround that splits the system output on line breaks.

And yes, MuPDF is not capable (unfortunately) to zoom to specific lines. I'm already using a hack to get it to zoom to a page. I think this is the best that is possible. I've also added a hack to get reverse search based on the current page number, but I am not really using that myself. It is mapped to \lr, and will move the cursor to the first line in vim for the current page in MuPDF.

@lervag lervag closed this Jun 6, 2015

@gkapfham

This comment has been minimized.

Show comment
Hide comment
@gkapfham

gkapfham Jun 8, 2015

I am writing to confirm that the recent commits have also resolved the issue with MuPDF loading multiple times. Also, I can confirm that it was normally the missing systemlist function that caused forward searching with mupdf to crash on slightly older versions of vim.

Perhaps it would be useful to document in the vimtex documentation the versions of vim on which vimtex can be used successfully? For instance, many Ubuntu 14.04 LTS users will not be able to get forward searching with vimtex and MuPDF to work because of the fact that, by default, the older version of vim does not support the systemlist function.

gkapfham commented Jun 8, 2015

I am writing to confirm that the recent commits have also resolved the issue with MuPDF loading multiple times. Also, I can confirm that it was normally the missing systemlist function that caused forward searching with mupdf to crash on slightly older versions of vim.

Perhaps it would be useful to document in the vimtex documentation the versions of vim on which vimtex can be used successfully? For instance, many Ubuntu 14.04 LTS users will not be able to get forward searching with vimtex and MuPDF to work because of the fact that, by default, the older version of vim does not support the systemlist function.

@lervag

This comment has been minimized.

Show comment
Hide comment
@lervag

lervag Jun 8, 2015

Owner

This seems to indicate that I probably should stop using "bleeding edge" functionalities like systemlist. It is probably a good idea to update the code to instead use the more videly available system and instead parse the result through split to obtain the list.

In any case, thanks for your input!

Owner

lervag commented Jun 8, 2015

This seems to indicate that I probably should stop using "bleeding edge" functionalities like systemlist. It is probably a good idea to update the code to instead use the more videly available system and instead parse the result through split to obtain the list.

In any case, thanks for your input!

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