Anonymous 1123
I use answers package like this

\documentclass[12pt,a4paper]{report}
\usepackage{amsthm,amsfonts,amssymb,amsmath}
\theoremstyle{definition}
\Newassociation{sol}{Solution}{ans}
\newtheorem{ex}{Exercise}[chapter]
\begin{document}
\chapter{Try}
\Opensolutionfile{ans}[ans1]
\section{Problems}
\begin{ex}
First exercise
\begin{sol}
First solution.
\end{sol}
\end{ex}
\begin{ex}
Second exercise
\begin{sol}
Second solution.
\end{sol}
\end{ex}
\Closesolutionfile{ans}
\section{Solutions}
\input{ans1}
\end{document}


![ScreenHunter 1075.png](/image?hash=20628d3c9374e5d262bd6ede6c0e0c2fdb7ed21e31b8f33af4b9b81de1eb82d5)

Somtimes, I do not show solutions of exercises. I know, there is a command
\usepackage[nosolutionfiles]{answers}
In manual write "If the optional argument is given, solutions appear at that point in the text, rather than being written to external files".
Is there a key to on or off  solutions of exercises automatically. That is mean, when I use "off", I do not see solutions at all document, and if I use "on", I see solutions.
samcarter
You can add your own if statement to switch on/off the solutions. In the following example, they will be off by default. Use \solutionstrue to switch them on or \solutionsfalse for off again.


\documentclass[12pt,a4paper]{report}
\usepackage{amsthm,amsfonts,amssymb,amsmath}

\newif\ifsolutions
%\solutionstrue % comment this line for no solutions

\theoremstyle{definition}
\Newassociation{sol}{Solution}{ans}
\newtheorem{ex}{Exercise}[chapter]
\begin{document}
\chapter{Try}
\Opensolutionfile{ans}[ans1]
\section{Problems}
\begin{ex}
First exercise
\begin{sol}
First solution.
\end{sol}
\end{ex}
\begin{ex}
Second exercise
\begin{sol}
Second solution.
\end{sol}
\end{ex}
\Closesolutionfile{ans}
\ifsolutions
\section{Solutions}
\input{ans1}
\fi
\end{document}


(you could even use something like https://topanswers.xyz/tex?q=583 to automatically compile both versions)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.