1

I've tried solutions posted in here, here, and other relevant posts to no avail. I'm trying to use hyperref in document that uses natbib and bibentry, but it gives me tons of errors. The major difference between my issue and others posts is that I'm using bibentry in a section heading, in which I had to use \protect to make it work.

Please see my code below:

\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}

Diana
  • 11
  • Did you try \section[Alternative Section Title]{\protect\bibentry{mccarty2018theory}}? I believe hyperref will just get into massive trouble trying to make a bookmark out of this section title. – Manuel Weinkauf Jun 30 '21 at 16:39
  • Welcome to TeX.SE. – Mico Jun 30 '21 at 17:10
  • @ManuelWeinkauf - Your intuition was correct. However, what needs to be fixed is not the optional argument of \section but the material that has to go into the bookmarks column. – Mico Jun 30 '21 at 17:11

1 Answers1

1

The issue you're encountering is caused by the fact that the argument of \section far exceeds hyperref's ability to create an associated bookmark. You need to employ the \texorpdfstring macro as the argument of \section -- and make sure that the second argument of \texorpdfstring isn't too complicated. In fact, I would keep that second argument as simple as possible while still being sufficiently informative. E.g., McCarty and Schickler, 2018, On the theory of parties.

enter image description here

\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}

Mico
  • 506,678