1

When using the cite, bibuints, and hyperref packages together, there are no links from citations to the references list. How can I get the links to exist while keeping the default cite citation sorting and my customization on citepunct? Here's my MWE (you'll need your own "refs.bib" file with article1 and article2 entries):

\documentclass{report}
\usepackage{cite}
\usepackage{bibunits}
\usepackage{hyperref}

\renewcommand\citepunct{], [} \renewcommand\citedash{]--[}

\begin{document}

\chapter*{Executive Summary} \begin{bibunit}[ieeetr] Second article~\cite{article2}. \putbib[refs] \end{bibunit}

\chapter{A Chapter} First article~\cite{article1}. Second article~\cite{article2}. Both articles~\cite{article2,article1}.

\bibliographystyle{ieeetr} \bibliography{refs} \end{document}

I found similar questions on TeX StackExchange ([1], [2], [3]) that provide a solution to users using the natbib package, but these only partially work with cite. Specifically, when I apply the code from both answers in [1], the links work but I lose the custom citepunct rendering and the automatic sorting that cite performs when citing multiple references in the same \cite{} command. As such, \cite{article2,article1} renders as "[2, 1]" instead of the "[1], [2]" that my school requires. How can I overcome this? Thank you.

EDIT: My school uses a custom .bst (BibTeX style) file so I do not have the option of switching to BibLaTeX and Biber.

possum
  • 125
  • 1
    why don't you use biblatex + biber? They support hyperref out of the box. – Ulrike Fischer Mar 11 '24 at 17:05
  • Good point, @UlrikeFischer. Unfortunately, I'm stuck with needing to use my school's custom .bst file. It is similar to the ieeetr style so I just used that in my MWE to keep it minimal. I updated the question to incorporate this aspect. Thank you. – possum Mar 11 '24 at 17:42
  • 1
    I something stopping you from (a) changing \usepackage{cite} to \usepackage[numbers,square]{natbib} and (b) writing \cite{article1}, \cite{article2} to generate [1], [2]? BTW, your school's formatting requirements for citation call-outs are insane. I'm sure you're aware of this. – Mico Mar 11 '24 at 19:43
  • I tried @Mico's suggestion. For (a), I found no ability to redefine the natbib equivalent of cite's citedash; it's hard-coded on line #416 of natbib.sty (v. 8.31b) so I would need to branch natbib. This affects having >2 citations appearing consecutively in the references list. For (b), I would need to sort all my multiple cites manually. Alternatively, I got the right citepunct with package options numbers,square,sort&compress, \setcitestyle{citesep={], [}}, and redefining \NAT@spacechar{}. It's doable once but not for improving the school's template, which I'd like to do. – possum Mar 11 '24 at 21:24
  • Thank you to @Mico for this idea. An hour later, I thought of etoolbox's \patchcmd, tested it, and found that worked! I probably would not have figured this out today without your help. Thank you! – possum Mar 11 '24 at 22:51

1 Answers1

1

Thank you to an idea from @Mico in the comments of the initial question, that is, to replace cite with natbib, which necessitated some deep (but not wide) customization of natbib (v. 8.31b). The trick was in overcoming natbib's lack of hooks to modify attributes that cite calls citepunct and citedash. In natbib, using \setcitestyle to modify citesep was not enough to have the same effect as cite's citepunct because natbib always follows citesep with a space (\ , to be exact). Thus, I also had to redefine \NAT@spacechar from {\ } to {}. The citedash was the only hard-coded aspect so I used etoolbox's \patchcmd to replace the -- with a ]--[.

Here's the updated MWE with the solution:

\documentclass{report}
\usepackage{etoolbox}
\usepackage[numbers,square,sort&compress]{natbib}
    \setcitestyle{citesep={], [}}
    \makeatletter
            \renewcommand\NAT@spacechar{}
            \patchcmd{\NAT@citexnum}{--}{]--[}{}{}
    \makeatother
\usepackage{bibunits}
\usepackage{hyperref}

\begin{document}

\chapter*{Executive Summary} \begin{bibunit}[ieeetr] Second article~\cite{article2}. \putbib[refs] \end{bibunit}

\chapter{A Chapter} First article~\cite{article1}. Second article~\cite{article2}. Both articles~\cite{article2,article1}. All articles~\cite{article2,article1,article3}.

\bibliographystyle{ieeetr} \bibliography{refs} \end{document}

This is an answer to the question, "How can I keep the same citation style while overcoming the apparent conflict between the cite, bibunits, and hyperref packages that prevents the citation links to the references list from working?"

possum
  • 125