Custom Bibliography In Latex
I was required to use a specific citation style that was specified by the
professor for a report. It was a specific version of IEEE. Although Latex
supports IEEE format, the format did not match the specification of the
professor.
Therefore, I was looking for a way to customize the way the references look in
the reference list. I presumed this would be rather simple, boy was I wrong.
If you don't want to read the story part of this blog and you just want the
answer, skip to Custom references in Latex
Customizing References In Tex
After a lot of online research, a lot of which is really old posts, I found that
you had to customize a .bst
file which latex uses to format the references.
For some stupid reason, the configuration is insanely complicated. It uses a
bunch of macros and crazy instructions. It was recommended that I find one that
is closest to my desired reference style, and modify that.
Since I was using IEEE, I found this IEEE reference .bst
file online:
IEEEtran.
However, once I tried to include it in my code, I realized that .bst
files are
ACTUALLY for an older version of citation, bibtex
, and I'm using biblatex
.
Therefore this method did not work for me.
Customizing References In Latex
After looking around for a little longer, at which point I found out that to
customize the reference list using biblatex
, you are required to edit two
separate files: bbx
and 'cbx'. The recommendation here is also to just
download an existing style that gets as close to your required style and edit
it. Here's a list of styles:
BibLatex Styles. If you're trying to get
the same IEEE files I require, here is a direct link to it:
IEEE Style - download and unzip
biblatex-ieee.tds.zip
.
Once you download the required files, rename them to something else so that you
can test if they are being included in your latex code.
\documentclass{article}
\usepackage[style=CustomIEEE]{biblatex}
\begin{document}
\end{document}
Here I have files called CustomIEEE.bbx
and CustomIEEE.cbx
in the same
directory.
To test if this works, change something obvious about the .bbx
file (I found
this to be the primary file) so that you can compile and check if the file is
being included in the compilation.
In that file, I updated the following files to test it:
\DeclareBibliographyDriver{online}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\adddot\addspace}%
%% Commented this line to check if now title is no longer included.
%% \usebibmacro{title}%
\setunit{\adddot\addspace}%
%% ...
After this update, I no longer saw the title
included in the references list
which indicated to me that my custom configuration was actually the
configuration being used.
Note: This is the command that I used to compile by pdf. I'm on an ArchLinux
machine and this may differ for you if you use a different operating system.
biber
is the program used to compile the references. Here, my tex file is
called report.tex
.
pdflatex report && \
biber report && \
pdflatex report && \
pdflatex report
Adding Custom Fields
To add custom fields to your .bib
files (such as "accessed"), you have to
create a .dbx
file. This file should contains all the "fields" that are to be
specific in your .bib
file.
Contents of the .dbx
file:
\DeclareDatamodelFields[type=field, datatype=literal]{accessed}
Include this data model into the tex file:
\documentclass{article}
% Specify the datamodel attribute
\usepackage[style=CustomIEEE, datamodel=accessed]{biblatex}
\addbibresource{references.bib}
% This specifies the style that the attribute is printed in.
\DeclareFieldFormat{accessed}{[Accessed: #1]}
...
Here is the update I made to the .bbx
file to reflect this new field:
\newbibmacro*{accessed}{%
\iffieldundef{accessed}
{}
{%
\printtext{\printfield{accessed}}%
}%
}
\DeclareBibliographyDriver{online}{%
%% ...
\usebibmacro{accessed}%
%% ...