4

When using the cite package, how can I stop just one citation from being sorted automatically? In

\documentclass{article}

\usepackage[nocompress,space]{cite}
\usepackage{hyperref}

\begin{document}

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

Do not sort this: \cite{2,3,1}. %print "[2, 3, 1]"

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

\begin{thebibliography}{9}

\bibitem{1}
\bibitem{2}
\bibitem{3}

\end{thebibliography}

\end{document}

I would like the middle citation to print as "[2, 3, 1]", but the first and last citations to print as "[1, 2, 3]". Also, I know I'll be using the hyperref package and the nocompress and space options of cite.

EDIT: FYI, looking in cite.sty, I tried defining a \citenosort command and using it for the citation I don't want to be sorted:

\documentclass{article}

\usepackage[nocompress,space]{cite}
\usepackage{hyperref}

\makeatletter
\newcommand{\citenosort}[1]{\begingroup\def\@addto@cite@list{\@cite@dump@now}\cite{#1}\endgroup}
\makeatother

\begin{document}

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

Do not sort this: \citenosort{2,3,1}. %print "[2, 3, 1]"

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

\begin{thebibliography}{9}

\bibitem{1}
\bibitem{2}
\bibitem{3}

\end{thebibliography}

\end{document}

It seems to work in my example, but I don't know what side effects it might have. Obviously my command can't have an optional argument.

Mico
  • 506,678
MSC
  • 2,722

2 Answers2

5

Print the cites independently:

\documentclass{article}

\usepackage[nocompress,space]{cite}
\usepackage{hyperref}

\begin{document}

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

Do not sort this: \citeleft\citen{2}\citepunct\citen{3}\citepunct\citen{1}\citeright. %print "[2, 3, 1]"

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

\begin{thebibliography}{9}

\bibitem{1}
\bibitem{2}
\bibitem{3}

\end{thebibliography}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
3

You seem to want the original \cite command available; this requires some hackery.

\documentclass{article}

\makeatletter % save the original \@citex command
\let\latex@citex\@citex
\makeatother

\usepackage[nocompress,space]{cite}
\usepackage{hyperref}

\makeatletter % define \citenosort as the original \cite
\DeclareRobustCommand{\citenosort}{%
  \@ifnextchar[{\@tempswatrue\latex@citex}{\@tempswafalse\latex@citex[]}%
}
\begin{document}

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

Do not sort this: \citenosort{2,3,1}. %print "[2, 3, 1]"

Sort this: \cite{2,3,1}. %print "[1, 2, 3]"

\begin{thebibliography}{9}

\bibitem{1}

\bibitem{2}

\bibitem{3}

\end{thebibliography}

\end{document}

enter image description here

egreg
  • 1,121,712