我正在为我的 BibTex 文件使用 apacite 包,但根据我的写作风格,如果有的话,它不需要url
在参考书目中列出doi
。有什么方法可以强制 apaciteurl
在参考书目中隐藏并仅显示doi
?
答案1
\bibitem
我们可以使用样式所制作的具体格式apacite.bst
。
\documentclass{article}
\usepackage{filecontents}
\usepackage{apacite}
\usepackage{etoolbox}
\begin{filecontents}{\jobname.bib}
@article{aa,
title = "DOI and URL",
author = "Author, Author",
year = 2000,
journal = "Apacite Examples",
url = "http://www.example.com/1",
doi = "123/123"
}
@article{bb,
title = "Only URL",
author = "Author, Author",
year = 2001,
journal = "Apacite Examples",
url = "http://www.example.com/2"
}
@article{cc,
title = "No DOI no URL",
author = "Author, Author",
year = 2002,
journal = "Apacite Examples"
}
@article{dd,
title = "Only DOI",
author = "Author. Author",
year = 2004,
journal = "Apacite Examples",
doi = "123/124"
}
\end{filecontents}
\newtoggle{bibdoi}
\newtoggle{biburl}
\makeatletter
\newsavebox{\bib@url}
\newsavebox{\bib@doi}
\undef{\APACrefURL}
\undef{\endAPACrefURL}
\undef{\APACrefDOI}
\undef{\endAPACrefDOI}
\newenvironment{APACrefURL}
{\global\toggletrue{biburl}\lrbox\bib@url}
{\endlrbox}
\newenvironment{APACrefDOI}
{\global\toggletrue{bibdoi}\lrbox\bib@doi}
{\endlrbox}
\newcommand{\printinfo}{
\iftoggle{bibdoi}{\usebox{\bib@doi}}{\usebox{\bib@url}}
\togglefalse{bibdoi}
}
\AtBeginEnvironment{thebibliography}{
\pretocmd{\PrintBackRefs}{%
\iftoggle{bibdoi}
{\iftoggle{biburl}{\unskip\unskip}{}Doi: \usebox{\bib@doi}}
{\iftoggle{biburl}{Retrieved from \usebox{\bib@url}}}{}
\togglefalse{bibdoi}\togglefalse{biburl}%
}{}{}}
\makeatother
\begin{document}
\cite{aa}
\cite{bb}
\cite{cc}
\cite{dd}
\bibliographystyle{apacite}
\bibliography{\jobname}
\end{document}
apacite
使用APACrefURL
和APACrefDOI
环境来包装\url
和doi
。因此,我们可以使用lrbox
来存储这样的文本片段,并设置切换来识别它们是否存在。然后,在每个文本的末尾apacite
插入,因此我们可以使用它来将打印和的命令挂接到其中。在这个钩子中,我们进行推理以确定哪些必须打印(并撤消空格)。\PrintBackRefs
bibitem
url
doi