5.1 General description

Document: BTXHAK ["Designing BibTeX Styles" by Oren Patashnik]


next 5.2 Commands
up 5 Bibliography-style hacking
gif 5 Bibliography-style hacking

5.1 General description

You write bibliography styles in a postfix stack language. It's not too hard to figure out how by looking at the standard-style documentation, but this description fills in a few details (it will fill in more details if there's a demand for it).

Basically the style file is a program, written in an unnamed language, that tells how to format the entries that will go in the reference list (henceforth ``the entries'' will be ``the entry list'' or simply ``the list'', context permitting). This programming language has ten commands, described in the next subsection. These commands manipulate the language's objects: constants, variables, functions, the stack, and the entry list. (Warning: The terminology in this documentation, chosen for ease of explanation, is slightly different from 's. For example, this documentation's ``variables'' and ``functions'' are both ``functions'' to . Keep this in mind when interpreting 's error messages.)

There are two types of functions: built-in ones that provides (these are described in Section 5.3), and ones you define using either the MACRO or FUNCTION command.

Your most time-consuming task, as a style designer, will be creating or modifying functions using the FUNCTION command (actually, becoming familiar with the references listed above will be more time consuming, but assume for the moment that that's done).

Let's look at a sample function fragment. Suppose you have a string variable named label and an integer variable named lab.width, and suppose you want to append the character `a' to label and to increment lab.width:

    .  .  .
    label "a" * 'label :=          % label := label * "a"
    lab.width #1 + 'lab.width :=   % lab.width := lab.width + 1
    .  .  .
In the first line, label pushes that variable's value onto the stack. Next, the "a" pushes the string constant `a' onto the stack. Then the built-in function * pops the top two strings and pushes their concatenation. The 'label pushes that variable's name onto the stack. And finally, the built-in function := pops the variable name and the concatenation and performs the assignment. treats the stuff following the % as a comment in the style file. The second line is similar except that it uses #1, with no spaces intervening between the `#' and the `1', to push this integer constant.

The nonnull spacing here is arbitrary: multiple spaces, tabs, or newlines are equivalent to a single one (except that you're probably better off not having blank lines within commands, as explained shortly).

For string constants, absolutely any printing character is legal between two consecutive double quotes, but here (and only here) treats upper- and lower-case equivalents as different. Furthermore, spacing is relevant within a string constant, and you mustn't split a string constant across lines (that is, the beginning and ending double quotes must be on the same line).

Variable and function names may not begin with a numeral and may not contain any of the ten restricted characters on page 143 of the book, but may otherwise contain any printing characters. Also, considers upper- and lower-case equivalents to be the same.

Integers and strings are the only value types for constants and variables (booleans are implemented simply as 0-or-1 integers). There are three kinds of variables:

global variables
These are either integer- or string-valued, declared using an INTEGERS or STRINGS command.

entry variables
These are either integer- or string-valued, declared using the ENTRY command. Each has a value for each entry on the list (example: a variable label might store the label string you'll use for the entry).

fields
These are string-valued, read-only variables that store the information from the database file; their values are set by the READ command. As with entry variables, each has a value for each entry.

Document: BTXHAK ["Designing BibTeX Styles" by Oren Patashnik]


next 5.2 Commands
up 5 Bibliography-style hacking
gif 5 Bibliography-style hacking



WebMaster@eeng.dcu.ie
Wed May 15 11:28:03 GMT 1996