我正在尝试创建自己的biblatex
风格,并且想提供一个以斜体或粗体显示标题的选项。
根据其他样式文件,我尝试了这个:
\newtoggle{bftitle}
\DeclareBibliographyOption{bftitle}[true]{
\settoggle{bftitle}{#1}}
\ExecuteBibliographyOptions{bftitle=true}
\iftoggle{bftitle}{
\DeclareFieldFormat{title}{\bfseries{#1}}
\DeclareFieldFormat{journaltitle}{\bfseries{#1}}
\DeclareFieldFormat{issuetitle}{\bfseries{#1}}
\DeclareFieldFormat{maintitle}{\bfseries{#1}}
\DeclareFieldFormat{booktitle}{\bfseries{#1}}
\DeclareFieldFormat{citetitle}{\bfseries{#1}}
}{}
和这个:
\newbool{bftitle}
\DeclareBibliographyOption{bftitle}{
\ifstrequal{#1}{true}
{\global\booltrue{bftitle}}
{\global\boolfalse{bftitle}}}
\ifbool{bftitle}{
\DeclareFieldFormat{title}{\bfseries{#1}}
\DeclareFieldFormat{journaltitle}{\bfseries{#1}}
\DeclareFieldFormat{issuetitle}{\bfseries{#1}}
\DeclareFieldFormat{maintitle}{\bfseries{#1}}
\DeclareFieldFormat{booktitle}{\bfseries{#1}}
\DeclareFieldFormat{citetitle}{\bfseries{#1}}
}{}
两种方法都行不通。无论我使用什么来调用biblatex
(bftitle=true
或bftitle=false
),结果总是相同的(有时总是粗体,有时总是斜体)。
我不知道问题是否出在ExecuteBibliographyOptions
......我无法弄清楚如何使用这些命令,文档对它们的说明很少。
那么我做错了什么?有没有更好的方法来完成我想做的事情?
答案1
您遇到了“时间问题”。该命令\ExecuteBibliographyOptions
“现在”应用了一些设置(设置默认值),但并未采纳任何用户选择。这些应用后您的文件已被读取。因此
\ifbool{bftitle}{
\DeclareFieldFormat{title}{\bfseries{#1}}
\DeclareFieldFormat{journaltitle}{\bfseries{#1}}
\DeclareFieldFormat{issuetitle}{\bfseries{#1}}
\DeclareFieldFormat{maintitle}{\bfseries{#1}}
\DeclareFieldFormat{booktitle}{\bfseries{#1}}
\DeclareFieldFormat{citetitle}{\bfseries{#1}}
}{}
将始终获取您在代码中设置的布尔值,而不是您作为选项传递的值。
您需要安排设置是“动态的”,并在每次调用选项时更改。典型的方法是将检查放在格式“内部”
\DeclareFieldFormat{citetitle}{\ifbool{bftitle}{\mkbibbold{#1}}{#1}}
或者让选项本身进行测试
\DeclareBibliographyOption{bftitle}[true]{
\ifstrequal{#1}{true}
{
\DeclareFieldFormat{title}{\mkbibbold{##1}}
\DeclareFieldFormat{journaltitle}{\mkbibbold{##1}}
\DeclareFieldFormat{issuetitle}{\mkbibbold{##1}}
\DeclareFieldFormat{maintitle}{\mkbibbold{##1}}
\DeclareFieldFormat{booktitle}{\mkbibbold{##1}}
\DeclareFieldFormat{citetitle}{\mkbibbold{##1}}
}
{
\DeclareFieldFormat{title}{##1}
\DeclareFieldFormat{journaltitle}{##1}
\DeclareFieldFormat{issuetitle}{##1}
\DeclareFieldFormat{maintitle}{##1}
\DeclareFieldFormat{booktitle}{##1}
\DeclareFieldFormat{citetitle}{##1}
}
}