![biblatex 中的超链接](https://linux22.com/image/232113/biblatex%20%E4%B8%AD%E7%9A%84%E8%B6%85%E9%93%BE%E6%8E%A5.png)
我正在制作一种biblatex
样式来解决标准样式的问题:如果您有一个带有字段的参考doi
,它只会打印 DOI 编号,如果hyperref
启用,则会带有可点击的链接。
但是 DOI 号又大又丑,没人愿意看到它。我想让链接锚定在期刊参考后面:以期刊名称开头,以页面结尾。到目前为止,我设法编写了以下代码:
\DeclareBibliographyDriver{article}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{bytranslator+others}%
\newunit\newblock
\printfield{version}%
\newunit\newblock
\href{http://dx.doi.org/\thefield{doi}}{\usebibmacro{journal+issuetitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\usebibmacro{note+pages}}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{issn}}
{}%
\newunit\newblock
\usebibmacro{eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\newunit\newblock
\usebibmacro{pageref}%
\usebibmacro{finentry}}
但有一个问题:由于标点符号和空格实际上是由 之后\printfield
的第一个 产生的\newunit\newblock
,因此它们被 捕获\href
,结果非常丑陋。有没有办法强制它们在期刊标题之前产生,而下一个恰好在 之后产生\usebibmacro{note+pages}
?换句话说,我可以让链接环境恰好从期刊名称开始,并在 之后包含标点符号note+pages
吗?
答案1
我找到了方法(感谢雷曼先生!)
当\href
更改格式时,最好在biblatex
格式化原语中使用它,这样它将得到一致的处理。代码是
\DeclareFieldFormat{doilink}{\href{http://dx.doi.org/\thefield{doi}}{#1}}
\DeclareBibliographyDriver{article}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{bytranslator+others}%
\newunit\newblock
\printfield{version}%
\newunit\newblock
\printtext[doilink]{\usebibmacro{journal+issuetitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\usebibmacro{note+pages}}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{issn}}
{}%
\newunit\newblock
\usebibmacro{eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\newunit\newblock
\usebibmacro{pageref}%
\usebibmacro{finentry}}
当然,应该添加一些逻辑(\iffieldundef{doi}
,\ifhyperref
);我只是决定让例子保持简单。