我正在使用 biblatex,并希望将我的 DOI 打印出来(感谢doi=true
)不同的颜色和字体在参考书目部分。
基本上,它们的格式与 URL 相同,在我看来它们相当大。我希望减小 DOI 的字体,并以较浅的颜色显示它们。
这是一个最小的工作示例:
\documentclass[a4paper]{article}
\usepackage{libertine}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,doi=true]{biblatex}
\addbibresource{mybib.bib}
\begin{document}
Hello \cite{Smith12}
\printbibliography[title={References}]
\end{document}
内容如下mybib.bib
:
@article{Smith12,
author = {John Smith},
title = {A great article},
journal = {Journal of something},
volume = {1},
number = {1-3},
pages = {42--50},
year = {2012},
doi = {12.345/123456789},
}
注 1: 包libertine
不是必需的,只是它使 URL 字体更大。
笔记2:我不想更改 URL 字体(这很容易),只想更改 DOI 颜色和字体。
答案1
您可以调整doi+eprint+url
宏:
\documentclass[a4paper]{article}
\usepackage{libertine}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Smith12,
author = {John Smith},
title = {A great article},
journal = {Journal of something},
volume = {1},
number = {1-3},
pages = {42--50},
year = {2012},
doi = {12.345/123456789},
}
\end{filecontents*}
\usepackage{xcolor}
\usepackage[backend=biber,doi=true]{biblatex}
\addbibresource{\jobname.bib}
\renewbibmacro*{doi+eprint+url}{%
\iftoggle{bbx:doi}
{\color{red}\tiny\printfield{doi}}
{}%
\newunit\newblock
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock
\iftoggle{bbx:url}
{\usebibmacro{url+urldate}}
{}}
\begin{document}
Hello \cite{Smith12}
\printbibliography[title={References}]
\end{document}
编辑
感谢伟大的@moewe 的评论更改 doi 的字段格式更简单:
\documentclass[a4paper]{article}
\usepackage{libertine}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Smith12,
author = {John Smith},
title = {A great article},
journal = {Journal of something},
volume = {1},
number = {1-3},
pages = {42--50},
year = {2012},
doi = {12.345/123456789},
}
\end{filecontents*}
\usepackage{xcolor}
\usepackage[backend=biber,doi=true]{biblatex}
\addbibresource{\jobname.bib}
\DeclareFieldFormat{doi}{%
\color{red}\tiny%
\mkbibacro{DOI}\addcolon\space
\ifhyperref
{\href{https://doi.org/#1}{\nolinkurl{#1}}}
{\nolinkurl{#1}}}
\begin{document}
Hello \cite{Smith12}
\printbibliography[title={References}]
\end{document}