我尝试过发布在这里,这里以及其他相关帖子均无济于事。我尝试hyperref
在使用natbib
和的文档中使用bibentry
,但它给出了大量错误。我的问题与其他帖子之间的主要区别在于,我bibentry
在章节标题中使用,我必须使用它\protect
才能使其正常工作。
请参阅下面的代码:
\begin{filecontents}{test.bib}
@article{mccarty2018theory,
author = {McCarty, Nolan and Schickler, Eric},
date-added = {2021-05-16 19:43:59 -0400},
date-modified = {2021-05-16 19:43:59 -0400},
journal = {Annual Review of Political Science},
pages = {175--193},
publisher = {Annual Reviews},
title = {On the theory of parties},
volume = {21},
year = {2018}}
}
\end{filecontents}
\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{titlesec}
\usepackage{hanging}
\usepackage{color}
\usepackage{natbib}
\bibliographystyle{apa}
\usepackage{bibentry}
\makeatletter\let\saved@bibitem\@bibitem\makeatother
\usepackage{hyperref}
\makeatletter\let\@bibitem\saved@bibitem\makeatother
\author{Test}
\title{Test}
\titleformat*{\section}{\normalsize\bfseries}
\titleformat*{\subsection}{\normalsize\bfseries}
\titleformat*{\subsubsection}{\normalsize\bfseries}
\makeatletter
\renewcommand\BR@b@bibitem[2][]{\BR@bibitem[#1]{#2}\BR@c@bibitem{#2}}
\makeatother
\nobibliography*
\begin{document}
\maketitle
\tableofcontents
\section{\protect\bibentry{mccarty2018theory}} %THIS LINE CAUSES AN ERROR
\cite{mccarty2018theory} blah blah blah ...
\clearpage
\bibliography{test.bib}
\end{document}
答案1
您遇到的问题是由于 的参数\section
远远超出了hyperref
创建关联书签的能力。您需要使用\texorpdfstring
宏作为 的参数\section
,并确保 的第二个参数\texorpdfstring
不太复杂。事实上,我会让第二个参数尽可能简单,同时仍然提供足够的信息。例如,McCarty and Schickler, 2018, On the theory of parties
。
\begin{filecontents}[overwrite]{test.bib}
\@article{mccarty2018theory,
author = {McCarty, Nolan and Schickler, Eric},
date-added = {2021-05-16 19:43:59 -0400},
date-modified = {2021-05-16 19:43:59 -0400},
journal = {Annual Review of Political Science},
pages = {175--193},
publisher = {Annual Reviews},
title = {On the theory of parties},
volume = {21},
year = {2018},
}
\end{filecontents}
\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage{amsmath}
%%\usepackage{amsfonts} % is loaded automatically by 'amssymb'
\usepackage{amssymb}
\usepackage{titlesec}
\titleformat*{\section}{\normalsize\bfseries}
\titleformat*{\subsection}{\normalsize\bfseries}
\titleformat*{\subsubsection}{\normalsize\bfseries}
\usepackage{hanging}
\usepackage{xcolor}
\usepackage[numbers]{natbib}
\bibliographystyle{apa}
\usepackage{bibentry}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\makeatletter
\let\saved@bibitem\@bibitem
%\let\@bibitem\saved@bibitem
\renewcommand\BR@b@bibitem[2][]{\BR@bibitem[#1]{#2}\BR@c@bibitem{#2}}
\makeatother
\nobibliography*
\begin{document}
\tableofcontents
\bigskip\hrule\bigskip
\section{\texorpdfstring{%
\protect\bibentry{mccarty2018theory}}{%
McCarty and Schickler, 2018, On the theory of parties}}
\cite{mccarty2018theory} \dots
\bigskip\hrule\bigskip
\bibliography{test}
\end{document}