0

I want to create a custom environment to be used with the answers package, something like

 ...
\usepackage{answers}
\Newassociation{solu}{Soln}{ans}
\newtheorem{ex}{Ejercicio}[chapter]
\newenvironment{exer}{\begin{ex}\normalfont}{\end{ex}}

\newenvironment{\exercises}[1]{ 
\bigskip%
\Opensolutionfile{ans}[ans\thechapter]
....
}{ \Closesolutionfile{ans}... }


\begin{document}

....
\begin{exercises}

     \begin{exer} blabla...1
                \begin{sol}
                          blahblah 1
                \end{sol}
     \end{exer}

         \begin{exer} blabla...2
                \begin{sol}
                          blahblah 2
                \end{sol}
     \end{exer}
\end{exercises}

... but I can't do it. Can you help me?

  • 1
    It's advisable that you include a minimal working example (MWE). At least show some form of expected output. – Werner Aug 22 '13 at 2:20
  • it looks like you're trying to open a new answer file for every chapter... depending on the number of chapters, this could get tricky- TeX has quite a small limit to the number of files it can write to – cmhughes Aug 22 '13 at 3:24
  • yes that is my goal, I trying to open a new answer file for every chapter – wmora2 Aug 22 '13 at 4:02
1

The solution is easy, as we can see:

\documentclass{book}
\usepackage[centering,text={18cm,22cm},showframe=false]{geometry}
\setcounter{chapter}{0}

\usepackage{amsmath,amssymb,amsfonts,latexsym}
\usepackage{xparse}
\usepackage{tcolorbox}        
\tcbuselibrary{skins,breakable} 


\usepackage{answers}
\newtheorem{exer}{}[chapter]
\newenvironment{ejer}{\begin{exer}\normalfont}{\end{exer}}
\Newassociation{solu}{Soln}{ans}

% box---------------------------------------------------------------
\colorlet{color1}{gray!5!white}
\definecolor{color2}{RGB}{117,184,68} 

\newtcolorbox{wwlistaejercicios}[1][]{%
arc=0mm,breakable,enhanced,colback=color1,boxrule=0pt,top=8mm, 
enlarge top by=\baselineskip/2+1mm, enlarge top at break by=0mm,pad at break=2mm,fontupper=\normalsize,
overlay ={
\node[rectangle, minimum width=4cm, top color=color2, bottom color=color2, 
inner sep=1mm,anchor=west,font=\normalsize] at ([xshift=0pt,yshift=-3mm]frame.north west)%
{\textbf{Ejercicios}};}#1}

% Custom environment--------------------------------------------------
\NewDocumentEnvironment{ejercicios}{O{}}{%
\bigskip\begin{wwlistaejercicios}%
\expandafter\ifx\csname Closesolutionfile\endcsname \relax\else
\Closesolutionfile{ans}\fi
\Opensolutionfile{ans}[ans\thechapter]
 #1}{\end{wwlistaejercicios}\bigskip } % 
% Close ans
\def\soluciones{
\expandafter\ifx\csname Closesolutionfile\endcsname \relax\else
\Closesolutionfile{ans}\fi
}
% Include ans#i for chapter i
\def\solucionesCap#1{\section*{Soluciones del Cap\'{\i}tulo #1}\input{ans#1}}

%----------------------------------------------------------------------



\begin{document}


\chapter{First List}

\section{Excercises - List 1}

\begin{ejercicios}
  \begin{ejer}   Resolver $|\tan(\theta)|=1$  con $\theta \in\, R.$ 
    \begin{solu}
      {\bf Sugerencia:} Mmmmmm
    \end{solu}
  \end{ejer}
  \begin{ejer}  Resolver $|\sec(\theta)|=1$ con $\theta \in\, R^+$
    \begin{solu}
    $|\sec(\theta)|=1 \Longrightarrow....$
    \end{solu}
  \end{ejer}
\end{ejercicios}


\chapter{Second List}
\section{Excercises - List 2}

\begin{ejercicios}
  \begin{ejer}   Resolver $|\cos(\theta)|=1$  con $\theta \in\, R.$ 
    \begin{solu}
    $|\cos(\theta)|=1 \Longrightarrow \theta=k\pi, \; k \in\, Z$
    \end{solu}
  \end{ejer}

  \begin{ejer}  Resolver $|\sin(\theta)|=1$ con $\theta \in\, R^+$
    \begin{solu}
      $|\sin(\theta)|=1 \Longrightarrow \theta=(2k+1)
                         \displaystyle\frac{\pi}{2}, \; k \in\, Z^+$
    \end{solu}
  \end{ejer}

  \begin{ejer}  Resolver 
    \begin{enumerate}
      \item[a.)] $|2\sin(\theta)\cos(\theta)|=1$ con $\theta \in\, R^+$
      \item[b.)] $|2\sin(\theta)\cos(\theta)|=1$ con $\theta \in\, R$
    \end{enumerate}
    \begin{solu}
    Ejercicio para el estudiante.
    \end{solu}
  \end{ejer}
\end{ejercicios} 

\chapter*{Solutions to excercises}
 % Print solutions 
 \soluciones        % Mandatory (to close ans)
 \solucionesCap{1}  
 \solucionesCap{2}

\end{document}

List on chapter 1

List on chapter 2

Result

  • The code allows multiple lists of exercises in each chapter – wmora2 Aug 29 '13 at 0:21

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.