A desired feature for the latex-templates that we're using for exercises is to give hints in a way that the students have the option of trying to solve the exercise without it (i.e. not directly below the problem formulation).
endnotes (or rather, the newer enotez), seemed like a good starting point for this. However, I'd like the mark of each endnote to be a reference back to the subproblem for which the hint is given. My idea was to automatically label all subproblems with a counter derived from \thesubproblem, and thus reconstruct the right label without having to manually feed the label to the \hint-command I'd like to have (see code below). Unfortunately, I can't manage to:
- expand the reference in the argument of
\endnote - feed any reference into the optional argument (which is responsible for the mark). This is secondary however, because by changing the style and removing the marks, I could just put the reference at the beginning of the body of the hint.
I've looked at a few tex.sx questions (How to expand several arguments in an environment?, When to use \edef, \noexpand, and \expandafter?, etc.), but with no success.
Additionally, I'd like to make use of the splitting into sections that enotez offers, ideally by tricking it into thinking that a new problem belongs to a new section (which I do below with a \section*{} that I'd like to get rid of). I've played around with incrementing the counters and so forth, but this didn't work and my expl3-fu is not good enough to parse what enotez.sty is actually doing.
Here's my sample code:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{etoolbox}
\usepackage{enotez}
\usepackage[colorlinks]{hyperref}
\makeatletter
\setenotez{
list-name=Hints,
list-style=section,
mark-cs=\@gobble,
split=section,
split-title={Hints for Problem <ref>}
}
\makeatother
\DeclareInstance{enotez-list}{custom}{list}{number = #1:}
\newcounter{exsheet}
\newcounter{problem}[exsheet]
\newcommand{\exsheet}[1]
{\setcounter{exsheet}{#1}
\begin{center} {\Large Homework Problem Sheet #1} \end{center}
}
\setlength{\parindent}{0pt}
\makeatletter
\renewcommand{\theproblem}{\arabic{exsheet}.\arabic{problem}}
\newcommand{\problem}[2][]{%
% details see tex.stackexchange.com/q/31780
\@startsection{problem}{1}{\z@}{-3.25ex\@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}%
{\large\bfseries Problem~}[\ifstrempty{#1}{#2}{#1}]{#2}}
\let\problemmark\@gobble
\newcounter{subproblem}[problem]
\renewcommand{\thesubproblem}{(\arabic{exsheet}.\arabic{problem}\alph{subproblem})}
\newcommand{\thesp}{\arabic{exsheet}.\arabic{problem}.\arabic{subproblem}}
\newcommand*{\subproblem}{\@startsection{subproblem}{2}{0em}{1ex}{0pt}{\bfseries}{}%
\label{sp.\thesp}}
\let\subproblemmark\@gobble
\makeatother
% % % % % % Help needed here: % % % % % % %
%\newcommand{\hint}[#1]{\endnote[...expansion magic...\ref{sp.\thsp}]{#1}}
\let\thesection\theproblem
\begin{document}
\exsheet{1}
\problem{Test}
\subproblem Text
\subproblem Text\endnote[(1.1b)]{Hint} % call should just be \hint{Hint}
\subproblem Text
\subproblem Text\endnote[(1.1d)]{Hint} %\ref{sp.\thesp} works outside
\section*{Section for splitting endnotes -- shouldn't be here}
\problem{Test}
\subproblem Text\endnote[(1.2a)]{Hint}
\subproblem Text
\subproblem Text
\subproblem Text\endnote[(1.2d)]{Hint}
\vfill % would normally be \newpage
\printendnotes[custom]
\end{document}

enotez. I plan to revise and probably re-implement it one day... I can't when I will find the time, though. Maybe it is easier to use LaTeX's toc-mechansim with a custom list for your task... – cgnieder Jul 09 '14 at 10:09exsheetspackage. If you're interested I'll post something with it later. – cgnieder Jul 09 '14 at 12:03