lervag / vimtex

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

vimtex compilation fails despite compiling successfully when done from command line #2974

Closed Espacio-root closed 11 hours ago

Espacio-root commented 3 days ago

Description

I'm generating .tex files from .ipynb via jupyter nbconvert

When running latexmk -f -pdf test.tex from the command line, it reports some errors but eventually does generate a pdf. The same, unfortunately, cannot be said about vimtex when executing :VimtexCompile from neovim

Steps to reproduce

  1. unzip hello_world.zip to obtain hello_world.tex hello_world.zip

  2. attempt to compile via neovim with the following config:

    vim.g.vimtex_view_method = "zathura"
    vim.g.tex_flavour = "latex"
    vim.g.vimtex_quickfix_mode = 0
    vim.g.vimtex_compiler_method = "latexmk"
    vim.cmd[[set conceallevel=2]]
    vim.g.vimtex_compiler_latexmk = {
      continuous = 1,
      options = {
        "-f",
        "-file-line-error",
        "-interaction=nonstopmode"
      }
    }

Expected behavior

The file should report the encountered errors, but eventually compile

Actual behavior

The file does not compile

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Linux 6.9.7-zen1-1-zen
  Vim version: NVIM v0.11.0-dev-313+gfc9b70826e
  Has clientserver: true
  Servername: /run/user/1000/nvim.561445.0

VimTeX project: hello_world
  base: hello_world.tex
  root: /home/espacio/notes/ml
  tex: /home/espacio/notes/ml/hello_world.tex
  main parser: current file verified
  document class: article
  packages: adjcalc adjustbox alphabeta amsbsy amsfonts amsgen amsmath amsopn amssymb amstext array atbegshi atbegshi-ltx atveryend atveryend-ltx auxhook bigintcalc bitset booktabs calc caption caption3 collectbox color enumerate enumitem environ epstopdf-base etexcmds etoolbox eurosym fancyvrb float fontenc fontspec geometry gettitlestring graphics graphicx grffile hycolor hyperref ifoddpage iftex ifvtex infwarerr inputenc intcalc keyval kvdefinekeys kvoptions kvsetkeys longtable ltcaption ltxcmds mathrsfs nameref parskip pdfcol pdfescape pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgfrcs pgfsys refcount rerunfilecheck soul soul-ori tcolorbox textcomp titling trig trimclip trimspaces ucs ulem unicode-math uniquecounter upquote url varwidth verbatim xcolor xkeyval
  compiler: latexmk
    engine: -pdf
    options:
      -f
      -file-line-error
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
lervag commented 3 days ago

… with the following config:

vim.g.vimtex_view_method = "zathura"
vim.g.tex_flavour = "latex"
vim.g.vimtex_quickfix_mode = 0
vim.g.vimtex_compiler_method = "latexmk"
vim.cmd[[set conceallevel=2]]
vim.g.vimtex_compiler_latexmk = {
  continuous = 1,
  options = {
    "-f",
    "-file-line-error",
    "-interaction=nonstopmode"
  }
}

You don't need g:tex_flavor - just remove it. Also, you don't need to set things that are already at their default. Further, set conceallevel is not really VimTeX/LaTeX specific - it will impact other filetypes as well. You should move that to where you set other Neovim options. Finally, there is no need to add -f to the latexmk options when it already has interaction=nonstopmode. Also, you should probably not remove the -verbose and -synctex=1 options (unless you know what you are doing).

Combined, you should consider to simplify/change your VimTeX config to this:

vim.g.vimtex_view_method = "zathura"
vim.g.vimtex_quickfix_mode = 0

I'm generating .tex files from .ipynb via jupyter nbconvert

When running latexmk -f -pdf test.tex from the command line, it reports some errors but eventually does generate a pdf. The same, unfortunately, cannot be said about vimtex when executing :VimtexCompile from neovim

Your example does not compile properly on my side. It seems to me that the generated LaTeX file is not quite valid and has one or more errors.

I found that the part that didn't work was this:

        \IfFileExists{alphabeta.sty}{
              \usepackage{alphabeta}
          }{
              \usepackage[mathletters]{ucs}
              \usepackage[utf8x]{inputenc}
          }

If I comment out that part, then the document compiles on my end. Going further, it seems to be specifically the \usepackage[utf8x]{inputenc} that does not work. If I comment out just that line, then things work.

Espacio-root commented 3 days ago

Thanks a lot for the suggestions! Just two questions:

  1. How did you figure out which lines were causing the errors? (In my quick fix menu, it seemed like a bunch of gibberish about additional parenthesis')
  2. Isn't there a way to have vimtex ignore the errors and compile regardless (as the default behaviour is, with latexmk via the command line, try `latexmk -f -pdf hello_world.tex')?
lervag commented 3 days ago
  1. How did you figure out which lines were causing the errors? (In my quick fix menu, it seemed like a bunch of gibberish about additional parenthesis')

Yes, the error message was not very helpful here. So I commented out increasingly large parts of the documents in turn until the error was gone. This allowed me to pinpoint what the problem was.

  1. Isn't there a way to have vimtex ignore the errors and compile regardless (as the default behaviour is, with latexmk via the command line, try `latexmk -f -pdf hello_world.tex')?

To be honest, I'm not quite sure why the document compiles on your end and ignores the errors. The -interaction=nonstopmode is typically enough to "force" the compilation. But in any case, I do advice to not ignore errors like these. What you see here is not just a warning, it is a real error. And you should not just ignore it.

Espacio-root commented 2 days ago

after checking :VimtexCompileOutput, I see something that isn't present when I manually compile

./mnist.tex:316:  ==> Fatal error occurred, no output PDF file produced!
Transcript written on mnist.log.
Latexmk: Failure to make the files correctly
    ==> You will need to change a source file before I do another run <==
Latexmk: Getting log file 'mnist.log'
Latexmk: Examining 'mnist.fls'
Latexmk: Examining 'mnist.log'
Latexmk: Errors, so I did not complete making targets

This does not show up when I run latexmk manually, it definitely gives me >100 errors, but does not stop compilation. Any ideas?

lervag commented 2 days ago

Nope, sorry. Again, I don't really think this is something you should pursue - I still think that the strict mode is better here.

Just for the heck: I tried to remove my latexmkrc file, then run latexmk -f -pdf hello_world.tex on my end. This happens:

> latexmk -f -pdf hello_world.tex
Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 31 Jan. 2024. Version 4.83.
No existing .aux file, so I'll make a simple one, and require run of *latex.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex':  Reasons for rerun
Category 'other':
  Rerun of 'pdflatex' forced or previously required:
    Reason or flag: 'Initial setup'

------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex  -recorder  "hello_world.tex"'
------------
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024/Arch Linux) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./hello_world.tex
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-02-20>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size11.clo))
(/usr/share/texmf-dist/tex/latex/tcolorbox/tcolorbox.sty
(/usr/share/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/share/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.tex)
(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def)
(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex
(/usr/share/texmf-dist/tex/generic/pgf/pgf.revision.tex)))
(/usr/share/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
(/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texmf-dist/tex/latex/graphics-def/pdftex.def)))
(/usr/share/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeyslibraryfiltered.code.te
x)) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg)
(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-pdftex.def
(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-pdf.def)))
(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.code.tex))
(/usr/share/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/share/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texmf-dist/tex/latex/graphics/mathcolor.ltx))
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code
.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.comparison.code.te
x) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integerarithmetics
.code.tex) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex))
(/usr/share/texmf-dist/tex/generic/pgf/math/pgfint.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconstruct.code.tex
) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicstate.code.tex)

(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransformations.code.t
ex) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathprocessing.code.te
x) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransparency.code.tex)
 (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code.tex)))
(/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex)
(/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex)
(/usr/share/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version-0-65.sty)
(/usr/share/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version-1-18.sty))
(/usr/share/texmf-dist/tex/latex/tools/verbatim.sty)
(/usr/share/texmf-dist/tex/latex/environ/environ.sty
(/usr/share/texmf-dist/tex/latex/trimspaces/trimspaces.sty))
(/usr/share/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texmf-dist/tex/latex/tcolorbox/tcbbreakable.code.tex
Library (tcolorbox): 'tcbbreakable.code.tex' version '6.2.0'
(/usr/share/texmf-dist/tex/latex/pdfcol/pdfcol.sty
(/usr/share/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/share/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/share/texmf-dist/tex/generic/iftex/iftex.sty))))
(/usr/share/texmf-dist/tex/latex/parskip/parskip.sty
(/usr/share/texmf-dist/tex/latex/kvoptions/kvoptions.sty
(/usr/share/texmf-dist/tex/latex/kvsetkeys/kvsetkeys.sty)))
(/usr/share/texmf-dist/tex/latex/caption/caption.sty
(/usr/share/texmf-dist/tex/latex/caption/caption3.sty))
(/usr/share/texmf-dist/tex/latex/float/float.sty)
(/usr/share/texmf-dist/tex/latex/tools/enumerate.sty)
(/usr/share/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/share/texmf-dist/tex/generic/iftex/ifvtex.sty))
(/usr/share/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/share/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/share/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/share/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/share/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/share/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/share/texmf-dist/tex/latex/base/textcomp.sty)
(/usr/share/texmf-dist/tex/latex/upquote/upquote.sty)
(/usr/share/texmf-dist/tex/latex/eurosym/eurosym.sty)
(/usr/share/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/share/texmf-dist/tex/latex/ucs/ucs.sty
(/usr/share/texmf-dist/tex/latex/ucs/data/uni-global.def))
(/usr/share/texmf-dist/tex/latex/base/inputenc.sty
(/usr/share/texmf-dist/tex/latex/ucs/utf8x.def))
(/usr/share/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty)
(/usr/share/texmf-dist/tex/latex/grffile/grffile.sty)
(/usr/share/texmf-dist/tex/latex/adjustbox/adjustbox.sty
(/usr/share/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/share/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/share/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))
(/usr/share/texmf-dist/tex/latex/adjustbox/adjcalc.sty)
(/usr/share/texmf-dist/tex/latex/adjustbox/trimclip.sty
(/usr/share/texmf-dist/tex/latex/collectbox/collectbox.sty)
(/usr/share/texmf-dist/tex/latex/adjustbox/tc-pdftex.def))
(/usr/share/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty)
(/usr/share/texmf-dist/tex/latex/varwidth/varwidth.sty))
(/usr/share/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/share/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty)
(/usr/share/texmf-dist/tex/generic/pdfescape/pdfescape.sty
(/usr/share/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty))
(/usr/share/texmf-dist/tex/latex/hycolor/hycolor.sty)
(/usr/share/texmf-dist/tex/latex/auxhook/auxhook.sty)
(/usr/share/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texmf-dist/tex/latex/refcount/refcount.sty)
(/usr/share/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty))
(/usr/share/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texmf-dist/tex/generic/intcalc/intcalc.sty)
(/usr/share/texmf-dist/tex/latex/hyperref/puenc.def)
(/usr/share/texmf-dist/tex/latex/url/url.sty)
(/usr/share/texmf-dist/tex/generic/bitset/bitset.sty
(/usr/share/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty))
(/usr/share/texmf-dist/tex/latex/base/atbegshi-ltx.sty))
(/usr/share/texmf-dist/tex/latex/hyperref/hpdftex.def
(/usr/share/texmf-dist/tex/latex/base/atveryend-ltx.sty)
(/usr/share/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty
(/usr/share/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty)))
(/usr/share/texmf-dist/tex/latex/titling/titling.sty)
(/usr/share/texmf-dist/tex/latex/tools/longtable.sty)
(/usr/share/texmf-dist/tex/latex/booktabs/booktabs.sty)
(/usr/share/texmf-dist/tex/latex/tools/array.sty)
(/usr/share/texmf-dist/tex/latex/tools/calc.sty)
(/usr/share/texmf-dist/tex/latex/enumitem/enumitem.sty)
(/usr/share/texmf-dist/tex/generic/ulem/ulem.sty)
(/usr/share/texmf-dist/tex/generic/soul/soul.sty
(/usr/share/texmf-dist/tex/generic/soul/soul-ori.sty)
(/usr/share/texmf-dist/tex/generic/etexcmds/etexcmds.sty))
(/usr/share/texmf-dist/tex/latex/jknapltx/mathrsfs.sty)
(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./hello_world.aux) (/usr/share/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/share/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/share/texmf-dist/tex/latex/caption/ltcaption.sty)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
*geometry* verbose mode - [ preamble ] result:
* driver: pdftex
* paper: <default>
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: 
* h-part:(L,W,R)=(72.26999pt, 469.75502pt, 72.26999pt)
* v-part:(T,H,B)=(72.26999pt, 650.43001pt, 72.26999pt)
* \paperwidth=614.295pt
* \paperheight=794.96999pt
* \textwidth=469.75502pt
* \textheight=650.43001pt
* \oddsidemargin=0.0pt
* \evensidemargin=0.0pt
* \topmargin=-37.0pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=11.0pt
* \footskip=30.0pt
* \marginparwidth=59.0pt
* \marginparsep=10.0pt
* \columnsep=10.0pt
* \skip\footins=10.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)

(/usr/share/texmf-dist/tex/latex/ucs/ucsencs.def)
(/usr/share/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texmf-dist/tex/latex/amsfonts/umsb.fd)
(/usr/share/texmf-dist/tex/latex/jknapltx/ursfs.fd)

LaTeX Warning: No \author given.

(/usr/share/texmf-dist/tex/latex/base/t1cmtt.fd)
! Argument of  has an extra }.
<inserted text> 
                \par 
l.413 \end{document}

? 

The last question mark indicates that latexmk asks for user input. Are you sure that you do not have a .latexmkrc file?

Espacio-root commented 11 hours ago

thanks a lot for looking into this. I understand why this was a stupid idea to begin with. I ended up writing a custom script that simply removes that pesky \usepackage line, along with the rest of the styling, and including that in preamble.tex and including \input{preamble} in my main tex file. Thanks again for the help p.s: spamming enter whenever ? shows up during compilation works.