Generating APA 6 formatting and references with LaTeX and BibLaTeX

What is LaTeX

It's a toolset that is able to transform the documents written in TeX language into something beautifully rendered, like a PDF file, requiring almost no effort for formatting. It was invented to counteract the problem of different machines displaying files differently, especially things that are hard to format, like equations, tables, and so on.


The steps typically look like this:

+----------------+      +------------------+
| Reference Mgr. +------>   Biblatex .bib  +--------+
+----------------+      +------------------+       +v-------------+    +-----------+
                                                   |   latexmk    +---->  .pdf     |
+----------------+      +------------------+       +^-------------+    +-----------+
|  Text editor   +------>   LaTeX .tex     +--------+
+----------------+      +------------------+

Automate referencing and formatting with LaTeX for psychology papers

Psychology papers are mostly text heavy with some formulas and tables, and generally with a lot of referencing and citations with special formattings, like APA 6 essay style, or two column formatting. Making sure that the document format and the references are correct is time consuming and error-prone but LaTeX can totally automate this process:

- Format the document according to the full APA 6 standard
- Automate referencing and bibliography management
- Highlight unused references
- Correctly reference all tables and figures

The advantage of using automation to generate the correct final APA 6 format is that we can focus on writing the content itself without worrying about accidentally missing a formatting requirement or a reference from bibliography, or correctly pointing to a figure from the text, or just an italics when inserting a mathematical formula. Also, as the source is a simple text file, it's much denser and easier to read than the final output, which according to APA 6 is required to use double spacing, making it hard to overview.

Workflow for reference management

First, as usual, we collect the references for the paper in either Zotero or Mendeley. I personally found a couple of papers that Mendeley had incorrectly imported and the author names were distorted, so I've settled for Zotero, which happens to be open source, unlike Mendeley. Once we have the references, we can export them into BibLaTeX format. I would also highly recommend installing Better BibTeX for Zotero, as the BibLaTeX export is not buggy, it allows customising the citation keys, and even copying them from Zotero with a shortcut (Shift+Command+C).

Editing the LaTeX (.tex) file can be done in any editor, even in Word or LibreOffice as it's a simple text file with some markers but without any kind of formatting. I have attached a sample APA 6 template at the end of this post that will generate a fully formatted APA 6 essay with very little effort from the author.

To generate the output PDF file, either use an online TeX editor or run the LaTeX toolkit locally (see both later):

latexmk -pdf -xelatex

Getting LaTeX, generating the APA 6 format

The only difficult part of using LaTeX is actually setting up the environment. There are great online collaborative LaTeX tools that remove this problem altogether, like Overleaf. It's good to start with those to have a feel for editing TeX files before installing the environment ourselves.

When we are familiar with TeX, it's good to install it locally too: visit the LaTeX project and find the package for the system.

For Mac manual installation, I decided to install it using MacPorts instead of the prepackaged MacTex installer, so these are the components that I needed:

sudo port install texlive
sudo port install biblatex-biber
sudo port install texlive-bibtex-extra
sudo port install texlive-publishers
sudo port install texlive-fonts-extra 
sudo port install texlive-fonts-recommended


Unfortunately, this approach is very time consuming, so retrospectively it would have been much easier to use MacTex...

Sample APA 6 TeX file and the output

The following sample will generate an APA 6 essay in PDF with two "References" section. The second list is the "error list", highlighting the unused references in the BibLaTeX .bib resource - it's not a bug, it's a feature. Try to run it locally or just upload it to Overleaf.

main.tex
\documentclass[a4paper,man,floatsintext]{apa6}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
\usepackage[colorlinks,citecolor=blue,urlcolor=blue]{hyperref}
\DeclareLanguageMapping{american}{american-apa}
\usepackage[utf8]{inputenc}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text, Scale=MatchLowercase}
\setmainfont{Times New Roman}

\DeclareBibliographyCategory{cited}
\AtEveryCitekey{\addtocategory{cited}{\thefield{entrykey}}}
\nocite{*}

\addbibresource{main.bib}

\title{The effect of Social networks on us}
\shorttitle{Social networks}
\author{Adam Horvath}
\affiliation{Your University \\ studentid12345}

\abstract{Your abstract here.}

\begin{document}

\maketitle

Your research paper goes here. You can inline cite like \textcite{ryan_who_2011}. But of course, the usual citation works too \parencite{ryan_who_2011}. Pan es union nostre, con medical linguage historiettas un. Altere auxiliar giuseppe web ha. Del linguas introduction es. Peano publicava linguistic se pro. Su comprende simplificate qui. Sia ma vide germano, tempore specimen per al.
                                                                                                                             
This is a new paragraph. Pan es union nostre, con medical linguage historiettas un. Altere auxiliar giuseppe web ha. Del linguas introduction es. Peano publicava linguistic se pro. Su comprende simplificate qui. Sia ma vide germano, tempore specimen per al.
                                                                                                                             
\printbibliography[category=cited]                                                                                           
\printbibliography[notcategory=cited]                                                               
                                                                                                    
\end{document} 


main.bib
@article{ryan_who_2011,
    title = {Who uses Facebook? An investigation into the relationship between the Big Five, shyness, narcissism, loneliness, and Facebook usage},
    volume = {27},
    issn = {07475632},
    url = {http://linkinghub.elsevier.com/retrieve/pii/S0747563211000379},
    doi = {10.1016/j.chb.2011.02.004},
    shorttitle = {Who uses Facebook?},
    pages = {1658--1664},
    number = {5},
    journaltitle = {Computers in Human Behavior},
    author = {Ryan, Tracii and Xenos, Sophia},
    urldate = {2018-05-12},
    date = {2011-09},
    langid = {english},
}

@article{indian_when_2014,
    title = {When Facebook is easier than face-to-face: Social support derived from Facebook in socially anxious individuals},
    volume = {59},
    issn = {01918869},
    url = {http://linkinghub.elsevier.com/retrieve/pii/S0191886913013743},
    doi = {10.1016/j.paid.2013.11.016},
    shorttitle = {When Facebook is easier than face-to-face},
    pages = {102--106},
    journaltitle = {Personality and Individual Differences},
    author = {Indian, Michaelle and Grieve, Rachel},
    urldate = {2018-05-12},
    date = {2014-03},
    langid = {english},
}  

The output PDF (as images). Notice the last page where the missing references are listed (indian_when_2014 was not cited in the text):


Comments

Popular posts from this blog

MurMurHash3, an ultra fast hash algorithm for C# / .NET

ESP32 - send a push notification from the Arduino ESP32 device to your phone

Octoprint as a systemd service - running it with high priority