使用答案包的自定义环境

使用答案包的自定义环境

我想创建一个与包一起使用的自定义环境answers,例如

 ...
\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}

...但我做不到。你能帮助我吗?

答案1

解决方案很简单,正如我们所见:

\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}

第 1 章列表

第 2 章列表

结果

相关内容