[Tex/LaTex] Citations and Bibliography

bibliographiesjabref

Before I begin: I'm sorry for the probably rudimentary question I'll be asking. Please be sure it's not for lack of trying/research.

I'm using TeXShop. I've got my document. I have a .bib file, saved in the same folder as all the stuff TeXShop generates when I run it (I'm using JabRef).

I cannot get in-text citations or a bibliography running.

I have at the bottom of my document

\bibliographystyle{plain}

and

\bibliography {$Users/my name/Documents/Latex/name of bib file}

I have also put \cite{Ref_key6} in the document.

All I'm getting is when I look at the document after hitting "typeset" is a [?] where the citation should be and a section called "References" with nothing written under it .

If there is a relatively jargon-free explanation as to how to get TeXshop to see my .bib file and how to get my citations in I'd be deeply appreciative.

Best Answer

In order to successfully use BibTeX, you need to execute the following sequence of commands:

  1. run latex on the .tex file
  2. run bibtex
  3. run latex again
  4. run latex again

The first pass of latex detects a citation command in your .tex file, as well as the \bibliographystyle{...} and \bibliography{...} commands. Then, running bibtex formats the citation based on the \bibliographystyle{...} command. Running latex the second time makes the appropriate links, and, finally, running latex the third time puts everything in place.

(In TeXShop, you run latex by either clicking on Typeset in the window or by the shortcut COMMAND+T; bibtex is run by changing the dropdown menu next to the Typeset button to BibTeX and then clicking Typeset or by using the shortcut SHIFT+COMMAND+B.)

A couple things you may want to note:

First, if the .bib file is in the same directory as the .tex file, you do not need to specify the entire file path.

Second, you probably want to avoid having spaces in the name of your .bib file. If the name, for example, is my bibliography.bib, you probably want to change it to my_bibliography.bib, and you can include it simply with \bibliography{my_bibliography}, leaving off the file extension.

Third, if these instructions are confusing, there is an engine called pdflatexmk, which is, I think, a Perl script that was written to execute latex and bibtex the correct number of times on a .tex file. This is available as an engine with any recent version of TeXShop. By default, it is inactive. If you type:

mv ~/Library/TeXShop/Engines/Inactive/Latexmk/pdflatexmk.engine ~/Library/TeXShop/Engines/ 

into the command line (i.e., Terminal) it will move this script into the active folder for you, and then you can access this from the dropdown menu in TeXShop right next to the Typeset button, after quitting and reopening TeXShop. (You can also do this by using 'drag & drop' techniques and Finder, though you will probably need to reveal your Library folder, if you're running a recent OS X.)

Finally, a suggestion: you need not make separate .bib files for each document that you write in LaTeX. You can make one 'master' file, and put it in the ~\Library\texmf\bibtex\bib directory (which is a place that will always be found when you run latex, bibtex, and/or pdflatexmk). Only citations that you have cited with a \cite{...} command will actually show up in the References section of the document. I find that this is a good way to manage citations, rather than having separate files for everything, particularly if there are works that you you end up citing multiple times.


Update (as per some recent comments):

First, make sure that your TeX distribution is up to date.

Then, if you have not already set up the requisite texmf directory structure for adding your own .sty files, .bib files, etc., you can follow the instructions here to do so.

After following those instructions, you can move your .bib file to the ~\Library\texmf\bibtex\bib directory. This should take care of any problems that latex \ bibtex might have in locating the .bib file. (Again, doing this might require you to reveal your Library folder.)

Moreover, MWEs for both the .bib file and .tex file will look as follows:

.bib file, which is named master.bib and located in ~\Library\texmf\bibtex\bib:

@article{ref_key6,
Author = {Example Author},
Journal = {Example Journal},
Number = {1},
Pages = {1-32},
Title = {Example Title},
Volume = {1},
Year = {2013}}

and the .tex file:

\documentclass{article}

\usepackage{natbib}

\begin{document}

I am going to cite `ref\_key6' here.\citep{ref_key6}

\bibliographystyle{plain}
\bibliography{master}

\end{document}

enter image description here

Related Question