# How can I get a question's difficulty to be typeset in the question's heading?

In his excellent exsheets package, cgnieder explains how to define custom dividing concepts, such as question difficulty. After difficulty has been as a new dividing concept, each question can be attributed a certain difficulty value, such as, for example, basic, intermediate, advanced, insanely hard, etc. Questions of a given difficulty can then be shown/hidden very easily (as in my code below).

What I would like is for a question's difficulty to be typeset in the question's heading.

That way, I could, for example, tell my students that they should be comfortable with all basic questions, and that they should make an attempt at insanely hard questions only if they like a real challenge.

As far as I know, none of the headings instances defined in subsection 19.2 of the exsheets documentation allow for dividing concepts to be printed somewhere in a question's heading. Is there an easy way of doing that?

% adapted from subsection 12.3 in the exsheets manual
\documentclass{article}

\usepackage{exsheets}
\DeclareQuestionClass{difficulty}{difficulties}
\SetupExSheets{use-difficulties={easy,hard}}

\begin{document}

\begin{question}[difficulty=easy] % I'd like 'easy' to be printed in the heading
An easy question.
\end{question}
\begin{question}[difficulty=medium] % I'd like 'medium' to be printed in the heading
This one’s a bit harder.
\end{question}
\begin{question}[difficulty=hard] % I'd like 'hard' to be printed in the heading
Now let’s see if you can solve this one.
\end{question}

\end{document}


With v0.11 (2013/11/20) you can retrieve the value of a class defined with \DeclareQuestionClass that a question has with the commands \GetQuestionClass{<class>} and \PrintQuestionClassTF{<class>}{<true>}{<false>}. While the first simply expands to the value (or nothing if the value is empty or doesn't exist) the second on either expands to <true> or <false>. In the <true> branch #1 will be replaced by the actual value. You can then do something like

\documentclass{article}

\usepackage{exsheets}
\DeclareQuestionClass{difficulty}{difficulties}

join = { title[r,B]number[l,B](.333em,0pt) } ,
attach = {
main[l,vc]title[l,vc](0pt,0pt) ;
main[r,vc]points[l,vc](\marginparsep,0pt)
} ,
number-post-code = {%
\PrintQuestionClassT{difficulty}{ (#1)}%
}
}

\SetupExSheets{
use-difficulties={easy,hard} ,
}

\begin{document}

\begin{question}[difficulty=easy]
An easy question.
\end{question}
\begin{question}[difficulty=medium]
This one’s a bit harder.
\end{question}
\begin{question}[difficulty=hard]
Now let's see if you can solve this one.
\end{question}

\end{document}


With version prior to v0.11 the code below can be used and gives the same output as the one above.

The newly defined class and it's value is saved for each question in an internal variable \l__exsheets_questions_<class>_tl. It can be used in a custom headings instance:

\documentclass{article}

\usepackage{exsheets}
\DeclareQuestionClass{difficulty}{difficulties}

\ExplSyntaxOn
join = { title[r,B]number[l,B](.333em,0pt) } ,
attach = {
main[l,vc]title[l,vc](0pt,0pt) ;
main[r,vc]points[l,vc](\marginparsep,0pt)
} ,
number-post-code = {
\tl_if_blank:VF \l__exsheets_questions_difficulty_tl
{
\space
( \tl_use:N \l__exsheets_questions_difficulty_tl )
}
}
}
\ExplSyntaxOff

\SetupExSheets{
use-difficulties={easy,hard} ,
}

\begin{document}

\begin{question}[difficulty=easy]
An easy question.
\end{question}
\begin{question}[difficulty=medium]
This one’s a bit harder.
\end{question}
\begin{question}[difficulty=hard]
Now let's see if you can solve this one.
\end{question}

\end{document}


Note: since the variable is an internal one it may be that it is not available any more in future versions of exsheets. Then the code proposed at the beginning of my answer should be used.

• Thanks! That will do the trick for now. Have you considered making newly defined class values more readly accessible in a future release of exsheets? It would be a nice feature. – jub0bs Nov 18 '13 at 15:36
• @Jubobs I'll think of something :) – clemens Nov 18 '13 at 16:33
• Keep up the good work. That exsheets package of yours is great! – jub0bs Nov 18 '13 at 16:39
• @Jubobs Glad to hear that it proves useful :) – clemens Nov 18 '13 at 17:18
• @Jubobs I added something to exsheets. The new version should be available on CTAN and in TeX Live in a few days. – clemens Nov 20 '13 at 10:22