1

I am trying to use cleveref package to create custom referencing scheme for exercises created using exsheets. I customize cross-referencing of floats and equations very well using codes similar to the one below.

The output of the code below does not show any correct referencing to any question. Even debugging using \SetupExSheets{debug=true} shows that questions have not been tagged.

My source code

\documentclass[]{book}
\usepackage[no-math]{fontspec}

\usepackage{cleveref}

    \crefformat{question}{Question. (#1)}
    \crefrangeformat{question}{Questions. (#1) to (#2)}
    \crefmultiformat{question}{Questions. (#1)}{ and (#1)}{, (#1)}{ and (#1)}
    \crefrangemultiformat{question}{Questions. (#1) to (#2)}{ and (#1) to (#2)}{, (#1) to (#2)}{ and (#1) to (#2)}


\usepackage{exsheets}

\SetupExSheets[points]{format=\bfseries, number-format=\itshape}            
\SetupExSheets{counter-format=\thesection.(qu[A]), counter-within=section}
\SetupExSheets{solution/print=true}
\SetupExSheets{debug=true,auto-label={false},ref-cmd={\cref},label-format={#1}}


\begin{document}


\chapter{My Chapter}



\section{Section 1}

\begin{question}
    \label[question]{qu:1}
    Question
\end{question}

\begin{solution}
    \label[question]{qu:2}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:3}
    Question
\end{question}

\begin{solution}
    \label[question]{qu:4}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:5}
    Question
\end{question}

\begin{solution}
    \label[question]{qu:7}
    Solution
\end{solution}



\section{Section 2}

\begin{question}
    \label[question]{qu:6}
    Question
\end{question}

\begin{solution}
    \label[question]{qu:7}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:8}
    Question
\end{question}

\begin{solution}
    \label[question]{qu:9}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:10}
    Question
\end{question}

\begin{question}
    \label[question]{qu:10}
    Question
\end{question}


\cref{qu:1,qu:2,qu:3,qu:4,qu:5}

\cref{qu:1,,qu:2,,qu:3,,qu:4,,qu:5}

\cref{qu:1,qu:6,qu:9,qu:2,qu:3,qu:4,qu:5,,qu:10}

\end{document}
1

enter image description here

We use \renewcommand{\thequestion}{\thesection.(\Alph{question})}. We can edit the representation as we wish. A more generalized case could be:

\renewcommand{\thequestion}{\the<parent label><type of seperation>(\<type of numbering>{question})}

The definition we write here must match the one we write by counter-format option in \SetupExSheets. Otherwise, the equation tag could be something like 1.3 while \cref output could be 1.III.

\documentclass[]{book}
\usepackage[no-math]{fontspec}

\usepackage[x11names]{xcolor}
\usepackage{exsheets}

\SetupExSheets[points]{format=\bfseries, number-format=\itshape}            
\SetupExSheets{counter-format=\thesection.(qu[A]), counter-within=section}
\SetupExSheets{solution/print=true}
\SetupExSheets{debug=true,auto-label={false},ref-cmd={\cref},label-format={#1}}

\usepackage{hyperref}
\hypersetup{linkcolor=DodgerBlue3, colorlinks=true}

\usepackage{cleveref}

\crefformat{question}{Question #2#1#3}
\crefrangeformat{question}{Questions #3#1#4 to #5#2#6}
\crefmultiformat{question}{Questions #2#1#3}{ and #2#1#3}{, #2#1#3}{ and #2#1#3}
\crefrangemultiformat{question}{Questions #3#1#4 to #5#2#6}{ and #3#1#4 to #5#2#6}{, #3#1#4 to #5#2#6}{ and #3#1#4 to #5#2#6}
\renewcommand{\thequestion}{\thesection.(\Alph{question})}

\begin{document}


\chapter{My Chapter}



\section{Section 1}

\begin{question}
    \label[question]{qu:1}
    Question
\end{question}


\begin{solution}
    \label[solution]{sol:1}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:2}
    Question
\end{question}

\begin{solution}
    \label[solution]{sol:2}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:3}
    Question
\end{question}

\begin{solution}
    \label[solution]{sol:3}
    Solution
\end{solution}



\section{Section 2}

\begin{question}
    \label[question]{qu:4}
    Question
\end{question}

\begin{solution}
    \label[solution]{sol:4}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:5}
    Question
\end{question}

\begin{solution}
    \label[solution]{sol:5}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:6}
    Question
\end{question}

\begin{question}
    \label[question]{qu:7}
    Question
\end{question}

\begin{question}
    \label[question]{qu:8}
    Question
\end{question}

\begin{solution}
    \label[solution]{sol:6}
    Solution
\end{solution}

\begin{question}
    \label[question]{qu:9}
    Question
\end{question}

\begin{solution}
    \label[solution]{sol:7}
    Solution
\end{solution}


\newpage
\cref{qu:1}

\cref{qu:1,qu:2,qu:3}

\cref{qu:4,,qu:5,,qu:6}

\cref{qu:1,qu:2,qu:3,qu:5,qu:6,qu:9}

\cref{qu:2,qu:3,qu:5,qu:6,qu:7,qu:8,,qu:9}

\cref{qu:1,qu:2,qu:3,qu:5,qu:6,qu:7,qu:8,qu:9}


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.