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

Showing compiler output on non-continuous latexmk compile #2138

Closed
ThSGM opened this issue Aug 19, 2021 · 10 comments
Closed

Showing compiler output on non-continuous latexmk compile #2138

ThSGM opened this issue Aug 19, 2021 · 10 comments

Comments

@ThSGM
Copy link

ThSGM commented Aug 19, 2021

This is related to the following issue: Displaying the results of a LaTeX run at the time which was asked, and to a certain extent resolved at the time in 2016. However, I don't think the resolution works anymore, perhaps due to changes since 2016.

I would like to:

  1. Using vimtex in non-continuous mode, via,

    " Setting latexmk options
    let g:vimtex_compiler_latexmk = {
            \ 'build_dir' : '',
            \ 'callback' : 1,
            \ 'continuous' : 0,
            \ 'executable' : 'latexmk',
            \ 'hooks' : [],
            \ 'options' : [
            \   '-verbose',
            \   '-file-line-error',
            \   '-synctex=1',
            \   '-interaction=nonstopmode',
            \ ],
            \}
  2. When a file is compiled, I'd like to display the compiler output as it is outputted. This would be helpful in diagnosing errors that cause hangups in the compilers, or for large projects where compilation can take some time. This is the default behaviour in, e.g. SublimeText with LaTeXTools:

    020_latex_build_results_sublime_text

    The resolution that was proposed was to use:

    augroup MyVimtex
      au!
      autocmd User VimtexEventCompileStarted call MyVimtexOutputter()
    augroup END
    
    function! MyVimtexOutputter()
      call vimtex#latexmk#output()
    
      " Move window to bottom
      wincmd J
    
      " Set window height
      resize 20
    
      " Return to LaTeX buffer
      wincmd w
    endfunction

    However, it suffers from two problems:

    1. I get the error

      Error detected while processing function MyVimtexOutputter:
      line    1:
      E117: Unknown function: vimtex#latexmk#output
      

      I'm unable to find mention of vimtex#latexmk#output in the documentation.

    2. Also, according to the documentationVimtexEventCompileStarted only works with continuous mode set to on.

lervag added a commit that referenced this issue Aug 25, 2021
@lervag
Copy link
Owner

lervag commented Aug 25, 2021

This is related to the following issue: Displaying the results of a LaTeX run at the time which was asked, and to a certain extent resolved at the time in 2016. However, I don't think the resolution works anymore, perhaps due to changes since 2016.

Ah, yes; I don't think it is unlikely that all of the VimTeX code has been rewritten since 2016. So it is quite likely that we need a new take on this to settle a good solution. Thanks for bringing it up!

Using vimtex in non-continuous mode, via,

I just want to remark that you can simplify the config. You only need to specify things you want to change. In this case, you can simplify to:

let g:vimtex_compiler_latexmk = {'continuous' : 0}

When a file is compiled, I'd like to display the compiler output as it is outputted.

I'm not sure if it is easy to show it live while it is compiling, but let's see how far we can come.

The resolution that was proposed was to use:

I think the proposed solution is close to what we want, but I am not surprised to find that it is deprecated. I made some updates, and the following should now work:

let g:vimtex_compiler_latexmk = {'continuous' : 0}

augroup MyVimtex
  au!
  autocmd User VimtexEventCompileStarted call MyVimtexOutputter()
augroup END

function! MyVimtexOutputter()
  VimtexCompileOutput
  wincmd J
  resize 20
  wincmd w
endfunction

@lervag lervag closed this as completed Aug 25, 2021
@lervag
Copy link
Owner

lervag commented Aug 25, 2021

I'm unable to find mention of vimtex#latexmk#output in the documentation.

It's not documented. I've updated my response; it is better to use the documented command :VimtexCompileOutput - it does the same thing.

@ThSGM
Copy link
Author

ThSGM commented Aug 26, 2021

Hi,

I implemented the fix and there seems to be an error when compiling after the first time. I have recorded a video to show this. You will see the red error when compiling the second time and then the creation of the window in a separate buffer window.

vimtex_compile.mp4

lervag added a commit that referenced this issue Aug 26, 2021
@lervag
Copy link
Owner

lervag commented Aug 26, 2021

Sorry about that - it should be fixed now.

@ThSGM
Copy link
Author

ThSGM commented Aug 26, 2021

Sorry about that - it should be fixed now.

Yup, that seems to fix it.

So now the issue seems to be that the console mechanism does not play so nicely with the usual vimtex popup buffers. For example, running the compiler and then pressing <localleader>le generates the error window in the top-most window.

Screenshot 2021-08-26 at 13 56 44

The most sensible behaviour for people who want this functionality, I expect, is that a call to le will replace the output window with the quickfix error window. Then further calls to compile will then replace the error window with the output window and so forth.

I suppose I am simply saying that the best outcome that would appeal to people would be a single console window at the bottom of the screen that handles both output and errors.

@ThSGM
Copy link
Author

ThSGM commented Aug 26, 2021

I also found a weird bug.

When using the output console functionality, you get massive slowdown when the window is open. I show this in the following video. I compile a document, and show the CPU usage spike when the new console window is open. Scrolling is very laggy.

I then close the window and functionality returns to normal.

vimtex_slow.mp4

@lervag
Copy link
Owner

lervag commented Aug 26, 2021

I pushed an update that I think resolves your last issue. The idea was to avoid reloading the file if there is no new change. Please test.

I'll look at the other part now.

lervag added a commit that referenced this issue Aug 26, 2021
lervag added a commit that referenced this issue Aug 26, 2021
@lervag
Copy link
Owner

lervag commented Aug 26, 2021

I believe the other problem is due to a race condition between the output window and the compiler callback. I've pushed a couple of fixes that should address it. To ensure the quickfix window appears on the bottom, you can close it first. I.e.:

let g:vimtex_compiler_latexmk = {'continuous' : 0}

augroup MyVimtex
  au!
  autocmd User VimtexEventCompileStarted call MyVimtexOutputter()
augroup END

function! MyVimtexOutputter()
  " Close quickfix window first
  cclose

  " Open output window
  VimtexCompileOutput
  wincmd J
  resize 20
  wincmd w
endfunction

@krissen
Copy link
Contributor

krissen commented Sep 17, 2022

I've been using this solution quite a bit; appreciate the possibility of seeing perhaps primarily that something is happening, as well as, to a lesser degree, what is happening.

I've added the following, to also automatically close the output window when the compilation is stopped:

augroup MyVimtex " *Addition* to the augroup mentioned earlier in the thread
  autocmd User VimtexEventCompileStopped call MyVimtexOutputterStop()
augroup END

function MyVimtexOutputterStop()
  wincmd j
  close
endfunction

Not foolproof by any means, but it works as I want it to more often than not.

@lervag
Copy link
Owner

lervag commented Sep 17, 2022

Cool; thanks for sharing!

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