bibtext bst 文件的 bib 风格格式 - 通过示例解释

发布于 2024-09-15 09:42:29 字数 295 浏览 9 评论 0原文

我的问题是关于在 bst 文件中定义 bibtex 样式字段的方式。我希望通过下面的示例逐个解释,以了解每个部分的作用。我希望自己能够对该示例进行更改。

FUNCTION {format.eprint}
{ eprint duplicate$ empty$
    'skip$
    { "\eprint"
      archive empty$
        'skip$
        { "[" * archive * "]" * }
      if$
      "{" * swap$ * "}" *
    }
  if$
}

my question is regarding the way a bibtex-style field is defined in a bst file. I would like to have the following example below explained piece by piece, to understand what each piece is doing. I would like to be in a position to make changes to that example myself.

FUNCTION {format.eprint}
{ eprint duplicate$ empty$
    'skip$
    { "\eprint"
      archive empty$
        'skip$
        { "[" * archive * "]" * }
      if$
      "{" * swap$ * "}" *
    }
  if$
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2024-09-22 09:42:29

BibTeX 语言有点复杂:要获得完整的参考,请查看 驯服野兽。要记住的关键事情是它是一种堆栈语言并且它使用后缀方法。几乎所有内置函数也会从堆栈中删除其输入。

一点一点来看,第一行以FUNCTION开头,这意味着它将定义一个新函数(format.eprint),可以在中的其他地方使用.bst 文件。重要的是,这个新函数只能在下面使用:.bst 文件中的函数顺序很重要。大括号用于显示不同的参数:FUNCTION 需要两个,函数的名称和实现它的代码。

在代码本身中,eprint 将是一个字段。使用字段名称将字段值添加到堆栈(对于当前记录)。然后我们有duplicate$,它复制堆栈顶部的项目。这是一条 BibTeX 内置指令,由终端 $ 显示。因此堆栈现在将包含 eprint 值的两个副本。

下一条指令是empty$。这将测试堆栈顶部的项目是否为空并将其删除,因此需要duplicate$。测试结果为 10,并保留在堆栈中。因此,堆栈顶部的项现在不是 1 就是 0,下一项是 eprint 的值。

接下来有一个 if$ 语句,该语句位于后缀中,因此在 if$ 之前有两个分支。由于语言是后缀,如果堆栈顶部的项是 1if$ 将选择 true 分支,否则选择 false 分支。这也会从堆栈中删除顶部项目。 (如果您想要真正的细节,两个分支实际上被放置在堆栈上,然后 if$ 语句删除相应的分支并留下要执行的其余材料。)

第一个 ( true) 分支读取 'skip$,这是一条“不执行任何操作”指令。如果包含前导 ',则单个指令周围的大括号可能会被忽略。对于新用户来说(稍微)更容易阅读的替代方案是

FUNCTION {format.eprint}
{ eprint duplicate$ empty$
    { }
    { "\eprint"
      archive empty$
        { }
        { "[" * archive * "]" * }
      if$
      "{" * swap$ * "}" *
    }
  if$
}

简单地使用一组空大括号作为“不执行任何操作”(true)分支。因此,这里的目标是,如果 eprint 字段为空,则不执行任何操作。

false 分支开始 "\eprint",它将把文字 \eprint 放到堆栈的顶部。下一部分将 archive 字段放入堆栈中,并对空字段进行另一次测试。如果 archive 字段可用,代码

"[" * archive * "]" * 

会将 [ 放入堆栈中,然后将其连接到堆栈顶部的项目(即 \eprint):这个连接操作就是*所做的。然后,archive 字段的值被添加到堆栈中并加入,后跟另一个 ]。因此,如果为 archive 提供了任何内容,则堆栈顶部将包含

\eprint[<archive>]

(其中 是存档字段的值),并且仍然只是 \eprint 否则。

最后,还有一些字符串构建工作要做。我们

"{" * swap$ * "}" *

首先将 { 放入堆栈。将其连接到顶部项目(\eprint\eprint[])以给出 \eprint{swap$ 函数交换堆栈顶部的两项,因此顶部项目是 name eprint 的值)场地)。需要进行连接

\eprint{<eprint>

,然后在末尾添加 }

结果是堆栈将在顶部获得一项。如果eprint为空,则栈顶会有一个空项,否则会读取

    \eprint{<eprint>}

The BibTeX language is a bit complex: for a full reference take a look at Tame the BeaST. The key things to remember are that it is a stack language and that it uses a postfix approach. Almost all of the built-in functions also remove their input from the stack.

Taking it piece by piece, the first line starts with FUNCTION, which means it will define a new function (format.eprint) that can be used elsewhere in the .bst file. Importantly, this new function can only be used below here: the order of functions in the .bst file is important. The braces are used to show different arguments: FUNCTION needs two, the name of the function and the code that implements it.

In the code itself, eprint will be a field. Using the name of a field adds the value of the field to the stack (for the current record). We then have duplicate$, which duplicates the top item on the stack. This is a BibTeX build-in instruction, shown by the terminal $. So the stack will now contain two copies of the value of eprint.

The next instruction is empty$. This will test if the top item of the stack is empty and deletes it, hence the need for the duplicate$. The result of the test is either 1 or 0, which is left on the stack. So the top item on the stack is now either 1 or 0, and the next item is the value of eprint.

Next you have an if$ statement, which is in postfix and so has the two branches before the if$. As the language is postfix, what happens is that the if$ will select the true branch if the top item on the stack is 1 and the false branch otherwise. That also removes the top item from the stack. (If you want the real detail, the two branches are actually placed on the stack, and the if$ statement then removes the appropriate one and leaves the rest of the material to be executed.)

The first (true) branch reads 'skip$, which is a 'do nothing' instruction. The braces around a single instruction can be missed out if you include the leading '. An alternative which is (slightly) easier to read for new users would be

FUNCTION {format.eprint}
{ eprint duplicate$ empty$
    { }
    { "\eprint"
      archive empty$
        { }
        { "[" * archive * "]" * }
      if$
      "{" * swap$ * "}" *
    }
  if$
}

i.e. simply using an empty set of braces for the 'do nothing' (true) branch. So the aim here is to do nothing if the eprint field was empty.

The false branch starts "\eprint", which will place the literal \eprint onto the top of the stack. The next part them places the archive field onto the stack and does another test for an empty field. If the archive field is available, the code

"[" * archive * "]" * 

will place [ onto the stack then join it to the top item on the stack (which was \eprint): this joining operation is what * does. The value of the archive field is then added to the stack and joined on, followed by another ]. So the top of the stack will contain

\eprint[<archive>]

(where <archive> is the value of the archive field) if there is anything given for archive, and still just \eprint otherwise.

Finally, there is some more string-building to do. We have

"{" * swap$ * "}" *

which first places { onto the stack. This is joined onto the top item (\eprint or \eprint[<archive>]) to give \eprint{. The swap$ function swaps the top two items on the stack, so the top item is name <eprint> (the value of the eprint field). There is a joint to make

\eprint{<eprint>

followed by a final addition of } to the end.

The result is that the stack will gain one item on the top. If eprint is empty there will be an empty item on the top of the stack, otherwise it will read

    \eprint{<eprint>}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文