2

My \cite{} command doesn't seem to work as expected while my bibliographical references are correctly set. How could I fix that? Could you please tell me if I didn't forget something anywhere? This is my MWE:

    \documentclass[a4paper,12pt,twoside]{book}
    \usepackage{mathptmx}
    \setcounter{secnumdepth}{3}
    \setcounter{tocdepth}{3}
    \usepackage{setspace}
    \usepackage[left=4.5cm,right=4.5cm,top=5cm,bottom=5cm]{geometry}
    \onehalfspacing
    \usepackage[frenchb]{babel}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{tocloft}
    \renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters
    \usepackage[numberedbib,nosectionbib]{apacite}
    \usepackage[makeindex]{imakeidx}
    \makeindex[name=npr, title=Index des noms cités] 
    \makeindex[name=mat, title=Index des matières]
    \begin{filecontents}{mybib.bib}
@book{Tufte2002,
 author = {Tufte, Blabla},
 year = {2002},
 title = {A title},

} \end{filecontents}

\usepackage{hyperref}
\begin{document}
\title{A title}

\maketitle


\renewcommand{\contentsname}{Table}
\tableofcontents

\chapter{A title}

\cite{Tufte2002}

\bibnewpage 
{%start grouping
  \doublespacing % <====================================================
  \raggedright 
  \nocite{}
  \bibliographystyle{apacite} 
    \bibliography{mybib}
}%end grouping

\phantomsection
\cleardoublepage
\printindex[npr] 
\addcontentsline{toc}{chapter}{Index des noms cités}
\printindex[mat]
\addcontentsline{toc}{chapter}{Index des matières}

\end{document}

domi
  • 1,473
  • Load apacite after hyperref. – leandriis Dec 27 '20 at 15:12
  • It probably doesn't have anything to do with your immediate problem, but \nocite{} looks wrong. If you want to add all entries from the .bib file to the bibliography, you want to use \nocite{*}. I would remove the \nocite{}, but I should stress again that this probably won't resolve the problem at hand. – moewe Dec 27 '20 at 17:28
  • 2
    It would help a lot if you could describe in more detail how the \cite commands don't work for you after you applied the changes suggested in the answer below. Do you get error messages (if so, what do the messages say)? Does the output look wrong (if so, what output do you get, what do you expect instead)? ... – moewe Dec 27 '20 at 17:29

1 Answers1

3

Further reducing the MWE results in the following example code that upon compiling twice results in the following error message:

\documentclass{book}

\usepackage[numberedbib,nosectionbib]{apacite} \usepackage{hyperref}

\begin{filecontents}{mybib.bib} @book{Tufte2002, author = {Tufte, Blabla}, year = {2002}, title = {A title},

} \end{filecontents}

\begin{document}

\cite{Tufte2002}

\bibliographystyle{apacite} \bibliography{mybib}

\end{document}


Undefined control sequence.
\hyper@@link ->\let \Hy@reserved@a 
                                   \relax \@ifnextchar [{\hyper@link@ }{\hyp...
l.17 \cite{Tufte2002}

This can be solved by inverting the load order of apacite and hyperref, loading apacite after hyperref.

This is also mentioned in the apacite manual:

The hyperref package turns (cross-) references into hypertext links. This can beused in conjunction with a program such as LATEX2HTML to compose .html files with clickable links, to internet pages or within the same document, or it can be used to create a .pdf document with clickable crossreferences. Evidently, citations are also references. Therefore, the hyperref package transforms these into hypertext links as well, and needs to redefine the citation commands and reference list commands in order to do so. These redefinitions have caused severe incompatibility problems between apacite and hyperref in the past. These incompatibility problems have been solved and apacite is compatible with hyperref, provided that apacite is loaded after hyperref.

leandriis
  • 62,593
  • It doesn't work. – domi Dec 27 '20 at 16:51
  • Waht does "it does not work" mean specifically? According to my tests, my suggestion works both with my example code, as well as with the original example from your question. Do you still get the same error messages? – leandriis Dec 27 '20 at 18:34
  • After compiling, even several times, the year of the book quoted doesn't appear in the text body. – domi Dec 28 '20 at 13:12
  • Which example code did you use? The exact one from my answer? Did you also make sure, to load apacite after hyperref (not the case in the example code in my question since I originally wanted to show a more minimal example that still produces the issue)? Do you get any error messages? Of so, which? – leandriis Dec 28 '20 at 13:15
  • No, no, excuse-me: it works. I just didn't load Apacite after Hyperref. But when I compile my whole document, it doesn't work anymore. – domi Dec 28 '20 at 17:49