2

I am facing a strange problem while using the enumitem and answers packages. The following code compiles with no errors.

\documentclass{article}
\usepackage{enumitem}    
\usepackage{answers}
\Newassociation{sol}{Solution}{ans}

\newlist{question}{enumerate}{1}
\setlist[question,1]{label=\arabic*}

\begin{document}

\Opensolutionfile{ans}
\section{Problems}

\begin{question}
\item Question 1 \begin{sol}Solution 1\end{sol}
\end{question}

\Closesolutionfile{ans}

\section{Solutions}
\input{ans}

\end{document}

However, whenever I try to style the label in the list, answers throws a TeX capacity exceeded, sorry error.

\documentclass{article}
\usepackage{enumitem}    
\usepackage{answers}
\Newassociation{sol}{Solution}{ans}

\newlist{question}{enumerate}{1}
\setlist[question,1]{label=\textbf{\arabic*}}

\begin{document}

\Opensolutionfile{ans}
\section{Problems}

\begin{question}
\item Question 1 \begin{sol}Solution 1\end{sol}
\end{question}

\Closesolutionfile{ans}

\section{Solutions}
\input{ans}

\end{document}

Surely there must be a way to use these packages together?

  • 1
    Please edit your MWE so they can be compiled without having to add anything. Thee is no document class in these examples. – daleif Jul 1 '15 at 13:20
  • I can confirm this – user31729 Jul 1 '15 at 14:52
  • Apologies, I have fixed this. – Steven Jul 2 '15 at 7:57
2

The answers package does an automatic definition of the solution environment numbering/heading, defining \Solutionlabel, basically to be \emph{Solution #1}, #1 being fed with \textbf --- which is wrong for another reason (due to the label=\arabic* way of enumitem, this can't work this way. Use label={\bfseries \arabic*} rather.

The trick is to redefine the \Solutionlabel to use the same labeling style, but this actually tedious, since it requires to define the list labelling and the solution label.

I recommend an question environment being theoremlike instead of an enumeration list.

\documentclass{article}


\usepackage{answers}
\usepackage{enumitem}

\Newassociation{sol}{Solution}{ans}


\newlist{question}{enumerate}{1}
\setlist[question,1]{label={\bfseries \arabic*}} % defines questioni counter

\renewcommand{\Solutionlabel}[1]{\bfseries Solution \arabic{questioni}}

\begin{document}

\Opensolutionfile{ans}
\section{Problems}

\begin{question}
\item Question 1 \begin{sol}Solution 1 -- finally\end{sol}
\end{question}

\Closesolutionfile{ans}

\section{Solutions}
\input{ans}

\end{document}

enter image description here

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.