6

I can disable reference sorting globally using the nosort or the compress package options, that's described in the docs. The same chapter explains how to disable compression for one instance of \cref. But it doesn't mention how to disable sorting for one instance.

MWE:

\documentclass[12pt,a4paper]{article}
\usepackage{cleveref}

\begin{document}

\section{Foo}
\label{sec:foo}

\subsection{Bar}
\label{sec:foo.bar}

\section{Refs}
Check \cref{sec:foo.bar,sec:foo}

\end{document}

Output is "See sections 1 and 1.1", but I would like "See sections 1.1 and 1".

Elrond
  • 485

1 Answers1

6

Just set temporarily to false the conditional \if@cref@sort:

\documentclass[12pt,a4paper]{article}
\usepackage{cleveref}

\makeatletter
\DeclareRobustCommand{\crefnosort}[1]{%
  \begingroup\@cref@sortfalse\cref{#1}\endgroup
}
\makeatother

\begin{document}

\section{Foo}
\label{sec:foo}

\subsection{Bar}
\label{sec:foo.bar}

\section{Refs}
Check \crefnosort{sec:foo.bar,sec:foo}

\end{document}

enter image description here

The \DeclareRobustCommand is a precaution in case the command finds its way in a \caption.

egreg
  • 1,121,712