2

I have recently switched from using Overleaf to writing my documents in Vim with the vim-latex plugin, also known as latex-suite. For the most part everything is working smoothly, but I cannot get bibliography/references to work.

To keep it simple I tried to set up bibliography management the same way I did in Overleaf, with BibTex. So I have a file refs.bib containing, at the moment, a single entry:

@article{berntson2020multi,
  ...
}

My main.tex file contains a citation

\cite{berntson2020multi}

and ends with

...

\bibliographystyle{plain}
\bibliography{refs.bib}

\end{document}

Both files are in the same directory. This worked in Overleaf, but when I try to compile via vim-latex I get the error message

LaTeX Warning: Citation `berntson2020multi' on page 3 undefined on input line 1
84.

No file main.bbl.
[3] (./main.aux)

LaTeX Warning: There were undefined references.

So, what is a minimal setup to get this to work? The answers I find online seem to all be for complicated specialized setups; I just want something simple that works.

If it is simpler to use BibLaTeX instead I am open to that as well. I tried for a bit myself but couldn't get it to work.

Oh, and my .vimrc contains the following lines related to vim-latex:

" Recommended settings for vim-latex
filetype plugin on
filetype indent on
let g:tex_flavor='latex'

" Compile .pdf instead of .dvi
let g:Tex_DefaultTargetFormat='pdf'
6
  • 2
    Welcome to TeX.SE!
    – Mensch
    Mar 9 at 19:26
  • 1
    This is unlikely to be the issue unless you are using an older MikTeX system, but technically speaking \bibliography{refs.bib} is incorrect. \bibliography takes the file names without file extension. So it should be \bibliography{refs}.
    – moewe
    Mar 9 at 19:47
  • 1
    For a bibliography with working citations, your document must be compiled with LaTeX, BibTeX, LaTeX, LaTeX. Overleaf does that for you (it uses the amazing latexmk that automatically runs the required tools when required). I don't know what vim-latex does. github.com/lervag/vimtex/issues/1736 suggests latexmk is involved, in which case things should in theory work unless there are errors (did you check the .log and .blg for errors? did you try deleting the auxiliary files?). There is also tex.stackexchange.com/q/95026/35864.
    – moewe
    Mar 9 at 19:51
  • 2
    Oh, vimtex and vim-latex are two different things, so what I wrote about latexmk might not be true. vim-latex.sourceforge.net/documentation/latex-suite/… says vim-latex may run LaTeX (and BibTeX) up to five times, but from what I read there it could be that this happens only for DVI output and that you need to enable that for PDF output? So maybe you need let g:Tex_MultipleCompileFormats='pdf'?
    – moewe
    Mar 9 at 19:56
  • 1
    @moewe is correct on this, while the capability to run/re-run the likes of bibtex as necessary is natively there in vim-latex it's enabled by default just for dvi target format. Any target formats <fmt> not included in g:Tex_MultipleCompileFormats are just run once according to the formats listed in g:Tex_FormatDependency_<fmt> and their associated g:Tex_CompileRule_<fmt> variables, for pdf this defaults to a single pdflatex call.
    – Dai Bowen
    Mar 9 at 21:25

2 Answers 2

3

vim-latex's mechanism to manage repeated/bibtex/etc compilations is tied explicitly to the file format that is being produced, rather than simply being active or not.

Whether these additional compilation runs are attempted depends on whether g:Tex_DefaultTargetFormat (or possibly also any format specified within the associated g:Tex_FormatDependency_<fmt>) is found in the g:Tex_MultipleCompileFormats.

By default this is only set to apply to dvi, and it is necessary to put pdf in there, e.g. by setting let g:Tex_MultipleCompileFormats='pdf' in vim to only apply multiple compilations to the vim-latex pdf format.

0

I found a solution here. That is, I added

let g:Tex_MultipleCompileFormats='pdf,bib,pdf'

to my .vimrc file. My .vimrc now contains the lines

" Recommended settings for vim-latex
filetype plugin on
filetype indent on
let g:tex_flavor='latex'

" Compile .pdf instead of .dvi
let g:Tex_DefaultTargetFormat='pdf'
let g:Tex_MultipleCompileFormats='pdf,bibtex,pdf'

related to vim-latex. This works for me.

2
  • 2
    Having the second pdf and bibtex in g:Tex_MultipleCompileFormats is not actually necessary or beneficial, as long as the g:Tex_DefaultTargetFormat is in g:Tex_MultipleCompileFormats the multiple and bibtex compilations will be run to try and keep that target format accurate viz bibliography, index, labels etc.
    – Dai Bowen
    Mar 9 at 22:05
  • I see, it seems you are correct. Thank you!
    – ummg
    Mar 10 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.