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}
Name
  • 2,816

1 Answers1

2

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}
touhami
  • 19,520