3

With the exsheets package, I'm defining a new question type that should be distinguished by having a coloured number. The following MWE throws the error message "Use of \SaveCounterPattern doesn't match its definition". But – accidental discovery – when I include the siunitx package (which I don't actually want/need), the error disappears. Is there a better way to set up the color so I don't need to include siunitx? (Or even just a good reason why siunitx 'fixes' things?)

\documentclass{article}

\usepackage{color}
%\usepackage{siunitx}

\usepackage{exsheets}

\NewQuSolPair
    {questionqr}[name=QR Question,pre-hook={\SetupExSheets{counter-format=
    {\color{blue}qu[1]}}},post-hook={\SetupExSheets{counter-format={qu[1]}}} ]
    {solutionqr}[name=QR Solution]          

\begin{document}

\begin{question}
    First question.
\end{question}

\begin{questionqr}
    Second question.
\end{questionqr}

\end{document}
0

2 Answers 2

3

Add \robustify\color to your preamble (\robustify is defined in the etoolbox package which is loaded by exsheets)

\documentclass{article}

\usepackage{color,etoolbox} % etoolbox is loaded by exsheets anyway
\robustify\color

\usepackage{exsheets}

\NewQuSolPair
    {questionqr}[name=QR Question,pre-hook={\SetupExSheets{counter-format=
    {\color{blue}qu[1]}}},post-hook={\SetupExSheets{counter-format={qu[1]}}} ]
    {solutionqr}[name=QR Solution]          

\begin{document}

\begin{question}
    First question.
\end{question}

\begin{questionqr}
    Second question.
\end{questionqr}

\end{document}

enter image description here


Using exsheets' successor xsim:

\documentclass{article}

\usepackage{xcolor}
\usepackage{xsim}

\DeclareExerciseType{QR}{
  exercise-env      = questionqr ,
  solution-env      = solutionqr ,
  exercise-name     = QR Question ,
  solution-name     = QR Solution ,
  counter           = exercise , % <<< leave away if the new type should be
                                 % numbered independently
  exercise-template = bluenumber ,
  solution-template = bluenumber
}

\DeclareExerciseEnvironmentTemplate{bluenumber}
  {%
    \subsection*
      {%
        \GetExerciseName\nobreakspace
        \textcolor{blue}{\GetExerciseProperty{counter}}%
        \IfInsideSolutionF
          {%
            \GetExercisePropertyT{subtitle}
              { {\normalfont\itshape\PropertyValue}}%
          }%
      }%
  }
  {}

\begin{document}

\begin{exercise}
  First question.
\end{exercise}

\begin{questionqr}
  Second question.
\end{questionqr}

\end{document}

enter image description here

3

Here a "condensed" version of the siunitx package that prevents the error. It seems that siunitx makes \color protected and thus it can be used to colour the question.

\documentclass{article}
\usepackage{exsheets}
\usepackage{xcolor}

\usepackage{expl3}[2015/09/11]
\usepackage{xparse}

\ExplSyntaxOn

\AtBeginDocument {
  \tl_map_function:nN { \color }
    \__siunitx_protect_symbols:N
}
\cs_new_protected:Npn \__siunitx_protect_symbols:N #1 {
   \cs_set_protected:Npx #1 { \exp_not:V #1 } 
}
\ExplSyntaxOff


\NewQuSolPair
    {questionqr}[name=QR Question,pre-hook={\SetupExSheets{counter-format=
    {\color{red}qu[1]}}},post-hook={\SetupExSheets{counter-format={qu[1]}}} ]
    {solutionqr}[name=QR Solution]          

\begin{document}

\begin{question}
    First question.
\end{question}

\begin{questionqr}
    Second question.
\end{questionqr}

\end{document}
3
  • etoolbox's \robustify would also do: \robustify\color
    – cgnieder
    Commented Jun 7, 2017 at 9:24
  • @clemens Interesting! Can you post this as an answer? Commented Jun 7, 2017 at 9:27
  • I did, although I originally thought you could just incorporate it into yours :)
    – cgnieder
    Commented Jun 7, 2017 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .