我想要一种自定义的引用样式,其中引用看起来像期刊和年份的简称,并超链接到 DOI 或期刊网站,而不是参考列表(参考书目)。
一种接近的方法是使用style=alphabetic
并指定shorthand
我想要的引用格式。
下面是一个尚未实现我想要的功能的 MWE:
\documentclass[english]{article}
\usepackage[style=alphabetic,maxnames=999,minalphanames=3,firstinits=true]{biblatex}
\usepackage{hyperref}
\begin{filecontents*}{\jobname.bib}
@book{tabmet,
author = {Ulrich Fischer and Max Heinzler and Roland Kilgus and Friedrich Näher and Stefan Oesterle and Heinz Paetzold and Werner Röhrer and Andreas Stephan and Ralf Winkow},
title = {Tabellenbuch Metall},
edition = {42},
year = {2002},
publisher = {Verlag Europa-Lehrmittel},
location = {Haan-Gruiten},
shorthand={Verlag 2002}
}
@article{fakeart,
author = {Walter Schnell and Dietmar Gross and Werner Hauger},
title = {Technische Mechanik},
volume = {2},
title = {Elastostatik},
edition = {4},
publisher = {Springer},
date = {2002},
location = {Berlin},
journal={Journal of BibTeX examples},
shorthand={J Bib Examp 2002}
}
\end{filecontents*}
%shorthand={\href{http://doi.org/10.1257/jep.23.1.221}{J Bib Examp 2002}}
\DeclareLabelalphaTemplate{
\labelelement{
\field[final]{shorthand}
\field[strwidth=4,strside=left,ifnames=1]{labelname}
\field[strwidth=2,strside=left,ifnames=2]{labelname}
\field[strwidth=1,strside=left]{labelname}
}
}
% \field{usera}
\addbibresource{\jobname.bib}
\begin{document}
Citing these \cite{tabmet,fakeart}
\printbibliography
\end{document}
这会产生一个自定义的(实际上是在数据库中单独指定的,因此并不理想)引用格式,但它不允许我链接到外面。
也就是说,我想写
shorthand={\href{http://doi.org/10.1257/jep.23.1.221}{J Bib Examp 2002}}
代替
shorthand={J Bib Examp 2002}
但这样做会产生错误。我真正想要的是不使用 来做到这一点shorthand
。我可以定义一种样式,使用url
数据库中的字段和journal
数据库中的字段,使引用表现得像
(\href{url}{journal year})
答案1
我认为最好将shorthand
和 链接 分成不同的字段。这样你就不必费心处理\href
,也不必执行不必要的格式化命令。
如果我们不想重复使用现有字段(如url
等doi
),则需要定义一个新字段来保存引用标签的链接。在下面的示例中,我将其称为。需要在文件中shorthandlink
声明新字段(在下面的 MWE 中,文件是使用 生成的,在实际应用程序中,只需生成一次文件并将其放在 LaTeX 可以找到的地方)。biblatex
.dbx
.dbx
filecontents
有了shorthandfield
可用的东西,就可以像更改负责将引文链接到参考书目的字段格式一样简单。
\documentclass[english]{article}
\begin{filecontents*}{shorthandlink.dbx}
\ProvidesFile{shorthandlink.dbx}[2020/11/15 arbitrary links for shorthands]
\DeclareDatamodelFields[type=field, datatype=uri]{shorthandlink}
\DeclareDatamodelEntryfields{shorthandlink}
\end{filecontents*}
\usepackage[style=alphabetic,
maxnames=999, minalphanames=3, giveninits=true,
datamodel=shorthandlink]{biblatex}
\usepackage{hyperref}
\DeclareFieldFormat{bibhyperref}{%
\iffieldundef{shorthandlink}
{\bibhyperref{#1}}
{\ifhyperref
{\href{\thefield{shorthandlink}}{#1}}
{#1}}}
\begin{filecontents*}{\jobname.bib}
@book{tabmet,
author = {Ulrich Fischer and Max Heinzler and Roland Kilgus
and Friedrich Näher and Stefan Oesterle
and Heinz Paetzold and Werner Röhrer
and Andreas Stephan and Ralf Winkow},
title = {Tabellenbuch Metall},
edition = {42},
year = {2002},
publisher = {Verlag Europa-Lehrmittel},
location = {Haan-Gruiten},
shorthand = {Verlag 2002},
shorthandlink = {https://example.com/verlag/2002},
}
@article{fakeart,
author = {Walter Schnell and Dietmar Gross and Werner Hauger},
title = {Technische Mechanik},
volume = {2},
title = {Elastostatik},
edition = {4},
publisher = {Springer},
date = {2002},
location = {Berlin},
journal = {Journal of BibTeX examples},
shorthand = {J Bib Examp 2002},
shorthandlink = {https://doi.org/10.1257/jep.23.1.221},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
Citing these\cite{tabmet,fakeart}
\printbibliography
\end{document}
如果要重用现有的doi
和url
字段,则不需要该.dbx
文件,但bibhperref
字段格式需要稍微复杂一些。
\documentclass[english]{article}
\usepackage[style=alphabetic,
maxnames=999, minalphanames=3, giveninits=true]{biblatex}
\usepackage{hyperref}
\DeclareFieldFormat{bibhyperref}{%
\iffieldundef{doi}
{\iffieldundef{url}
{\bibhyperref{#1}}
{\ifhyperref
{\href{\thefield{url}}{#1}}
{#1}}}
{\ifhyperref
{\href{https://doi.org/\thefield{doi}}{#1}}
{#1}}}
\begin{filecontents*}{\jobname.bib}
@book{tabmet,
author = {Ulrich Fischer and Max Heinzler and Roland Kilgus
and Friedrich Näher and Stefan Oesterle
and Heinz Paetzold and Werner Röhrer
and Andreas Stephan and Ralf Winkow},
title = {Tabellenbuch Metall},
edition = {42},
year = {2002},
publisher = {Verlag Europa-Lehrmittel},
location = {Haan-Gruiten},
shorthand = {Verlag 2002},
url = {https://example.com/verlag/2002},
}
@article{fakeart,
author = {Walter Schnell and Dietmar Gross and Werner Hauger},
title = {Technische Mechanik},
volume = {2},
title = {Elastostatik},
edition = {4},
publisher = {Springer},
date = {2002},
location = {Berlin},
journal = {Journal of BibTeX examples},
shorthand = {J Bib Examp 2002},
doi = {10.1257/jep.23.1.221},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
Citing these\cite{tabmet,fakeart}
\printbibliography
\end{document}