如何动态修改 BibLaTeX/Biber 中继承的交叉引用值?

如何动态修改 BibLaTeX/Biber 中继承的交叉引用值?

假设我有以下代码:

\documentclass{article}

\usepackage[backend=biber,bibencoding=utf8]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{test.bib}
    @online {page1,
        crossref = "mysite",
        title = "Page 1",
        url = "http://www.example.com/page1.html"
    }

    @online {page2,
        crossref = "mysite",
        title = "Page 2",
        url = "http://www.example.com/page2.html"
    }

    @online {mysite,
        title = "My Website Home",
        author = "John Doe",
        date = "2016-01-01",
        url = "http://www.example.com/",
        organization = "My Website"
    }
\end{filecontents}

\addbibresource{test.bib}

\begin{document}

\cite{mysite}, \cite{page1}, \cite{page2}.

\printbibliography

\end{document}

如您所见,我有两个网页,page1和,page2它们crossref来自条目mysite。这很好,但不幸的是,每次添加新页面时,我都需要复制 URL。现在,对于这样一个简单的例子,它不是太麻烦,但对于大型书目来说,这很麻烦,而且很容易出错。我开始尝试找出解决这个问题的方法。首先,我在标题中添加了以下映射代码:

...
\DeclareDriverSourcemap{
    \map[overwrite]{
      \pertype{online}
      \step[fieldsource=webpage]
      \step[fieldset=url, origfieldval, append]
    }
}
...

然后,我修改了两个引用的条目,mysite如下所示:

...
@online {page1,
    crossref = "mysite",
    title = "Page 1",
    webpage = "page1.html"
}

@online {page2,
    crossref = "mysite",
    title = "Page 2",
    webpage = "page2.html"
}
...

不幸的是,这不起作用。虽然它确实将webpage字段的内容放入字段中url,但它并没有附加前者的内容到继承的 URL。我不知道这是怎么回事。有没有办法让 BibLaTeX 在制作地图时使用继承的值?

答案1

感谢评论中的建议,我找到了解决问题的可行方法:

\documentclass{article}
\usepackage{hyperref}
\usepackage[backend=biber,bibencoding=utf8]{biblatex}
\usepackage{filecontents}

\DeclareDriverSourcemap{
    \map[overwrite]{
      \pertype{online}
      \step[fieldsource=webpage]
      \step[fieldset=verba, origfieldval]
    }
}

\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\nolinkurl{#1\thefield{verba}}}


\begin{filecontents}{plainurl.bib}
    @online {page1,
        crossref = "mysite",
        title = "Page 1",
        webpage = "page1.html"
    }

    @online {page2,
        crossref = "mysite",
        title = "Page 2",
        webpage = "page2.html"
    }

    @online {mysite,
        title = "My Website Home",
        author = "John Doe",
        date = "2016-01-01",
        url = "http://www.example.com/",
        organization = "My Website"
    }
\end{filecontents}

\addbibresource{plainurl.bib}

\begin{document}

\cite{mysite}, \cite{page1}, \cite{page2}.

\printbibliography

\end{document}

我没有尝试动态修改 URL 字段,而是更改了DeclareFieldFormat该字段的命令url。另外,我无法让它工作,\thefield{webpage}所以我首先将字段映射webpageverba,然后使用它。另外,需要注意的是,这是hyperref实现此功能所必需的,否则命令的输入\url将被视为逐字文本。

相关内容