lervag / vimtex

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

vimtex doesn't seem to recognise latexmkrc requesting lualatex #2956

Closed aaannestad closed 1 month ago

aaannestad commented 1 month ago

Description

I'm trying to compile a file that uses the fontspec package, which requires xelatex or lualatex to run. My latexmkrc is set up to trigger that:

$latex = 'lualatex %O %S';

and indeed, the file compiles perfectly well if I run latexmk file.tex from the terminal (though it throws an error about creating a pdf when it expected a dvi file that I can't seem to do anything about). But running \ll in vimtex results in the compiler giving an error, and complaining that fontspec must be run with xelatex or lualatex - clearly indicating that whatever vimtex is doing to call latexmk is causing it to miss or ignore my latexmkrc.

To be clear, I'm trying to set this up in my latexmkrc file rather than just doing like latexmk -lualatex or whatever because I never want to compile with anything other than lualatex or xelatex (which is mostly interchangeable for me), whether that's inside or outside of vim. As far as I'm concerned, engines other than lualatex and xelatex may as well not exist.

Steps to reproduce

  1. Create an MWE like the following:

    \documentclass{article}
    \usepackage{fontspec}
    \setmainfont{ [[some font you have on your system]] }
    \begin{document}
    lorem ipsum
    \end{document}
  2. Ensure that ~/.config/latexmk/latexmkrc contains the above $latex = ... line

  3. Open your MWE and do \ll

Expected behavior

Vimtex calls latexmk, which in turn calls lualatex, which compiles the file normally.

Actual behavior

Vimtex calls latexmk in some way that does not in turn cause it to call lualatex, meaning you get a fatal error when fontspec checks to make sure you're using the right engine.

Do you use a latexmkrc file?

Yes

VimtexInfo

System info:
  OS: Manjaro Linux
  Vim version: NVIM v0.9.5
  Has clientserver: true
  Servername: /run/user/1000/nvim.2986339.0

VimTeX project: test
  base: test.tex
  root: /home/USER/Documents/test
  tex: /home/USER/Documents/test/test.txt
  main parser: current file verified
  document class: article
  packages: expl3 fontspec xparse
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
aaannestad commented 1 month ago

(I didn't intend to open this as a bug - it's probably some config issue on my end - but now that it is a bug I see no way to change it)

lervag commented 1 month ago

I'm trying to compile a file that uses the fontspec package, which requires xelatex or lualatex to run. My latexmkrc is set up to trigger that:

$latex = 'lualatex %O %S';

and indeed, the file compiles perfectly well if I run latexmk file.tex from the terminal …

Yes. latexmk by default will use the latex option here, and you changed that to run lualatex.

However:

(I didn't intend to open this as a bug - it's probably some config issue on my end - but now that it is a bug I see no way to change it)

Correct. The problem is that it is not the correct way to specify by .latexmkrc to use lualatex. Instead, you should do this:

# This specifies to use lualatex
$pdf_mode = 4;

# This is typically also useful (and will be used both for latex, xelatex,
# pdflatex and lualatex)
set_tex_cmds('-synctex=1 -interaction=nonstopmode --shell-escape %O %S');

You can find details in the latexmk manual.

Notice that VimTeX will recognize the pdf_mode setting from your .latexmkrc file.

aaannestad commented 1 month ago

Thank you! That was remarkably difficult information to find just by googling.

lervag commented 1 month ago

Heh, yes; it's much easier if you already know it. ;)

The main things to know here is how latexmk works and how VimTeX is running it. Still, it's easy to see how this is hard-to-build knowledge.