Make your own bibliography style in LaTeX

If the many multitudes of LaTeX bibtex* bibliography styles don't suit you, never fear! It's easy and exciting to make your own bibliography style (.bst) in just a couple of minutes, or even hours if you really get into it! Here's how I did it:

*Bibtex is the traditional LaTeX bibliography backend that connects your .bib file (from your reference manager) with your .tex file. Bibtex is most commonly used with natbib, which is a package that can make style adjustments to your bibliography to meet the standards of various journals. The alternative to bibtex&natbib is the backend biber and the package biblatex (though biblatex supposedly also works with bibtex). Biber&biblatex is a combination frequently seen in the humanities for bibliography styles like Chicago full note and references.


WHAT YOU'LL NEED

  • A Unix computer (e.g. a Mac)
  • With MacTeX installed (MacTeX is the free LaTeX distribution for Macs)
  • A passion for procrastination and tedium

STEP ONE: OPEN TERMINAL

STEP TWO: START THE MAKEBST WIZARD
Simple type the following after the prompt$:

latex makebst

STEP THREE: HIT "ENTER" TWICE
When you hit "enter," the default option is selected. Throughout the wizard, the default option will either be written in parentheses, like (NO), or indicated with an asterisk (*).

In this case, you are being asked "Do you want a description of the usage?" and then prompted to enter the name of a .mbs file. By hitting the carriage return twice, you select the default option and keep things simple!

STEP FOUR: ENTER THE FILE NAME FOR YOUR .BST FILE
This part is important! What will your bibliography style be called? Only specify the name, no .bst extension needed

STEP FIVE:  SKIP THE NEXT FOUR OPTIONS BY CLICKING "ENTER"

STEP SIX: BEGIN DESIGNING YOUR BIBLIOGRAPHY
You didn't think this would be easy, did you? Now you'll be asked 70 questions about what you want your references to look like—without any visualization. Yikes! But it's fun, like taking a long personality quiz or filling out a form at the doctor's office...To choose an option, simply write the appropriate letter and then hit enter. If you don't write any letter and just hit enter, you'll automatically select the default option. There is no way to "back up" or "undo" in the wizard, so be sure not to accidentally select the wrong option! (But if you do, don't worry! I'll show you how to edit your selections afterwards). I recommended selecting the default option for any questions you don't know the answer to!

Here's a small snippet of what you can expect to see in the wizard, so that you can be prepared:

JOURNAL NAME PUNCTUATION:
(*) Comma after journal name
(x) Space after journal name
Select:

\ans=
You have selected: Comma after journal

BOOK TITLE:
(*) Book title italic (\em)
(p) Book title plain (no font command)
Select:

\ans=
You have selected: Book title italic

PAGES IN BOOKS:
(*) Pages in book plain as pp. 50-55
(p) Pages in book in parentheses as (pp. 50-55)
(x) Pages in book bare as 50-55
Select:

\ans=
You have selected: Pages in book plain

STEP SEVEN: AFTER ANSWERING ALL THE QUESTIONS, RUN THE PROGRAM
The wizard actually creates a docstrip batch job (.dbj) that needs to be run using TeX to make your style file (.bst) When you've answered all of the style questions, the program will say:

Finished!!
Batch job written to file `yourbibstyle.dbj'
Shall I now run this batch job? (NO)

Here, instead of the default (NO), write "yes" and the .dbj will compile into your .bst. If you accidentally do select no, just compile the .dbj as indicated in section 10.

STEP EIGHT: TELL YOUR TEX EDITOR ABOUT THIS STYLE
Now you have a .bst file, hooray! By default, this file was created in your root directory. We need to make a directory specifically for TeX and move it there. Write:

mkdir ~/texmf/bibtex/bst
cp yourbibstyle.bst ~/texmf/bibtex/bst/
sudo texhash ~/texmf

And type in your system password when prompted! The letters will not appear on the screen as you type.

STEP NINE: INCLUDE YOUR NEW STYLE IN YOUR .TEX DOCUMENT
You've made it! Now you can simply use your bibliography style as usual by including the following commands in your .tex file, where the bibliography from your reference manager is called "yourbib.bib":

\bibliographystyle{yourbibstyle}
\bibliography{yourbib}

\end{document}

STEP TEN: EDITING YOUR STYLE AFTER IT IS MADE
So, you've put in all this work but your bibliography has a small error. For example, maybe you accidentally italicized the titles of books when you wanted them plain. Oops. All you have to do to make this easy fix is to edit the relevant section of the .dbj file you created, select a different option, and re-run the file into a new .bst. Let me walk you through that.

First, find and open your .dbj file. If you followed the above steps, it should be in your root directory. You can either open your .dbj in Terminal using Vim or Emacs (Team Vim all the way though!) or open the file from Finder using TextEdit.

Then, find the relevant section of the file you made an error on. In this example, that section will look like:

%--------------------
%BOOK TITLE:
%: (def) Book title italic
% btit-rm,bt-rm,%: Book title plain
%--------------------

Here, like in a .tex file,  "%" indicates that a line is commented out and is thus ignored when compiled into a .bst file. In this case, "Book title italic" is not commented out (since it does not have a % in the left column) while "Book title plain is commented out. By adjusting these percent signs, you can change which option is selected. To force the style to have non-italicized book titles, you'll want to edit the code to look like this:

%--------------------
%BOOK TITLE:
% %: (def) Book title italic
btit-rm,bt-rm,%: Book title plain
%--------------------

Save your changes in a new file and then run the batch job to compile your .dbj file into a .bst using the command:

tex yourbibstyle2.dbj

Then move the file as above, and you're good!

cp yourbibstyle2.bst ~/texmf/bibtex/bst/ 
sudo texhash ~/texmf

Don't forget to use the new version of your file in your .tex code as well.


And there you have it! As in most cases, there is no need to reinvent the wheel when it comes to bibliography styles, so if you are trying to format a bibliography for a specific journal please look into what styles are already available to save your time and effort. However, if you're just looking for another fun thing to do in Terminal, I hope you find this process as entertaining as I do!

Comment below if you have any trouble with the process, or if you have any suggestions to this guide. Thanks!