I am writing a document that has several major sections, and each section will have some exercises and solutions. I am using the exsheets package, which seems to do almost everything I want. However, I'm puzzled about how to get my numbering and references to work the way I want. I would like the question numbers to be S.Q where S is the section # and Q the question #. I've used the counter-format and counter-within-section options to do that, and it looks like what I want in the document. The only problem is that I would like to be able to refer to the exercises by these numbers, but if I use a label in the question the counter only seems to keep track of Q. I can get the effect I want by using multiple references, for example \ref{s:seclabel}.\ref{q:exlabel}
. But this seems clunky, and I have to look up the section label every time. I would have expected that when I set the counter-within
option it would also make the reference numbers work the way I want, but it doesn't seem to. Is there a better way to do this than my hacky one?
I've included a MWE that uses the solution I came up with, so you can see what I would like it to do. The key part is the references in section 2. In the MWE, I also refer to a subpart of one question, which requires three separate references. To be honest, I'm not sure I would ever need to do this, and I suspect it's even trickier since I have a separate enumerate environment. But if anyone can come up with a general solution that deals with this also, that would be even better.)
\documentclass[11pt]{article}
\usepackage[counter-format=se.qu,counter-within=section]{exsheets}
\usepackage{enumitem}
\begin{document}
\section{First Section}
\label{s:first}
\subsection{Introduction}
Here's some text.
\subsection{Explanation}
And some more.
\subsection{Exercises}
\begin{question}\label{q:first}
Suppose I have ...
\begin{enumerate}[label=\alph*)]
\item What is ... \label{q:firstsub}
\item Now compute ...
\end{enumerate}
\end{question}
\begin{solution}
\begin{enumerate}[label=\alph*)]
\item Answer to first subpart
\item Answer to second subpart
\end{enumerate}
\end{solution}
\begin{question}\label{q:second}
Now I have ... What is ...
\end{question}
\section{Second Section}
\label{s:second}
\subsection{Some text}
Here I have an example that refers back to Exercise
\ref{s:first}.\ref{q:first}. I {\em might} even want to refer to
Exercise \ref{s:first}.\ref{q:first}\ref{q:firstsub} although that is
less important.
\subsection{Exercises}
\begin{question}\label{q:later}
And here's more...
\begin{enumerate}[label=\alph*)]
\item What is ...
\item Now compute ...
\end{enumerate}
\end{question}
And perhaps now I refer to Exercise \ref{s:second}.\ref{q:later}.
\end{document}