bibtext bst 文件的 bib 风格格式 - 通过示例解释
我的问题是关于在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BibTeX 语言有点复杂:要获得完整的参考,请查看 驯服野兽。要记住的关键事情是它是一种堆栈语言并且它使用后缀方法。几乎所有内置函数也会从堆栈中删除其输入。
一点一点来看,第一行以
FUNCTION
开头,这意味着它将定义一个新函数(format.eprint
),可以在中的其他地方使用.bst
文件。重要的是,这个新函数只能在下面使用:.bst
文件中的函数顺序很重要。大括号用于显示不同的参数:FUNCTION
需要两个,函数的名称和实现它的代码。在代码本身中,
eprint
将是一个字段。使用字段名称将字段值添加到堆栈(对于当前记录)。然后我们有duplicate$
,它复制堆栈顶部的项目。这是一条 BibTeX 内置指令,由终端$
显示。因此堆栈现在将包含eprint
值的两个副本。下一条指令是
empty$
。这将测试堆栈顶部的项目是否为空并将其删除,因此需要duplicate$
。测试结果为1
或0
,并保留在堆栈中。因此,堆栈顶部的项现在不是 1 就是 0,下一项是 eprint 的值。接下来有一个
if$
语句,该语句位于后缀中,因此在if$
之前有两个分支。由于语言是后缀,如果堆栈顶部的项是1
,if$
将选择 true 分支,否则选择 false 分支。这也会从堆栈中删除顶部项目。 (如果您想要真正的细节,两个分支实际上被放置在堆栈上,然后if$
语句删除相应的分支并留下要执行的其余材料。)第一个 ( true) 分支读取
'skip$
,这是一条“不执行任何操作”指令。如果包含前导'
,则单个指令周围的大括号可能会被忽略。对于新用户来说(稍微)更容易阅读的替代方案是简单地使用一组空大括号作为“不执行任何操作”(true)分支。因此,这里的目标是,如果
eprint
字段为空,则不执行任何操作。false 分支开始
"\eprint"
,它将把文字\eprint
放到堆栈的顶部。下一部分将archive
字段放入堆栈中,并对空字段进行另一次测试。如果archive
字段可用,代码会将
[
放入堆栈中,然后将其连接到堆栈顶部的项目(即\eprint):这个连接操作就是
*
所做的。然后,archive
字段的值被添加到堆栈中并加入,后跟另一个]
。因此,如果为archive
提供了任何内容,则堆栈顶部将包含(其中
是存档字段的值),并且仍然只是\eprint
否则。最后,还有一些字符串构建工作要做。我们
首先将
{
放入堆栈。将其连接到顶部项目(\eprint
或\eprint[]
)以给出\eprint{
。swap$
函数交换堆栈顶部的两项,因此顶部项目是 name
(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 haveduplicate$
, 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 ofeprint
.The next instruction is
empty$
. This will test if the top item of the stack is empty and deletes it, hence the need for theduplicate$
. The result of the test is either1
or0
, 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 ofeprint
.Next you have an
if$
statement, which is in postfix and so has the two branches before theif$
. As the language is postfix, what happens is that theif$
will select the true branch if the top item on the stack is1
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 theif$
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 bei.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 thearchive
field onto the stack and does another test for an empty field. If thearchive
field is available, the codewill 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 thearchive
field is then added to the stack and joined on, followed by another]
. So the top of the stack will contain(where
<archive>
is the value of the archive field) if there is anything given forarchive
, and still just\eprint
otherwise.Finally, there is some more string-building to do. We have
which first places
{
onto the stack. This is joined onto the top item (\eprint
or\eprint[<archive>]
) to give\eprint{
. Theswap$
function swaps the top two items on the stack, so the top item is name<eprint>
(the value of theeprint
field). There is a joint to makefollowed 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