8

I'm trying to read about .bst files from Tame the Beast. On page 38, there is this example for an and function:

FUNCTION {and}
{   'skip$
    { pop$ #0 }
  if$
}

What does the ' in front of skip do?

Comment 34 on page 32 says:

A variable name is a name that has been declared with STRINGS or INTEGERS, or with ENTRY. Moreover, it must be preceded with a single quote, so that BibTeX understands that you mean the name of the variable and not its value. For instance, ’label.

It still doesn't make sense that skip is a variable name.

1 Answer 1

8

Before we look at the underlying idea, it's important to remember that and in BibTeX is a comparator hidden inside a function. It's always used after something that will generate an integer, which will then either be 1 (TRUE) or 0 (FALSE). It's sorting out the logic of comparing two integers, but it only does something with the second one as the result is whatever the first integer is.

The ' here is used to allow 'simplification' of the code. The standard syntax for a conditional is

<number>
  { <code if true> }
  { <code if false> }
if$

Notice in particular that both branches require a set of braces. (BibTeX's if$ tests a number on a simple TRUE/FALSE = 1/0 basis. Most conditionals you'll see in BibTeX have a part before the if$ doing a bit of work to set this up.)

In the example, the TRUE branch consists of a BibTeX built-in only. Thus while you could write

FUNCTION {and}
{
    { skip$ }
    { pop$ #0 }
  if$
}

or

FUNCTION {and}
{
    { }
    { pop$ #0 }
  if$
}

this makes the TRUE branch a bit tricky to read. Thus there is a 'shortcut' syntax: the braces may be missed out if you use 'skip$ in place of { skip$ }.

You normally only see this approach for branches being skipped, as it's not really so useful with other built-ins (although you might see 'pop$ in the same way).

4
  • Thanks for your detailed reply! A couple of questions: 1) "the TRUE branch consists of a BibTeX built-in" >> What is a BibTeX built-in? 2) Why is { skip$ } trickier to read than 'skip$? I found the first one more natural.
    – Mika H.
    Commented Dec 4, 2012 at 16:01
  • @MikaH. BibTeX has a small number of built-in functions, all of which end $, for example skip$, pop$, if$. I'm contrasting them with functions defined in a .bst file, such as and in the example.
    – Joseph Wright
    Commented Dec 4, 2012 at 16:03
  • @MikaH. On the readability or otherwise: both approaches will work, so it's down to you how you approach this. In the LaTeX3 coding I do we've also decided that omitting braces does not necessarily help with readability! One thing to bear in mind is that parsing a { ... } expression is more work than an single statement, and while this is not important now, computers were a lot less powerful historically.
    – Joseph Wright
    Commented Dec 4, 2012 at 16:05
  • I'ts frustrating that this is not mentioned in the documentation... which makes 'skip$ much harder to read than {skip$}!!
    – akvilas
    Commented Mar 21, 2017 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .