1

I am using LaTeX (for the first time, I am a noob) with MiKTeX, Texmaker, and JabRef. I want to use citations in my document and I have a Refs.bib file (inspired by this post: Citation undefined error). In LaTeX I have the following code:

\begin{filecontents}[overwrite]{Refs.bib}
@article{Markowitz1952,
    author = {Markowitz, Harry},
    doi = {10.2307/2975974},
    journal = {The Journal of Finance},
    language = {English},
    month = 3,
    number = 1,
    pages = {77-91},
    title = {{Portfolio Selection}},
    url = {https://www.jstor.org/stable/2975974},
    volume = 7,
    year = 1952
}

@article{Michaud1989, author = {Michaud, Richard O.}, title = {{The Markowitz Optimization Enigma: Is ?Optimized? Optimal?}}, journal = {Financial Analysts Journal}, volume = 45, number = 1, pages = {31-42}, year = 1989, publisher = {Routledge}, doi = {10.2469/faj.v45.n1.31}, URL = {https://doi.org/10.2469/faj.v45.n1.31} } \end{filecontents}

\documentclass{article}

\begin{document}

The classical \cite{Markowitz1952} asset allocation algorithm is the stronghold of portfolio construction since its first appearance in 1952, however it is known to output concentrated portfolios with unstable weights achieving poor out-of-sample performances. \cite{Michaud1989} demonstrates its tendency to maximize the errors within the input assumptions.

\bibliographystyle{unsrt} \bibliography{Refs}

\end{document}

However, when I try to quick build the document Texmaker gives me the error citation undefined.

enter image description here

I have been trying to solve this for hours without any success. Do you have any idea what I am doing wrong?

Edit: Here is the log file of the run:

This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 23.5) (preloaded format=pdflatex 2023.5.27)  28 MAY 2023 13:06
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**./Test.tex
(Test.tex
LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-05-15>

LaTeX Warning: Writing or overwriting file `./Refs.bib'.

\openout15 = `Refs.bib'.

Edit2: This error had to do with me using a build directory and is not related to Question mark or bold citation key instead of citation number.

KGB91
  • 145
  • 1
    You need to include a bibliography package such as natbib or biblatex etc, add \usepackage{natbib} to your preamble (before \begin{document} and see if it works, let us know :) – JamesT May 28 '23 at 10:46
  • 2
    That did not work, sadly. I still get the same error. :( Edit: I only tried with natbib when I use biblatex I get an error. – KGB91 May 28 '23 at 10:48
  • Your examples works. You just have to run LaTeX (e.g. PDFLaTeX or XeLaTeX or LuaLaTeX) + bibtex + LaTeX + LaTeX. – cabohah May 28 '23 at 11:00
  • @cabohah I run PdfLaTeX + Bib(la)tex + PdfLaTeX (x2) + View PDF. Should I change? – KGB91 May 28 '23 at 11:03
  • Show the blg file of the BiBTeX run. If it does not begin with This is BibTeX but [0] Config.pm:307> INFO - This is Biber you've run the wrong program. – cabohah May 28 '23 at 11:05
  • @cabohah Where do I find the .blgfile? Edit: I updated with the log file. – KGB91 May 28 '23 at 11:07
  • In the same folder, where you can find the .log file. If you are using Windows, please activate the showing of file name extensions of all files. – cabohah May 28 '23 at 11:10
  • Yeah I have, but I cannot find such a file. Have I forgotten to install something? – KGB91 May 28 '23 at 11:11
  • 2
    If you do not have a .blg, you've not run BibTeX (or not given the basename as a parameter). Opening a .blg is the first thing, the program does, after reading the options an parameters. – cabohah May 28 '23 at 11:14
  • How do I run that? I can find the .exe file but nothing happens when I open it. – KGB91 May 28 '23 at 11:15
  • With the default settings of TeXmaker, you can run it from the menu. If you've changed the configuration, reset it to the defaults. Alternatively use the command line, go to the directory with your document, run bibtex <basename> with <basename> replaced by the basename of your main tex file. – cabohah May 28 '23 at 11:20
  • When I do it I get I couldn't open file name Test.aux Process exited normally – KGB91 May 28 '23 at 11:22
  • Aha! You are right. The problem was that I had a build directory in my settings enabled, but then LaTeX did not find the .aux file needed for the references. Restoring the settings solved the problem. A HUGE thanks for this help! I have spent 4-5 hours trying to solve this problem. You saved my weekend. :) – KGB91 May 28 '23 at 11:26
  • 3
    @JamesT natbib is not needed here, you just need to use bibtex – David Carlisle May 28 '23 at 11:50

1 Answers1

1

The problem was that I had a built directory in my settings enabled, but then LaTeX did not find the .aux file needed for the references. Restoring the settings solved the problem. @cabohah helped me with this solution.

Edit: Or one could use this solution https://stackoverflow.com/questions/55037493/bibtex-not-finding-aux-file-within-texmakers-build-subdirectory

KGB91
  • 145