lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.56k stars 391 forks source link

compilation error due to failed main file detection #3016

Closed qqqtwo closed 1 month ago

qqqtwo commented 1 month ago

Description

I only have one file I am trying to compile with \ll. When i do this I receive this error:

compilation error due to failed main file detection

Steps to reproduce

minimal.tex :

\[
  \int_0^1 \frac{dx}{e^x}
\]

~\lua\plugins\vimtex.lua :

return {
  'lervag/vimtex',
  config = function()
    -- Set Okular as the viewer with proper options
    vim.g.vimtex_view_method = 'okular'
    vim.g.vimtex_view_general_options = '--unique file:@pdf\\#src:@line@tex'

    -- Set compiler to latexmk
    vim.g.vimtex_compiler_method = 'latexmk'
  end
}

init.lua:

-- bootstrap lazy.nvim, LazyVim and your plugins
vim.g.vimtex_compiler_latexmk = {
    build_dir = '',
    callback = 1,
    continuous = 1,
    executable = 'latexmk',
    options = {
        '-pdf',
        '-interaction=nonstopmode',
        '-synctex=1',
    },
}

require("config.lazy")

okular is installed and the path added to Path is: C:\ProgramFiles\WindowsApps\KDEe.V.Okular_23.801.1522.0_x64__7vt06qxq7ptv8\bin

i am on windows

Expected behavior

when i compile with \ll, the document should compile and when i do \lv, the document should appear in okular

Actual behavior

when i compile with \ll. i get the error: compilation error due to failed main file detection

when i type \lv nothing happens

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: LAPTOP (Microsoft Windows 11 Home)
  Vim version: NVIM v0.10.2
  Has clientserver: true
  Servername: \\.\pipe\nvim.8408.0

VimTeX project: test
  base: test.tex
  root: C:\Users\andro\notes
  tex: C:\Users\andro\notes/test.tex
  main parser: fallback current file
  document class: 
  compiler: latexmk
    engine: -pdf
    options:
      -pdf
      -interaction=nonstopmode
      -synctex=1
    callback: 1
    continuous: 1
    executable: latexmk
  qf method: LaTeX logfile
lervag commented 1 month ago

I only have one file I am trying to compile with \ll. When i do this I receive this error:

compilation error due to failed main file detection

This is not a problem with VimTeX. Your minimal.tex file is not valid - you need to include a preamble and \begin{document}. Try this:

% minimal.tex
\documentclass{minimal}
\begin{document}
\[
  \int_0^1 \frac{dx}{e^x}
\]
\end{document}

~\lua\plugins\vimtex.lua :

return {
  'lervag/vimtex',
  config = function()
    -- Set Okular as the viewer with proper options
    vim.g.vimtex_view_method = 'okular'
    vim.g.vimtex_view_general_options = '--unique file:@pdf\\#src:@line@tex'

    -- Set compiler to latexmk
    vim.g.vimtex_compiler_method = 'latexmk'
  end
}

First: You should use init = function() ..., not config =. This is written in the install instructions in the README file.

Also, you don't need to specify the compiler method unless you are changing it from the default value (and you are not).

init.lua: …

You should not add -pdf to the options list. IMHO, you should just keep the default, so just remove these lines:

vim.g.vimtex_compiler_latexmk = {
    build_dir = '',
    callback = 1,
    continuous = 1,
    executable = 'latexmk',
    options = {
        '-pdf',
        '-interaction=nonstopmode',
        '-synctex=1',
    },
}