DIY Your BibTeX Style File

DIY Your BibTeX Style File

This is a short article explaining how to do handy hacks on a BibTeX style file. To customize your own style, you can type in command

latex makebst.tex

to enter an interactive program and generate your own .bst file. But this is VERY tedious. For those of you who just want to modify an existing style file a little bit to cater certain formatting requirement, this article introduces some basic knowledge about a .bst file. I hope that it is a good starting point to guide you into the world of hacking. When reading this article, you will find it convenient to also read an existing style file, say plain.bst, shipped with your latex installation, side by side.

Basic Structure of a BibTeX Style File

The following shows roughly what is inside a .bst file, which logically contains four sections:

ENTRY
{ author
title
journal
year

}
{ … }
{ … }

MACRO { … }{ … }

INTEGERS { … }
STRINGS { … }
FUNCTION { … }{ … }

READ
EXECUTE { … }
ITERATE { … }
SORT
EXECUTE { … }
ITERATE { … }
REVERSE { … }

At the very top is the ENTRY command. The first argument of ENTRY defines legitimate entries in your BibTeX database, such as author, title, journal, year, etc. The second and third augments define internal (but global) integer variables and string variables.

The MACRO commands define abbreviations. For example, the command

MACRO {ieeetcad}{"IEEE Trans. Comput.-Aided Design Integrated Circuits"}

says that if you type `ieeetcad’ in your .bib file, it will be expanded as `IEEE Trans. Comput.-Aided Design Integrated Circuits’ by BibTeX. So instead of typing the long journal name for each cited article in this journal, you only need to enter `ieeetcad’. This trick functions essentially the same as your defining @string macros in your .bib file.

Then come the INTEGERS and STRINGS commands, defining variables that are needed by the immediate FUNCTION. The FUNCTION commands define all the utility functions. It is the most important ingredient in a .bst file. Hacking is mostly done to the FUNCTIONs.

After all the above preparations, BibTeX starts to do its job. The sequence of commands READ, EXECUTE, ITERATE, SORT, EXECUTE, REVERSE… exactly tells the working flow how BibTeX processes and typesets the bibliography entries. First it READs in your BibTeX database file .bib, then it EXECUTEs some commands (defined previously as FUNCTIONs), ITERATEs through all the read-in reference entries, SORTs the entries (e.g. according to author name), and then EXECUTEs, ITERATEs on the sorted entries, REVERSEs, again and again, until all the references are satisfactorily typeset. Note that BibTeX READs only once, but can EXECUTE, ITERATE, REVERSE, and SORT multiple times, until the job is done.

Formatting

All the formatting of the reference entries are done in FUNCTIONs. The FUNCTIONs are implemented in stack-base, i.e., a LIFO fashion. (Well, you really don’t need to understand this, if all what you care about is formatting layout.)

For formatting of author names, let’s locate the FUNCTION format.names. You will see inside the function there is something like

"{ff~}{vv~}{ll}{, jj}" format.name$

This governs how a name is formatted. ff stands for first name, vv for von part,ll for last name, and jj for suffix, such as Sr. and Jr. This format says that the first name is followed immediately (separated by only a space but not a line-break) by the von part, which in turn is immediately followed by last name. After the last name comes a comma and a space, then the suffix. As another example, see the acm style:

"{vv~}{ll}{, jj}{, f.}" format.name$

This format indicates that the von part is presented in the front, immediately followed by last name, then a comma, a space and the suffix. First name goes in the very last, followed by a period. Note that ff means to display the first name fully, while f means that only the initial letter of the first name is displayed.

You will notice that in the acm style, all the letters of a name, except the initial letter, are typeset in smallcaps. This is because in the FUNCTIONformat.authors, there is a line of code

author format.names scapify

where scapify is another function that small-capifies the lower case letters.

Another example. Read the FUNCTION article. From the codes, you probably get a grasp of how different fields of a reference are listed if the reference is ofarticle type. First are the authors, then comes the article title, which is followed by journal information. The format.journal.vol.num.date is another FUNCTION doing more typesetting. But it only cares about volume, number and date. The pages information is only taken care in the FUNCTION format.pages.

Well, I have to stop here. If I explained all the FUNCTIONs, I probably needed to write a hundred-page book. As a hacker, I am sure that you would like to read the codes in existing style files yourself, and you will know a lot more about how to format in the end.

Further Reading

Patrick W. Daly. A Master Bibliographic Style File, for numerical, author–year, multilingual applications.
Nicolas Markey. Tame the BeaST, The B to X of BibTEX.
Oren Patashnik. Designing BibTeX Styles.
Michael Shell and David Hoadley. BibTEX Tips and FAQ.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值