考虑以下 MWE:
\documentclass{article}
\usepackage[isbn=false,giveninits=true,uniquename=init,style=authoryear-comp,backend=biber,sorting=ynt,natbib,maxbibnames=99,maxcitenames=3,hyperref=true,sortcites=true,language=british,doi=false,url=false,backref=true]{biblatex}
\RequirePackage[colorlinks=true,urlcolor=blue,linkcolor=black]{hyperref}
\addbibresource{References.bib}
% DOCUMENT
\begin{document}
\cite{bop_22}
\printbibliography
\end{document}
还有一个References.bib
包含如下条目的文件:
@online{bop_22,
title = {Inmate Statistics},
author = {{Federal Boreau of Prisons}},
year = {2022},
url = {https://www.bop.gov/about/statistics/statistics_inmate_offenses.jsp}
}
这是输出:
我希望标题(囚犯统计)可点击,同时让丑陋而冗长的 URL 完全不可见,但我无法实现。你能帮我实现吗?
答案1
摘自这个问题:biblatex:使标题超链接到 DOI、URL 或 ISBN。该选项[online]
将此更改仅限制于online
类型引用。
\documentclass{article}
\usepackage[isbn=false,giveninits=true,uniquename=init,style=authoryear-comp,backend=biber,sorting=ynt,maxbibnames=99,maxcitenames=3,hyperref=true,sortcites=true,language=british,doi=false,url=false,backref=true]{biblatex}
\RequirePackage[colorlinks=true,urlcolor=blue,linkcolor=black]{hyperref}
\addbibresource{References.bib}
% reference: https://tex.stackexchange.com/q/48400/133968
\newbibmacro{string+url}[1]{%
\iffieldundef{url}{#1}{\href{\thefield{url}}{#1}}}
\DeclareFieldFormat[online]{title}{\usebibmacro{string+url}{\mkbibemph{#1}}}
\DeclareFieldFormat[online]{url}{}
% DOCUMENT
\begin{document}
\cite{bop_22}
\printbibliography
\end{document}