# The usepackage notoccite does not work

I have used notoccite to avoid getting citations in my caption to be numbered first but to follow the rest of the document. Unfortunately this does not work. Does any one know what I can do to overcome this problem or does any one know which package to use instead of notoccite ( I have tried \protect\cite)? I do not know if some of my code interferes with the \usepackage{notoccite}. My code is:

\documentclass[a4paper,12pt, twoside]{report}
\renewcommand{\baselinestretch}{1.15}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr,lipsum}

\usepackage{cite}
\usepackage{hyperref}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{notoccite}

\makeatletter
\vspace*{1\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
%\huge\bfseries \@chapapp\space \thechapter
\Huge\bfseries \thechapter\space%
%\par\nobreak
%\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 20\p@
}}
\vspace*{1\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries  #1\par\nobreak
\vskip 20\p@
}}
\makeatother

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{todonotes}
\usepackage[textfont={rm, it}, labelfont={bf}]{caption}
\usepackage{float}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{url}
\numberwithin{equation}{section}
\newcommand{\degree}{\ensuremath{^\circ}}
\newcommand{\celcius}{\degree{}C}
\usepackage{lastpage}

\usepackage{nomencl}
\usepackage{multirow}
\usepackage{subcaption}
\usepackage{titlesec}
\usepackage{subfiles}
\newcommand{\aar}{\textit{år}}
\usepackage[version=3]{mhchem}
\numberwithin{figure}{section}
\renewcommand\bibname{References}

\usepackage{enumitem}

\usepackage{etoolbox}

\pagestyle{fancy}
\includegraphics[width=0.25\textwidth]{logoside.png}
\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\chaptername\ \thechapter. {##1}}}{}}
}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\arabic{section}.\ #1}}

\begin{filecontents}{\jobname.bib}
@misc{foo,
author = {Foo},
title = {Title of Foo},
}
@misc{bar,
author = {Bar},
title = {Title of Bar},
}
@misc{ba,
author = {Ba},
title = {Title of Ba},
}
\end{filecontents}
\begin{document}
this is the text \cite{foo} and it should be cited first \cite{bar}
\begin{figure} [h]
\centering
\includegraphics[scale=0.65]{A figure}
\caption[the caption in the list of figure]{the caption in the text\cite{ba}}
\label{X}
\end{figure}

\bibliographystyle{unsrt}
\bibliography{\jobname}
\end{document}

• Welcome to TeX.SX! Since there is no list of figures, the package notoccite does nothing. It's not really clear what the problem is. By the way, you're loading hyperref too early: it should be the last loaded package, in your case. – egreg Feb 3 '17 at 16:35
• Thanks. In my original code, there is a list of figures. The problem is that the references in the figures will be numbered first. In fact, will they be numbered first even if I delete the list of figures. :/ – Martine Khataei Notabi Feb 5 '17 at 11:49
• If I add \listoffigures, I get the order “Foo”, “Bar” and “Ba” in the bibliography. – egreg Feb 5 '17 at 13:23

It turns out that notoccite is incompatible with hyperref which undoes the work of the other package.

You can redo it on top of hyperref.

Please, revise the settings related to fancyhdr: redefining \chaptermark in the header is surely wrong.

I reordered your preamble in a more sensible way. Note that hyperref must be last (only a few packages should be loaded after it, none among the ones you use).

\begin{filecontents}{\jobname.bib}
@misc{foo,
author = {Foo},
title = {Title of Foo},
}
@misc{bar,
author = {Bar},
title = {Title of Bar},
}
@misc{ba,
author = {Ba},
title = {Title of Ba},
}
\end{filecontents}

\documentclass[a4paper,12pt, twoside]{report}
\usepackage[utf8]{inputenc}

\usepackage{fancyhdr}
\usepackage[colorinlistoftodos]{todonotes}

\usepackage{cite}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{array}
\usepackage{graphicx}
\usepackage[textfont={rm, it}, labelfont={bf}]{caption}
\usepackage{float}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{url}
\usepackage{lastpage}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage{nomencl}
\usepackage{multirow}
\usepackage{subcaption}
\usepackage{titlesec}
\usepackage{subfiles}
\usepackage[version=3]{mhchem}

\usepackage{hyperref}

\makeatletter
% do the same as notoccite on top of the redefinitions by hyperref
\AtBeginDocument{%
\patchcmd{\@starttoc}{\begingroup}{\begingroup\@fileswfalse}{}{}%
\patchcmd{\@starttoc}{\if@filesw}{\endgroup\begingroup\if@filesw}{}{}%
}
\makeatother

\makeatletter
\vspace*{1\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
%\huge\bfseries \@chapapp\space \thechapter
\Huge\bfseries \thechapter\space%
%\par\nobreak
%\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 20\p@
}}
\vspace*{1\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries  #1\par\nobreak
\vskip 20\p@
}}
\makeatother

\numberwithin{equation}{section}
\newcommand{\degree}{\ensuremath{^\circ}}
\newcommand{\celcius}{\degree{}C}
\newcommand{\aar}{\textit{år}}
\numberwithin{figure}{section}
\renewcommand\bibname{References}

\pagestyle{fancy}

% the following is very wrong
%\includegraphics[width=0.25\textwidth]{logoside.png}
%\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\chaptername\ \thechapter. {##1}}}{}}
%}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\arabic{section}.\ #1}}

% the following is very wrong

\begin{document}

\listoffigures

this is the text \cite{foo} and it should be cited first \cite{bar}
\begin{figure} [h]
\centering
\includegraphics[width=4cm]{example-image}
\caption{the caption in the text \cite{ba}}
\label{X}
\end{figure}

\bibliographystyle{unsrt}
\bibliography{\jobname}

\end{document}