2

I know the correct format to use the solution in answers package is the following:

\begin{ex}
   First exercise
 \begin{sol}
   First solution.
\end{sol}

\end{ex}

But when the statement of the exercise and its solution are very long the following format has advantage:

\begin{ex}
   First exercise
\end{ex}

 \begin{sol}
   First solution.
\end{sol}

But the problem is that with this format the numbering of the exercises becomes incorrect.

My question is that is there any way that this form works with answers package (probably by changing some settings in answers package)?

\documentclass{article}
\usepackage{answers}
\renewcommand{\solutionstyle}[1]{\bfseries Answer to Exercise #1 }
\Newassociation{sol}{Solution}{ans}
\newtheorem{ex}{Exercise}

\begin{document}
\Opensolutionfile{ans}[ans1]

\section{One }

\section{two}
\begin{ex}
   First exercise
\end{ex}

 \begin{sol}
   First solution.
\end{sol}

\Closesolutionfile{ans}
\section{Solutions}
\input{ans1}
\end{document}
  • 1
    try add \renewcommand{\Currentlabel}{\theex} – touhami Mar 23 '17 at 17:58
  • @touhami It seems that your suggestion solves my problem. Please consider to convert your comment to an answer if you like. – Name Mar 23 '17 at 19:02
1

Here is a solution \renewcommand{\Currentlabel}{\theex}

MWE

\documentclass{article}
\usepackage{answers}
\renewcommand{\solutionstyle}[1]{\bfseries Answer to Exercise #1 }
\renewcommand{\Currentlabel}{\theex}
\Newassociation{sol}{Solution}{ans}
\newtheorem{ex}{Exercise}

\begin{document}
\Opensolutionfile{ans}[ans1]

\section{One }

\section{two}
\begin{ex}
   First exercise
\end{ex}

 \begin{sol}
   First solution.
\end{sol}

\Closesolutionfile{ans}
\section{Solutions}
\input{ans1}
\end{document}

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.