How to cite references in LaTex

created at May 26, 2021, 4:15 p.m. views: 0

In this article, we are going to talk about how to cite references in LaTex document. Two basic things of the citing in LaTex are: a database file contains all reference items; and a package  determines how your text-citations and bibliographies will be styled. 

Generate or build a database of references

Don't be scared by this title, you don't need any professional knowledges to do this. But here we would give a short introduction of the database-like file we would use. Then we introduce two simple ways to generate or build our "database" file.

A database is a .bib file which stores bibliographies in the format of fields, here is an example:

@article{kowarik2016imputation,
  title={Imputation with the R Package VIM},
  author={Kowarik, Alexander and Templ, Matthias},
  journal={Journal of Statistical Software},
  volume={74},
  number={7},
  pages={1--16},
  year={2016},
  publisher={UCLA, Dept. of Statistics}
}

explain for the first line:

  • @article: to declare is this an article or any other types of materials you are referencing, if its a book, then the declaration would be @book.
  • kowarik2016imputation: the name and year of this article, and this is the string which you should copy and paste into your text at where you want to cite this article, like \cite{kowarik2016imputation}.

the rest parts of this record are "what you see is what you get", they store information of a single bibliography into several pieces of key-value pairs, just like a database does.

Build .bib file manually

First, in our .tex document, before the \end{document} mark, we add a statement:

\bibliography{myReference}

this sentence tells latex to insert bibliographies here, myReference is the name of my database file (myReference.bib) without extending, this file hasn't been created yet.

Once we type in this statement, in the Structure box on the left, a drop-down menu call BIBLIOGRAPHY will be generated, click the + symbol and we will see the same name we've just typed in in the declaration:

click this name and the TeXstudio will ask us to create the database file, because we haven't created it before:

choose yes and we get an empty database file in our structure:

adding records into our database

whenever we cite an article:

  1. search this article on google scholar
  2. click on cite
  3. in the pop-up box of reference styles, click on BibTeX at the bottom to go to the data page
  4. copy the data and paste into myReference.bib

repeat this work whenever you want to add a reference into your document.

Export from reference manager

This method would be quite convenient when we need to insert numbers of references into our latex document. We need extra tools to generate a database for us.

There are many reference managers or document readers, like Mendeley, JabRef, EndNote, etc. depends on which one your are using. Normally, they all would have the function to export references as a .bib file.

In my case, I use Mendeley, since its free. By the way, JabRef is free too, but there is some problem with the recent Windows version (can't run), but sounds it is also a good one to try in future.

steps of generation:

In Mendeley:

  1. review and make sure the information of our references are correct
  2. choose references we are gong to cite
  3. File-->export-->yourReference.bib-->save

steps of using:

  1. drap yourReference.bib file and drop it into the Structure box of our TeXstudio.
  2. add the \bibliography{yourReference} statement in our document.

done. Note the .bib file and .tex file should be at the same folder.

Insert citation and bibliographies into our document

After getting our database ready, now we are going to use it to insert citations and bibliographies into our text.

In this step, the only thing we need to care for is the \bibliographystyle{}, we would add this statement like:

\begin{document}
    ...
​
    \bibliographystyle{styleName} # style
    \bibliography{References} # database name
​
\end{document}
  • styleName: which style you may use, this determines how citations and bibliographies will look like.

natbib package

There are many styles we can choose, either from official or contributions from users. One of the most recommended styles is the natbib package because:

this package can meet most of our needs for citation styles

its is also well documented (document)

\documentClass{article}
​
\usepackage{natbib}
​
\begin{document}
    ...
​
    \bibliographystyle{plainnat} # style
    \bibliography{References} # database name
​
\end{document}
  • \usepackage{natbib}: import the natbib package. latex will ask you whether to install this package, click yes.
  • plainnat: plainnat is one of the style names of natbib package

here is a complete example:

\documentclass{article}
\usepackage{natbib}

\begin{document}
    \bibliographystyle{plainnat} # style name
    \setcitestyle{round} # set the bracket to be round 

    \title{A Word Can Be Used in a Sentence Many Ways}
        \author{Geoer}
    \maketitle
    Now,is it good \citep{de2012} \\
    cite2 \citet{Abbas2019}

    \bibliography{yourReference} # database name
\end{document}
  • \citep{}: parenthetical citation (see picture below)
  • \citet{} textual citation (see picture below)
  • \setcitestyle{}: set the form of bracket, round or square

then compile the document and check the preview.

the output:

compile

The last thing need to mention is compiling. There are two ways for compiling, keyboard shortcut and command line.

compile with shortcuts

No matter what editors you are using, they would provide shortcuts for you to compile conveniently. For example, in TeXstudio, click the Tools button on top menu bar, and you will see:

Build & View F5

Compile F6

Using the Command Line/Terminal

The commands listed below should work equally well in a Windows, Unix/Linux, or Mac environment.

In the command line or terminal, first navigate to the location where your .tex file is saved. The following commands can then be used:

latex [filename].tex will compile [filename].tex and output the file [filename].dvi

pdflatex [filename].tex will compile [filename].tex and output the file [filename].pdf

You can also use the command line/terminal to convert between different file types. For example:

dvips -o [filename].ps [filename].dvi will convert [filename].dvi into a PostScript file named [filename].ps

dvipdfm [filename].dvi will convert [filename].dvi into a PDF file named [filename].pdf

References

https://guides.lib.wayne.edu/latex/compile

Daly P W. Natural sciences citations and references[J]. 2010.

Please log in to leave a comment.