我的参考书目中有一个特殊字段,称为adsurl
,我想将此 url 显示在我的文件中作为链接。
但是,当我尝试这样做时,href 会抛出一个非常奇怪的错误。它会进入某种无限循环,不断提示
! Undefined control sequence.
\filename@simple ...#2\\}\fi \edef \filename@base
{#1}
梅威瑟:
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{elk,
author = {Anne Elk},
title = {On the Theory of Brontosauruses},
adsurl = {https://example.edu/~elk/bronto.html},
}
\end{filecontents*}
\usepackage[hyperref,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}
\begin{filecontents*}{biblatex-dm.cfg}
\DeclareDatamodelFields[type=field, datatype=literal, skipout=false]{adsurl}
\DeclareDatamodelEntryfields{adsurl}
\end{filecontents*}
\begin{document}
\cite{elk} %this works
\citefield{elk}{adsurl} %this also works
\href{\citefield{elk}{adsurl}}{ads} %this does not work
\end{document}
我怎样才能接受URLhref
的输出?citefield
答案1
感谢 moewe 提供的链接,我得以修复此问题。所以我决定回答此问题,这样人们就不必点击其他问题了。
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{elk,
author = {Anne Elk},
title = {On the Theory of Brontosauruses},
adsurl = {https://example.edu/~elk/bronto.html},
}
\end{filecontents*}
\usepackage[hyperref,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}
\begin{filecontents*}{biblatex-dm.cfg}
\DeclareDatamodelFields[type=field, datatype=literal, skipout=false]{adsurl}
\DeclareDatamodelEntryfields{adsurl}
\end{filecontents*}
%Here's the trick:
\DeclareCiteCommand{\ads}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\href{\thefield{adsurl}}{ads}}
{\multicitedelim}
{\usebibmacro{postnote}}
\begin{document}
\cite{elk}
\citefield{elk}{adsurl}
\ads{elk}
\end{document}
有关更多解释,请参阅链接的问题。