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

Compilation fail with option "-c" #2902

Closed
0xN1C04ND3 opened this issue Mar 19, 2024 · 10 comments
Closed

Compilation fail with option "-c" #2902

0xN1C04ND3 opened this issue Mar 19, 2024 · 10 comments
Labels

Comments

@0xN1C04ND3
Copy link

Description

I have tried to use the compilation argument "-c" to automatically clean up the output files instead of
running :VimtexClean every time.

But when passing this option/argument the compilation fails.
I cannot figure out what I'm doing wrong.

Steps to reproduce

  1. Run :VimtexCompile or <leader>ll

With this configuration:

return {
    'lervag/vimtex',
    init = function()
        -- This is necessary for VimTeX to load properly. The "indent" is optional.
        -- Note that most plugin managers will do this automatically.
        vim.cmd 'filetype plugin indent on'

        -- This enables Vim's and neovim's syntax-related features. Without this, some
        -- VimTeX features will not work (see ":help vimtex-requirements" for more
        -- info).
        vim.cmd 'syntax enable'

        -- Add the "-c" flag to latexmk
        vim.g.vimtex_compiler_latexmk = {
            options = {
                '-c',
            },
        }
    end,
}

And this .tex file :

\documentclass{article}

\begin{document}
Hello, world!
\end{document}

Expected behavior

I expect to compile the .tex file without error
and clean the output files after that like :VimtexClean does.

Actual behavior

The compilation fails with these messages:

Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 31 Jan. 2024. Version 4.83.
Latexmk: Doing main (small) clean up for 'test.tex'
VimTex: Compiler did not start successfully!

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: macOS 14.4 (23E214)
  Vim version: NVIM v0.9.5
  Has clientserver: true
  Servername: /var/folders/6q/dyzg9g_56d974h1jwh5tcd400000gn/T/nvim-24.username/ea8Tx9/nvim-24.65622.0

VimTeX project: test
  base: test.tex
  root: /Users/username/projects/latex-test
  tex: /Users/username/projects/latex-test/test.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -pdf
    options:
      -c
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 7
      output: /var/folders/6q/dyzg9g_56d974h1jwh5tcd400000gn/T/nvim-24.username/ea8Tx9/0
      cmd: max_print_line=2000 latexmk -c  -pdf -pvc -pvctimeout- -view=none -e '$compiling_cmd = ($compiling_cmd ? $compiling_cmd . " ; " : "") . "echo vimtex_compiler_callback_compiling"' -e '$success_cmd = ($success_cmd ? $success_cmd . " ; " : "") . "echo vimtex_compiler_callback_success"' -e '$failure_cmd = ($failure_cmd ? $failure_cmd . " ; " : "") . "echo vimtex_compiler_callback_failure"' 'test.tex'
      pid: 0
  viewer: General
  qf method: LaTeX logfile
@0xN1C04ND3 0xN1C04ND3 added the bug label Mar 19, 2024
@lervag
Copy link
Owner

lervag commented Mar 19, 2024

I have tried to use the compilation argument "-c" to automatically clean up the output files instead of running :VimtexClean every time.

That's not really possibly. :VimtexCompile starts latexmk in the background as a continuous process that compiles your document when you save it.

IMHO, there is really no reason to worry about the generated files. Just ignore them.

Also, please remove the vim.cmd 'filetype plugin indent on' and vim.cmd 'syntax enable' from your config. Those are not necessary when you use a plugin manager (as is mentioned in the very comments you've copied into your config!). Thus, you may simplify your config to this:

return {
    'lervag/vimtex',
    init = function()
        -- you could remove the init block if you are not setting any options
    end,
}

Also; if you really do want to add an option to latexmk, you should append to the default list. Thus:

return {
    'lervag/vimtex',
    init = function()
        vim.g.vimtex_compiler_latexmk = {
            options = {
                '-verbose',
                '-file-line-error',
                '-synctex=1',
                '-interaction=nonstopmode',
                '-c',
            },
        }
    end,
}

However, I still think it does not make sense to add -c when latexmk is run in continuous mode.

@0xN1C04ND3
Copy link
Author

0xN1C04ND3 commented Mar 20, 2024

Also, please remove the vim.cmd 'filetype plugin indent on' and vim.cmd 'syntax enable' from your config. Those are not necessary when you use a plugin manager (as is mentioned in the very comments you've copied into your config!).

Regarding the config I just simply copied the example but I don't have it in otherwise.

The thing is, I have different tex files in the same directory so generating 7 files instead of 3 for every tex files adds up.

I have tried to run with and without continuous mode. But the compiler simply don't compile with the -c flag.
Does this clean option work at all then ?

@lervag
Copy link
Owner

lervag commented Mar 20, 2024

Also, please remove the vim.cmd 'filetype plugin indent on' and vim.cmd 'syntax enable' from your config. Those are not necessary when you use a plugin manager (as is mentioned in the very comments you've copied into your config!).

Regarding the config I just simply copied the example but I don't have it in otherwise.

Then take this advice: 1) read the comments in example code that you copy, and 2) strive to properly understand code that you are copying. The latter is sometimes takes time you feel that you don't have, but I believe in many cases you can actually reduce time waste by investing this time up front.

The thing is, I have different tex files in the same directory so generating 7 files instead of 3 for every tex files adds up.

So, how about creating separate directories for your projects?

I have tried to run with and without continuous mode. But the compiler simply don't compile with the -c flag. Does this clean option work at all then ?

That's the expected behaviour. As far as I know, latexmk was never designed for doing compile then clean in the same invocation.

One thing you can try: Use an event to trigger clean when you exit neovim with something like this:

  init = function()
    vim.api.nvim_create_autocmd(
        "VimtexEventQuit",
        { command = "VimtexClean" }
    )
  end

You may also be interested in reading my related response here: #2820 (comment).

@0xN1C04ND3
Copy link
Author

0xN1C04ND3 commented Mar 20, 2024

Also, please remove the vim.cmd 'filetype plugin indent on' and vim.cmd 'syntax enable' from your config. Those are not necessary when you use a plugin manager (as is mentioned in the very comments you've copied into your config!).

Regarding the config I just simply copied the example but I don't have it in otherwise.

Then take this advice: 1) read the comments in example code that you copy, and 2) strive to properly understand code that you are copying. The latter is sometimes takes time you feel that you don't have, but I believe in many cases you can actually reduce time waste by investing this time up front.

As I said I do not use vim.cmd 'filetype plugin indent on' and vim.cmd 'syntax enable' as I read the comment. :)

The thing is, I have different tex files in the same directory so generating 7 files instead of 3 for every tex files adds up.

So, how about creating separate directories for your projects?

I would have liked to, but I'm told to do so.

When adding the following as suggested:

  init = function()
    vim.api.nvim_create_autocmd(
        "VimtexEventQuit",
        { command = "VimtexClean" }
    )
  end

Even though I don't lazy load Vimtex I get:

Failed to run `init` for **vimtex**
.../.config/nvim-24/lua/ftplugin/tex.lua:43: Invalid 'event': 'VimtexEventQuit'

I did read from the help page:

Note: Commands such as |:VimtexClean| cannot be used in this autocommand
because when quitting vim the current buffer does not necessarily have filetype "tex".

But I may use e.g. VimtexEventCompileSuccess

You are correct, I did see now that latexmk cannot compile and then clean.
Was using it wrong.
(And I know it defeats its purpose to clean after every compilation.)

Thank you for your precious help!

@lervag
Copy link
Owner

lervag commented Mar 20, 2024

As I said I do not use vim.cmd 'filetype plugin indent on' and vim.cmd 'syntax enable' as I read the comment. :)

Ok, cool. You included it in your original post, which is why I mentioned that.

When adding the following as suggested:

  init = function()
    vim.api.nvim_create_autocmd(
        "VimtexEventQuit",
        { command = "VimtexClean" }
    )
  end

Sorry, that's my mistake. It should be:

  init = function()
    vim.api.nvim_create_autocmd("User", {
        pattern = "VimtexEventQuit",
        group = vim.api.nvim_create_augroup("init_vimtex", {}),
        command = "VimtexClean"
    })
  end

I did read from the help page:

Note: Commands such as |:VimtexClean| cannot be used in this autocommand
because when quitting vim the current buffer does not necessarily have filetype "tex".

I think that comment may be wrong; I'm not 100% sure. Please test my updated version.

But I may use e.g. VimtexEventCompileSuccess

Yes, this is also an option, but you should only do it if you do not use continuous compilation.

Notice that for larger documents, LaTeX compilation times are sometimes nontrivial. Thus, cleaning after every compile implies that you need to fully recompile everything everytime. Thus, I think it is better to instead do a clean when you are finished working with your document.

Thank you for your precious help!

Glad to help!

@0xN1C04ND3
Copy link
Author

Sorry, that's my mistake. It should be:

 init = function()
   vim.api.nvim_create_autocmd("User", {
       pattern = "VimtexEventQuit",
       group = vim.api.nvim_create_augroup("init_vimtex", {}),
       command = "VimtexClean"
   })
 end

This works like a charm!
(Tried quitting from another buffer and the documentation seem to be correct)

Big thanks! Couldn't hope for a better solution.

@lervag
Copy link
Owner

lervag commented Mar 20, 2024

Great, I'm glad to hear it!

It seems I should update the docs, though, as they are indicating that this specific thing does not work. Thanks for pointing that out!

lervag added a commit that referenced this issue Mar 20, 2024
@0xN1C04ND3
Copy link
Author

It wasn't maybe not that clear in my phrase. Sorry. I mean the docs are correct in the current state.
When quitting from a buffer that is not of tex filetype, the command is not executed. :)

@lervag
Copy link
Owner

lervag commented Mar 20, 2024

Ah, ok, sorry. Then I'll revert the docs :)

lervag added a commit that referenced this issue Mar 20, 2024
@lervag
Copy link
Owner

lervag commented Mar 20, 2024

I believe the last update should be good - the text is better now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants