1

I know how to add questions to the Table of Contents using exsheets key questions-totoc.

I would like the Table of Contents to have question subtitles, so my students (and I) know what the questions are about at a glance.

How can I add subtitles to the ToC?

\documentclass{article}
\usepackage{exsheets}

\SetupExSheets{
    headings=block-subtitle,
    questions-totoc=true,
    question/name=Question
}

\begin{document}

\tableofcontents

\begin{question}[subtitle=Gradient Vector]
\end{question}

\begin{question}[subtitle=Optimization]
\end{question}

\begin{question}[subtitle=Optimization with Constraints]
\end{question}

\begin{question}[subtitle={Proving Second Derivative Test for $f(x,y)$}]
\end{question}

\end{document}

enter image description here

One idea I had was to use \IfQuestionSubtitleTF to conditionally add to the current ToC line. However, I don't know how to add to the current ToC line.

2

Would this work for you?

\documentclass{article}
\usepackage{exsheets}

\def\questionName{Question}

\SetupExSheets{
    headings=block-subtitle,
    %questions-totoc=true,
    question/name=\questionName
}
\newcommand{\QtoToC}[2]{
    \begin{question}[subtitle=#1]
     #2
     \addcontentsline{toc}{subsection}{\questionName\space\thequestion. \emph{#1}}
    \end{question}
    }

\begin{document}

    \tableofcontents

    \QtoToC{Gradient Vector}
         {} % <- the Q body goes here

    \QtoToC{Optimization}
         {}

    \QtoToC{Optimization with Constraints}
         {}

    \QtoToC{{Proving Second Derivative Test for $f(x,y)$}}
         {}

    \QtoToC{}% Q without subtitle
         {}

\end{document}

result

Edit:

Based on his comment, this is what I think @clemens would use: :)

\documentclass{article}
\usepackage{exsheets}

\def\questionName{Question}

\SetupExSheets{
    headings=block-subtitle,
    question/name=\questionName,
    question/pre-hook = \addcontentsline{toc}{subsection}{
        \questionName\space\thequestion. \IfQuestionSubtitleT{\emph{\GetQuestionProperty{subtitle}{\CurrentQuestionID}}}
        }
    }

\begin{document}

    \tableofcontents

    \begin{question}[subtitle=Gradient Vector]
    \end{question}

    \begin{question}[subtitle=Optimization]
    \end{question}

    \begin{question}[subtitle=Optimization with Constraints]
    \end{question}

    \begin{question}[subtitle={Proving Second Derivative Test for $f(x,y)$}]
    \end{question}

     \begin{question}
     \end{question}

\end{document}
  • I'd rather use the question hooks instead of putting the environment in a new macro... – clemens Nov 13 '15 at 17:49
  • @clemens I edited my answer to include your suggestion, thanks. I admit I tend to hide repeating environment calls (saves screen real estate & highlight distraction => "concentrate on the content"). – alwaysask Nov 13 '15 at 20:24
  • Are you saying you never use environments (which not only are core construct of LaTeX but also do serve a very good purpose having semantics in mind)? – clemens Nov 13 '15 at 21:22
  • @clemens No, I just hide them in macros (if possible) if I have to call them too often (dozens times) - as the OP MWE suggests. – alwaysask Nov 13 '15 at 21:33
  • Thanks both. I certainly prefer the hook version ... I'd rather use question as the environment, to make questions easier to reuse between different exsheets documents. – Chris Chudzicki Nov 14 '15 at 4:14

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.