我正在尝试在我的参考书目中创建一个引用 doi-url 的超链接。url 以期刊名称开头,以页面结尾。为此,我使用了 Mateus Araújo 提供的代码biblatex 中的超链接。不幸的是,这也会改变样式。例如,正常的引用如下所示
但是在添加代码后确实创建了 doi 超链接,它会在年份后添加一个点,并以大写字母开头。
我想删除点并以小写字母开头,但不知道该怎么做。
以下是代码:
\documentclass{article}
\usepackage[backref=true]{biblatex}
\usepackage[colorlinks]{hyperref}
\bibliography{biblatex-examples}
\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{
\iffieldundef{doi}{#1}
{\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
\usebibmacro{in:}%
\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{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\newunit\newblock
\usebibmacro{pageref}%
\usebibmacro{finentry}
}
\begin{document}
\cite{kastenholz}
\printbibliography
\end{document}
答案1
在链接的问题中使用了另一个书目驱动程序。
编辑2: maetra 评论:
我意识到,如果未定义页面,则将此与任何作者年份样式一起使用会导致链接后出现额外的空格。也许你知道解决办法?
解决方案:
在 biblatex 1.6 版本中,文件中有一个小错误authoryear.bbx
。样式重新定义了宏issue+date
。宏的重新定义取决于选项mergedate
。如果将选项设置为true
或,则compact
重新定义如下:
\renewbibmacro*{issue+date}{%
\iffieldundef{issue}
{}
{\printtext[parens]{\printfield{issue}}}
\newunit}%
在最后一个\newunit
操作之前有一个未转义的空格,这会导致多余的空格。因此,您必须执行以下操作:
\renewbibmacro*{issue+date}{%
\iffieldundef{issue}
{}
{\printtext[parens]{\printfield{issue}}}%
\newunit}%
这解决了问题。
编辑1:更改代码。
\documentclass{article}
\usepackage[backend=biber,backref=true]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage[colorlinks]{hyperref}
\ExecuteBibliographyOptions{doi=false}
\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{%
\iffieldundef{doi}{#1}%
{\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
\usebibmacro{in:}%
\printtext[doilink]{%
\usebibmacro{journal+issuetitle}%
\newunit
\usebibmacro{byeditor+others}%
\newunit
\usebibmacro{note+pages}%
}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{issn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\usebibmacro{finentry}}
\begin{document}
\cite{kastenholz}\qquad\cite{herrmann}\qquad\cite{sigfridsson}
\printbibliography
\end{document}
答案2
Marco 的解决方案对我来说也很好用。只是出于某种原因,当我使用他的答案时,参考文献中缺少年份。所以在他的代码中添加了这两行
\newunit
\space(\usebibmacro{date})%
包括年份。我还使用了这个帖子当 doi 不可用时,为 url 或 isbns 创建超链接。以下是 Marco 代码的修改版本:
\documentclass{article}
\usepackage[backend=biber,backref=true]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage[colorlinks]{hyperref}
\ExecuteBibliographyOptions{doi=false}
\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{%
\iffieldundef{doi}{%
\iffieldundef{url}{%
\iffieldundef{isbn}{%
\iffieldundef{issn}{%
#1%
}{%
\href{http://books.google.com/books?vid=ISSN\thefield{issn}}{#1}%
}%
}{%
\href{http://books.google.com/books?vid=ISBN\thefield{isbn}}{#1}%
}%
}{%
\href{\thefield{url}}{#1}%
}%
}{%
\href{http://dx.doi.org/\thefield{doi}}{#1}%
}%
}
\DeclareBibliographyDriver{article}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}\addcomma\space%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{bytranslator+others}%
\newunit\newblock
\printfield{version}%
\newunit\newblock
\printtext[doilink]{%
\usebibmacro{journal+issuetitle}%
\newunit
\usebibmacro{byeditor+others}%
\newunit
\usebibmacro{note+pages}%
\newunit
\space(\usebibmacro{date})%
}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{issn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\usebibmacro{finentry}}
\begin{document}
\cite{kastenholz}\qquad\cite{herrmann}\qquad\cite{sigfridsson}
\printbibliography
\end{document}