[Tex/LaTex] Citation MWE example doesn’t work

apa-stylebibliographies

I have a problem with apa6, apacite, etc. In the process of creating a mwe, I ran across code here on this site as a mwe, but it doesn't work. When compiled (Texpad on a Mac, using Bibtex), it produces [?] as the citation.

Here's the code:

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = {1986},
    title = {The \TeX book},
  }
\end{filecontents}

\begin{document}

Doesn't work. \cite{Knu86}

\bibliography{\jobname}
\end{document}

Thanks for any help on the mwe so I can post my real problem.

Best Answer

You also need a \bibliographystyle. And compile several times, like @barbarabeeton explained. This works:

\documentclass{article}

% Update 2022: Not needed anymore.
%\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = {1986},
    title = {The \TeX book},
  }
\end{filecontents}

\begin{document}

This works, yeah! \cite{Knu86}

\bibliographystyle{alpha}
\bibliography{\jobname}
\end{document}
Related Question