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

magic comment '%! TeX program = *' only work for *.tex #2326

Closed
Freed-Wu opened this issue Feb 10, 2022 · 5 comments
Closed

magic comment '%! TeX program = *' only work for *.tex #2326

Freed-Wu opened this issue Feb 10, 2022 · 5 comments
Labels

Comments

@Freed-Wu
Copy link
Contributor

Description

Set latexmk and vimtex's default tex program to xelatex, then use %! TeX program = lualatex to look which tex program vimtex will use for latexmk. For main.tex, vimtex will use lualatex, it's right. But for other file which extension is not tex, such as dtx or tikz, it still use xelatex.

Steps to reproduce

This is a simple tex file:

%! TeX program = lualatex
\documentclass[tikz]{standalone}
\usepackage{iftex}
\begin{document}
\ifluatex
1
\else
0
\fi
\end{document}

this is a simple latexmkrc:

$show_time = 1;
$dependents_phony = 1;
$do_cd = 1;
$preview_continuous_mode = 1;
push @default_files, '*.ins', '*.dtx';
push @default_files, '*.tikz';
$pdf_mode = 5;
$xelatex = 'xelatex -shell-escape -8bit -file-line-error -no-pdf -synctex=1 %O %S';

and in vimtex config:

  let g:vimtex_compiler_latexmk = {
        \ 'options' : [
          \ '-verbose',
          \ '-synctex=1',
          \ '-interaction=nonstopmode',
          \ '-shell-escape',
          \ '-8bit',
          \ ],
          \ }
  let g:vimtex_compiler_latexmk_engines = {
        \ '_': '-xelatex',
        \ }

pdf_mode = 5 means we use xelatex to generate dvi and convert dvi to pdf by xdvipdfmx.

When the tex file named main.tex, vimtex:

System info:
  OS: Arch Linux
  Vim version: NVIM v0.6.1
  Has clientserver: true
  Servername: /tmp/nvimTwypKA/0

VimTeX project: main
  base: main.tex
  root: /dev/shm
  tex: /dev/shm/main.tex
  main parser: current file
  document class: standalone
  packages: epstopdf-base graphics graphicx ifluatex iftex infwarerr ltxcmds luatex85 pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfrcs pgfsys shellesc tikz trig xcolor xkeyval
  compiler: latexmk
    engine: -lualatex
    options:
      -verbose
      -synctex=1
      -interaction=nonstopmode
      -shell-escape
      -8bit
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile

It is right.

However, when the file is main.dtx or main.tikz:

System info:
  OS: Arch Linux
  Vim version: NVIM v0.6.1
  Has clientserver: true
  Servername: /tmp/nvimBgTwle/0

VimTeX project: main
  base: main.dtx
  root: /dev/shm
  tex: 
  main parser: current file
  document class: 
  packages: epstopdf-base graphics graphicx ifluatex iftex infwarerr ltxcmds luatex85 pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfrcs pgfsys shellesc tikz trig xcolor xkeyval
  compiler: latexmk
    engine: -xelatex
    options:
      -verbose
      -synctex=1
      -interaction=nonstopmode
      -shell-escape
      -8bit
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile

It use xelatex, and will output a pdf which content is 0 not 1.

Expected behavior

I think whatever the file's name is main.dtx or main.tikz or main.ins or other name, the tex program always be lualatex.

Actual behavior

only main.tex can work.

Do you use a latexmkrc file?

Yes

VimtexInfo

vimtexinfo has been attached above.
@Freed-Wu Freed-Wu added the bug label Feb 10, 2022
@Freed-Wu
Copy link
Contributor Author

It seem to be related to the code judge the self.tex:

  let l:ext = fnamemodify(a:main, ':e')
  let l:new.tex = l:ext ==# 'tex' ? a:main : ''

If the file's ext is not tex, self.tex will be ''. And magic comment will not be used. Why not get extensions from latexmk's @default_files? Or just simply provide a variable named g:vimtex_extension_list?

@Freed-Wu
Copy link
Contributor Author

index 0ea336d3..1163ec54 100644
--- a/autoload/vimtex/state/class.vim
+++ b/autoload/vimtex/state/class.vim
@@ -18,7 +18,7 @@ function! vimtex#state#class#new(main, main_parser, preserve_root) abort " {{{1
   endif

   let l:ext = fnamemodify(a:main, ':e')
-  let l:new.tex = l:ext ==# 'tex' ? a:main : ''
+  let l:new.tex = a:main

   " Get preamble for some state parsing
   let l:preamble = !empty(l:new.tex)

This can solve this problem.

@lervag
Copy link
Owner

lervag commented Feb 12, 2022

Thanks! I agree that the suggested code should be relaxed. I want to avoid options, so I'll relax to allow .dtx and .tikz as well for now, which should resolve your issue.

lervag added a commit that referenced this issue Feb 12, 2022
@lervag lervag closed this as completed Feb 12, 2022
@Freed-Wu
Copy link
Contributor Author

.ins is also tex file extension. According to document of docstrip and doc, compile .ins to get package.sty, document.cls, example.tex, etc, and compile .dtx to get a document pdf about this macro package. I advice to add .ins.

I also suppose avoiding options (too many options maybe confuse user). However, I am not sure about .dtx, .ins, ... are all tex file extensions. If any new extensions are found (it seldom happen), we should add them.

lervag added a commit that referenced this issue Feb 12, 2022
@lervag
Copy link
Owner

lervag commented Feb 12, 2022

Ok :)

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