SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 366 forks source link

LaTeX Warning: There were undefined references, when a bibliographies refer to another #1206

Open evandrocoan opened 7 years ago

evandrocoan commented 7 years ago

When a bibliography has a \cite{} to another bibliography, pdflatex needs to be run 4/5 times, instead of 3 times. For the following document example, if we call LatexTools to build it:

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@manual{abntex2classe,
  Author = {abnTeX2 and Lauro},
  Organization = {Equipe abnTeX2},
  Title = {A classe abntex2},
  Note = {Substitui \cite{abntex2classe2}},
  Year = {2013}
}
@manual{abntex2classe2,
  Author = {abnTeX2 and Lauro},
  Organization = {Equipe abnTeX2},
  Title = {A classe abntex2},
  Year = {2013}
}
\end{filecontents}

\documentclass[10pt,a5paper,twoside]{memoir}

\begin{document}

\cite{abntex2classe}

\bibliographystyle{plain} % <===========================================
\bibliography{\jobname}

\end{document}

It will show the warnings:

[Compiling D:\Test\test3.tex] 2017-08-25, 18:38:42

Basic Builder: running pdflatex...done.
running bibtex...done.
running pdflatex...done.
running pdflatex...done.

No errors. Warnings:

D:\SublimeText\Data\Cache\LaTeXTools\3fadaf268cce53dfbb2db491bf19775c\test3.bbl:11: LaTeX Warning: Citation `abntex2classe2' on page 3 undefined on input line 11.
    D:\Test\test3.tex: LaTeX Warning: There were undefined references.

No bad boxes.

[Done in 00:00:16 seconds!]

image

We need to call Latex Tools more one time, then all the references are resolved:

[Compiling D:\Test\test3.tex] 2017-08-25, 18:44:46

Basic Builder: running pdflatex...done.
running bibtex...done.
running pdflatex...done.
running pdflatex...done.

No errors. No warnings. No bad boxes.

[Done in 00:00:14 seconds!]

image

ig0774 commented 7 years ago

I had a look at this and its not just pdflatex that needs be called a few times. It actually only works if bibtex is also called again. Basically, the minimal sequence that seems to compile this example is:

  1. pdflatex
  2. bibtex
  3. pdflatex
  4. bibtex
  5. pdflatex
  6. pdflatex

This is why the second run clears things up.

If it were merely a question of adding some pdflatex runs on the end, we could probably do it, but I think this example is just too complex to be adequately captured by the basic builder which, as its name suggests, is intended to run a basic build sequence. I'd recommend using something like latexmk or the script builder to compile this document.

latexmk handles the document just fine in my testing, and is used by the traditional builder on TeXLive. If you're using MiKTeX, you'll have to install the latexmk package and tweak the command builder setting to look like this:

"builder_settings": {
    "command": ["latexmk", "-cd", "-f", "-%E", "-interaction=nonstopmode", "-synctex=1"]
}

And then use the traditional builder.

To use the script builder, you need this in your builder settings:

"builder_settings": {
    "windows":  { // or "linux" or "osx"
         "script_commands":
        [
            "pdflatex -interaction=nonstopmode -synctex=1",
            "bibtex",
            "pdflatex -interaction=nonstopmode -synctex=1",
            "bibtex",
            "pdflatex -interaction=nonstopmode -synctex=1",
            "pdflatex -interaction=nonstopmode -synctex=1"
        ],
    }
}