10

I'm writing a book and for it I have created a little class file.

Each section in the book have (sub-)section of exercises. At the end of all the chapters I want to put a chapter* of answers to some of the exercises. Since the exercises are numbered by section (i.e. the exercise's counter reset whenever the section step), I want to group the answers according to the section (and the chapter) of the exercise they answer to. What I want is something like this:

mwe

Here is the relevant code of the class file. The commented lines are my unsuccessful attempts to achieve what I want. I have leaved almost all the packages to see if there some compatibility problem.

\NeedsTeXFormat{LaTeX2e}[2009/09/24]
\ProvidesClass{libro}

\LoadClassWithOptions{book}
\RequirePackage[pdftex]{graphicx}
\RequirePackage[latin1]{inputenc}
\RequirePackage[spanish]{babel}
\RequirePackage{amsmath,amsfonts,amssymb,amsthm}
\RequirePackage{array}
\RequirePackage{fancyhdr}
\RequirePackage{afterpage}
\RequirePackage{thmtools}
\RequirePackage{multicol}
\RequirePackage{color}
\RequirePackage{import}
\RequirePackage[font=small]{caption}
\RequirePackage{float}
\RequirePackage{subfig}
\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{remreset}
\RequirePackage{pb-diagram}
\RequirePackage[hidelinks]{hyperref}
\RequirePackage[capitalise,noabbrev,spanish]{cleveref}
\RequirePackage{answers}

\newcounter{cuentaejercicios}[section]
\renewcommand{\thecuentaejercicios}{\Alph{cuentaejercicios}}
\declaretheoremstyle[%
  spaceabove=1em,%
  spacebelow=1em,%
  headfont=\normalfont,%
  postheadspace=1em,%
  headpunct={.}]{estilodeejercicio} 
\declaretheorem[
    name={},
    style=estilodeejercicio,
    refname={Ejercicio},
    numberlike=cuentaejercicios
]{ejer}

\renewcommand\paragraph{\@startsection
    {paragraph}{3}{0cm}             
    {6pt}                           
    {1pt}                           
    {\bfseries}}                    

%\let\c@hapter\chapter
%\renewcommand{\chapter}{
%   \c@hapter
%   \Writetofile{solucionario}{\protect\paragraph*{Capítulo \Roman{\thechapter}.\space 
%   \leftmark}}
%}

\newcommand{\seccionDeEjercicios}{%
  \newpage%
  \kern 5mm
  \hrule
  \kern 3mm
  \null \hfill {\large Ejercicios~\thesection.~\rightmark}\par
  \kern 3mm
  \hrule
  \kern 5mm
  \Writetofile{solucionario}{\protect\paragraph*{Ejercicios\space\thesection.
  \space\rightmark}}
  }

\newcommand{\Z}{\ensuremath{\mathbb{Z}}}
\newcommand{\R}{\ensuremath{\mathbb{R}}}
\newcommand{\N}{\ensuremath{\mathbb{N}}}
\newcommand{\Q}{\ensuremath{\mathbb{Q}}}
\newcommand{\nin}{\not \in}
\newcommand{\ds}[1]{\displaystyle{#1}}

\AtBeginDocument{
    \addtocontents{toc}{\protect\markboth{\small\textsl Contenidos}{\small\textsl 
    Contenidos}}
    \pagestyle{fancy}
    \fancyhf{}
    \renewcommand\headrulewidth{0pt}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}     
    \renewcommand{\sectionmark}[1]{\markright{#1}{}}
    \fancyhead[LO]{\small\textsl{\leftmark}}            
    \fancyhead[RE]{\small\textsl{\rightmark}}           
    \fancyhead[LE,RO]{\thepage}                         
    \Opensolutionfile{solucionario}
    \Newassociation{respuesta}{Res}{solucionario}
    \renewcommand{\Res}[1]{\textbf{Ejercicio #1.}}
    \Writetofile{solucionario}{\protect\chapter*{Respuestas}}
%   \begin{Filesave}{solucionario}
%   \protect\chapter*{Respuestas}
%   \protect\fancyhf{}
%   \protect\fancyhead[LO]{\small\textsl{Soluciones a los ejercicios}}          
%   \protect\fancyhead[RE]{\small\textsl{Soluciones a los ejercicios}}           
%   \protect\fancyhead[LE,RO]{\thepage}                         
%   \end{Filesave}
}

The \seccionDeEjercicios command was provided by this answer.

Here is an example of my document:

\documentclass[12pt,letterpaper]{libro}

\usepackage[
%           showframe,
            headheight=14.5pt,text={14cm,21cm},centering
            ]{geometry}
\usepackage{enumerate}
\usepackage{cases}               

\parindent=0cm

\begin{document}
\chapter{Números Reales}
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 

\chapter{Álgebra}
\section{Operaciones con polinomios}
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 

\seccionDeEjercicios
\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.
\begin{multicols}{2}
\begin{enumerate}
\item $\left( x+\dfrac{1}{2}\right) ^{2}$
\item $\left( 3-2x\right) ^{2}$
\item $\left( x-\dfrac{2}{3}\right) ^{3}$
\item $\left( 2-x\right) ^{3}$
\item $\left( 2x^{2}-\dfrac{1}{2}+x^{2}\right) ^{2}$
\item $\left( -x-y\right) ^{2}$
\item $\left( -x-y\right) ^{3}$
\item $\left( -x-2y-4x\right) ^{3}$
\item $-\left( 2x^{3}-3t^{3}\right) ^{2}$
\item $\left(-2+x^{2}-3c-x^{2}\right) ^{2}$
\item $\left( \dfrac{x+2u^{2}}{3}\right) ^{2}$
\item $-\left( \dfrac{x^{2}-u^{2}}{2}\right) ^{2}$
\item $\left( \left( x-r\right)^{2}-r^{2}\right) ^{2}$
\item $3\left( x-2t\right) ^{4}-3\left(2t-x\right) ^{4}$
\end{enumerate}
\end{multicols}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item $x^{2}+x+\dfrac{1}{4}$ 
\item $4x^{2}-12x+9$ 
\item $ x^{3}-2x^{2}+\dfrac{4}{3}x-\dfrac{8}{27}$
\item $-x^{3}+6x^{2}-12x+8$
\item $ 9x^{4}-3x^{2}+\dfrac{1}{4}$
\item $ x^{2}+2xy+y^{2}$
\item $-x^{3}-3x^{2}y-3xy^{2}-y^{3}$
\item $-125x^{3}-150x^{2}y-60xy^{2}-8y^{3}$
\item $-9t^{6}+12t^{3}x^{3}-4x^{6}$
\item $9c^{2}+12c+4$
\item $\dfrac{4}{9}u^{4}+\dfrac{4}{9}u^{2}x+\dfrac{1}{9}x^{2}$
\item $-\dfrac{1}{4}u^{4}+\dfrac{1}{2}u^{2}x^{2}-\dfrac{1}{4}x^{4}$
\item $4r^{2}x^{2}-4rx^{3}+x^{4}$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}

\begin{ejer}
Determine el cociente y el residuo en cada caso.

\begin{enumerate}
\item $\left( 2x^{3}-x^{2}+2x-1\right) \div \left( x-2\right) $
\item $\left( 4x^{3}+2x^{2}-3x-5\right) \div \left( 2x-1\right) $
\item $\left( x^{8}+x^{6}+x^{4}-x^{2}+x\right) \div \left( x-3\right) $
\item $\left( x^{4}-x^{3}-x^{2}+x^{3}+1\right) \div \left( -x+1\right) $
\item $\left( x^{3}+x^{6}+2x^{5}-\dfrac{x^{2}}{2}+x\right) \div \left(x-1\right) $
\end{enumerate}
\end{ejer}

\newpage
\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.

\begin{enumerate}
\item $-(7x^{2}+3x-4)+(8-x^{2}+5x^{3})-(2x^{3}+3x^{2}-5+8x)$
\item $\left( 11x^{3}-x+7\right) -\left( 2x-4x^{3}-6\right) +\left(7x^{2}-9x+4\right) $
\item $\left( x^{2}+2xy+4y^{2}\right) \left( x-2y\right) $
\item $5a^{3}b^{2}\left( ab^{2}-b+4a\right) -(8a^{3}b^{3}-10a^{4}b^{4})$
\item $(3x^{2}-8x+7)(x^{3}+x)+(2x^{3}-6x+2)$
\item $\dfrac{-36x^{2}y^{2}+24x^{2}y^{2}}{-12x^{2}y^{2}}$
\item $\dfrac{2a^{4}b^{6}c-4a^{5}b^{3}c^{2}+5a^{3}b^{3}c^{3}}{2a^{2}b^{3}c}$
\item $19x^{2}-10x^{3}+x^{5}-14x+6)\div (x^{2}+1-2x)$
\item $(2x^{3}-31x+35-x^{2})\div (2x-7)$
\item $(2-x^{5})\div (x^{2}+1)$
\item $(3x-5x^{2}+9+x^{3})\div (3-x)$
\item $(2x+3)^{2}-(2x-3)^{2}$
\item $(3x+1)(x+4)-(x+2)^{2}$
\item $(7x^{2}-6)(x+1)+(3x-4)^{3}$
\item $-5(a-b^{2})^{2}+(3a+b)^{3}$
\item $(2x^{2}-3)(3x^{2}-5)-(5x^{2}+6)^{2}$
\item $3x(x-2)+(3x-1)(x+5)-(3-x)^{3}$
\item $\left( 7a+1\right) \left( 7a-1\right) -\left( 4a+1\right)^{3}+2a^{2}\left( 
a-\dfrac{1}{4}\right) ^{2}$
\end{enumerate}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item[1.] $3x^{3}-11x^{2}-11x+17$
\item[3.] $x^{3}-8y^{3}$
\item[5.] $3x^{5}-8x^{4}+12x^{3}-8x^{2}+x+2$
\item[7.] $-2a^{3}c+a^{3}b^{3}+\frac{5}{2}ac^{2}$
\item[9.] $x^{2}+3x+5$
\item[11.] $-x^{2}+2x+3$ 
\item[13.] $2x^{2}+9x$
\item[17.] $x^{3}-3x^{2}+35x-32$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}

\Closesolutionfile{solucionario}

\input{solucionario}
\end{document}

Edit: Here the relevant code of my class, with chapters based on fncychap (as requested). Some code to differentiate the style of the chapters, was provided by egreg in this.

\NeedsTeXFormat{LaTeX2e}[2009/09/24]
\ProvidesClass{libro}

\LoadClassWithOptions{book}
\RequirePackage[pdftex]{graphicx}
\RequirePackage[latin1]{inputenc}
\RequirePackage[spanish]{babel}
\RequirePackage{amsmath,amsfonts,amssymb,amsthm}
\RequirePackage{array}
\RequirePackage{fancyhdr}
\RequirePackage[Sonny]{fncychap}
\RequirePackage{afterpage}
\RequirePackage{thmtools}
\RequirePackage{multicol}
\RequirePackage{color}
\RequirePackage{import}
\RequirePackage[font=small]{caption}
\RequirePackage{float}
\RequirePackage{subfig}
\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{remreset}
\RequirePackage{pb-diagram}
\RequirePackage[hidelinks]{hyperref}
\RequirePackage[capitalise,noabbrev,spanish]{cleveref}
\RequirePackage{answers}

% Chapters
\ChNameVar{\bf\LARGE}               
\ChNumVar{\LARGE}                   
\ChTitleVar{\LARGE\normalfont}      
\ChRuleWidth{0.5pt}                 
\ChNameAsIs                         
\ChTitleAsIs                        
\renewcommand{\DOCH}{}
\renewcommand{\DOTI}[1]{%
    \vspace*{-0.9cm}
    \CTV\raggedleft\mghrulefill{\RW}\par\nobreak
    \vskip 2\p@
    \CNV\FmN{\@chapapp}\space\CNoV\Roman{chapter}.\space\CTV\FmTi{#1}\par\nobreak
    \vspace*{-11\p@}
    \mghrulefill{\RW}\par\nobreak
    \vspace*{40\p@}}
\renewcommand{\DOTIS}[1]{%
    \vspace*{-9mm}
    \CTV\raggedleft
    \CTV\FmTi{#1}\par\nobreak
    \vspace*{-11\p@}
    \mghrulefill{\RW}\par\nobreak
    \vspace*{40\p@}}


\renewcommand\@seccntformat[1]{
    {\csname the#1\endcsname}.\hspace{0.5em}}
\renewcommand\section{\@startsection
    {section}{1}{0mm}               
    {6pt}                           
    {1pt}                           
    {\bfseries}}                    

\renewcommand\paragraph{\@startsection
    {paragraph}{3}{0cm}             
    {6pt}                           
    {1pt}                           
    {\bfseries}}                    

\newcounter{cuentaEjercicios}[section]
\renewcommand{\thecuentaEjercicios}{\Alph{cuentaEjercicios}}
\declaretheoremstyle[%
  spaceabove=1em,%
  spacebelow=1em,%
  headfont=\normalfont,%
  postheadspace=1em,%
  headpunct={.}]{estiloDeEjercicio} 
 \declaretheorem[
    name={},
    style=estiloDeEjercicio,
    refname={Ejercicio},
    numberlike=cuentaEjercicios
]{ejer}

\newcounter{definicion}
\declaretheoremstyle[%
  spaceabove=6pt,%
  spacebelow=6pt,%
  headfont=\normalfont\bf,%
  notefont=\normalfont\bf,
  notebraces={{}{}},
  bodyfont=\itshape,
  headpunct={.}]{estiloDeDefinicion} 
 \declaretheorem[
    name={Definici\'on},
    numberlike=definicion,
    style=estiloDeDefinicion]{defi}


\let\c@hapter\chapter
\renewcommand{\chapter}{
  \ifnum\value{chapter}>0 
    \cambiarseccionydefi 
    \let\chapter\c@hapter
  \fi
    \c@hapter
}
\def\cambiarseccionydefi{%
   \renewcommand\section{\@startsection{section}{1}{0mm}{6pt}{1pt}{\Large}}%
   \@addtoreset{definicion}{section}%
   \renewcommand{\thedefi}{\thesection.\arabic{definicion}}%
 }

\newcommand{\seccionDeEjercicios}{%
  \newpage%
  \kern 5mm
  \hrule
  \kern 3mm
  \null \hfill {\large Ejercicios~\thesection.~\rightmark}\par
  \kern 3mm
  \hrule
  \kern 5mm
}


\newcommand{\Z}{\ensuremath{\mathbb{Z}}}
\newcommand{\R}{\ensuremath{\mathbb{R}}}
\newcommand{\N}{\ensuremath{\mathbb{N}}}
\newcommand{\Q}{\ensuremath{\mathbb{Q}}}
\newcommand{\nin}{\not \in}
\newcommand{\ds}[1]{\displaystyle{#1}}

\fancypagestyle{respuestas}{%
    \fancyhf{}%
    \fancyhead[LO]{\small\slshape Soluciones a los ejercicios}%           
    \fancyhead[RE]{\small\slshape Soluciones a los ejercicios}%          
     \fancyhead[LE,RO]{\thepage}}

\AtBeginDocument{
     \addtocontents{toc}{\protect\markboth{\small\textsl Contenidos}{\small\textsl 
    Contenidos}}
    \pagestyle{fancy}
    \fancyhf{}
    \renewcommand\headrulewidth{0pt}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}     
    \renewcommand{\sectionmark}[1]{\markright{#1}{}}
    \fancyhead[LO]{\small\textsl{\leftmark}}            
    \fancyhead[RE]{\small\textsl{\rightmark}}           
    \fancyhead[LE,RO]{\thepage}                         
    \Opensolutionfile{solucionario}
    \Newassociation{respuesta}{Res}{solucionario}
    \renewcommand{\Res}[1]{\textbf{Ejercicio #1.}}
    \Writetofile{solucionario}{\protect\chapter*{Respuestas}}
    \Writetofile{solucionario}{\protect\pagestyle{respuestas}}
}
leo
  • 1,337
  • @Gonzalo Medina you can compile with that class to see the style of chapters, stared chapters, sections, and sections of the chapter 1. – leo Jul 23 '12 at 02:56
  • I've updated my answer with a solution using titlesec and not requiring fncychap. – Gonzalo Medina Jul 23 '12 at 18:35

1 Answers1

8

A possible solution using the titlesec package to change the formatting for the sectional units and and explicit option to gain access to the title for the sectional units using #1 (refer to the package documentation); the fncychap package is no longer needed.

The modified file libro.cls (the code contains some comments):

\NeedsTeXFormat{LaTeX2e}[2009/09/24]
\ProvidesClass{libro}

\LoadClassWithOptions{book}
\RequirePackage[pdftex]{graphicx}
\RequirePackage[latin1]{inputenc}
\RequirePackage[spanish]{babel}
\RequirePackage{amsmath,amsfonts,amssymb,amsthm}
\RequirePackage{array}
\RequirePackage{fancyhdr}
\RequirePackage{afterpage}
\RequirePackage{thmtools}
\RequirePackage{multicol}
\RequirePackage{color}
\RequirePackage{import}
\RequirePackage[font=small]{caption}
\RequirePackage{float}
\RequirePackage{subfig}
\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{remreset}
\RequirePackage{pb-diagram}
\RequirePackage[hidelinks]{hyperref}
\RequirePackage[capitalise,noabbrev,spanish]{cleveref}
\RequirePackage{answers}

\renewcommand\paragraph{\@startsection
    {paragraph}{3}{0cm}             
    {6pt}                           
    {1pt}                           
    {\bfseries}}                    

\newcounter{cuentaEjercicios}[section]
\renewcommand{\thecuentaEjercicios}{\Alph{cuentaEjercicios}}
\declaretheoremstyle[%
  spaceabove=1em,%
  spacebelow=1em,%
  headfont=\normalfont,%
  postheadspace=1em,%
  headpunct={.}]{estiloDeEjercicio} 
 \declaretheorem[
    name={},
    style=estiloDeEjercicio,
    refname={Ejercicio},
    numberlike=cuentaEjercicios
]{ejer}

\newcounter{definicion}
\declaretheoremstyle[%
  spaceabove=6pt,%
  spacebelow=6pt,%
  headfont=\normalfont\bf,%
  notefont=\normalfont\bf,
  notebraces={{}{}},
  bodyfont=\itshape,
  headpunct={.}]{estiloDeDefinicion} 
 \declaretheorem[
    name={Definici\'on},
    numberlike=definicion,
    style=estiloDeDefinicion]{defi}

\RequirePackage[explicit]{titlesec}

% to store the chapter name
\newcommand\mychaptername{}
% to store the section name
\newcommand\mysectionname{}

% chapter formatting
\titleformat{\chapter}[display]
  {}{}{0pt}
  {\titlerule[0.5pt]\vspace{2ex}%
    \filleft{\LARGE\bfseries\chaptertitlename\ \thechapter.\space%
    \normalfont\LARGE#1}\gdef\mychaptername{#1}}
  [{\vspace{1ex}\titlerule[0.5pt]}]
\titleformat{name=\chapter,numberless}[display]
  {}{}{0pt}
  {\filleft\normalfont\LARGE#1}
  [{\vspace{1ex}\titlerule[0.5pt]}]
\titlespacing*{\chapter}
  {0pt}{20pt}{40pt}

% change section formatting in chapters 2,3,...
\let\leo@chapter\chapter
\renewcommand{\chapter}{
  \ifnum\value{chapter}>0 
    \changesectionanddefi 
    \let\chapter\leo@chapter
  \fi
    \leo@chapter
}

% format for sections in chapter 1 
\titleformat{\section}
  {\normalfont\bfseries}{\thesection}{0.5em}
  {#1\gdef\mysectionname{#1}}%

% format for sections in chapters 2,3,... 
\newcommand\changesectionanddefi{%
\titleformat{\section}
  {\normalfont\Large}{\thesection}{0.5em}
  {##1\gdef\mysectionname{##1}%
   \@addtoreset{definicion}{section}%
   \renewcommand{\thedefi}{\thesection.\arabic{definicion}}%
}%
}
\titlespacing*{\section}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\newcommand{\seccionDeEjercicios}{%
  \newpage%
  \kern 5mm
  \hrule
  \kern 3mm
  \null \hfill {\large Ejercicios~\thesection.\space\mysectionname}\par
  \kern 3mm
  \hrule
  \kern 5mm
  \ifnum\value{section}=1 \relax
    \Writetofile{solucionario}{\protect\paragraph*{\chaptername\space\thechapter.\space\mychaptername}}
  \else\fi
  \Writetofile{solucionario}{\protect\paragraph*{Ejercicios\space\thesection.
  \space\mysectionname}}
}


\newcommand{\Z}{\ensuremath{\mathbb{Z}}}
\newcommand{\R}{\ensuremath{\mathbb{R}}}
\newcommand{\N}{\ensuremath{\mathbb{N}}}
\newcommand{\Q}{\ensuremath{\mathbb{Q}}}
\newcommand{\nin}{\not \in}
\newcommand{\ds}[1]{\displaystyle{#1}}

\fancypagestyle{respuestas}{%
    \fancyhf{}%
    \fancyhead[LO]{\small\slshape Soluciones a los ejercicios}%           
    \fancyhead[RE]{\small\slshape Soluciones a los ejercicios}%          
     \fancyhead[LE,RO]{\thepage}}

\AtBeginDocument{
     \addtocontents{toc}{\protect\markboth{\small\textsl Contenidos}{\small\textsl 
    Contenidos}}
    \pagestyle{fancy}
    \fancyhf{}
    \renewcommand\headrulewidth{0pt}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}     
    \renewcommand{\sectionmark}[1]{\markright{#1}{}}
    \fancyhead[LO]{\small\textsl{\leftmark}}            
    \fancyhead[RE]{\small\textsl{\rightmark}}           
    \fancyhead[LE,RO]{\thepage}                         
    \Opensolutionfile{solucionario}
    \Newassociation{respuesta}{Res}{solucionario}
    \renewcommand{\Res}[1]{\textbf{Ejercicio #1.}}
    \Writetofile{solucionario}{\protect\chapter*{Respuestas}}
    \Writetofile{solucionario}{\protect\pagestyle{respuestas}}
}

The test file, with the new code using titlesec:

\documentclass[12pt,letterpaper]{libro}

\usepackage[
%           showframe,
            headheight=14.5pt,text={14cm,21cm},centering
            ]{geometry}
\usepackage{enumerate}
\usepackage{cases}               


\parindent=0cm

\begin{document}

\chapter{Números Reales}
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 

\section{Propiedades de campo}

\seccionDeEjercicios
\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.
\begin{multicols}{2}
\begin{enumerate}
\item $\left( x+\dfrac{1}{2}\right) ^{2}$
\item $\left( 3-2x\right) ^{2}$
\item $\left( x-\dfrac{2}{3}\right) ^{3}$
\item $\left( 2-x\right) ^{3}$
\item $\left( 2x^{2}-\dfrac{1}{2}+x^{2}\right) ^{2}$
\item $\left( -x-y\right) ^{2}$
\item $\left( -x-y\right) ^{3}$
\item $\left( -x-2y-4x\right) ^{3}$
\item $-\left( 2x^{3}-3t^{3}\right) ^{2}$
\item $\left(-2+x^{2}-3c-x^{2}\right) ^{2}$
\item $\left( \dfrac{x+2u^{2}}{3}\right) ^{2}$
\item $-\left( \dfrac{x^{2}-u^{2}}{2}\right) ^{2}$
\item $\left( \left( x-r\right)^{2}-r^{2}\right) ^{2}$
\item $3\left( x-2t\right) ^{4}-3\left(2t-x\right) ^{4}$
\end{enumerate}
\end{multicols}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item $x^{2}+x+\dfrac{1}{4}$ 
\item $4x^{2}-12x+9$ 
\item $ x^{3}-2x^{2}+\dfrac{4}{3}x-\dfrac{8}{27}$
\item $-x^{3}+6x^{2}-12x+8$
\item $ 9x^{4}-3x^{2}+\dfrac{1}{4}$
\item $ x^{2}+2xy+y^{2}$
\item $-x^{3}-3x^{2}y-3xy^{2}-y^{3}$
\item $-125x^{3}-150x^{2}y-60xy^{2}-8y^{3}$
\item $-9t^{6}+12t^{3}x^{3}-4x^{6}$
\item $9c^{2}+12c+4$
\item $\dfrac{4}{9}u^{4}+\dfrac{4}{9}u^{2}x+\dfrac{1}{9}x^{2}$
\item $-\dfrac{1}{4}u^{4}+\dfrac{1}{2}u^{2}x^{2}-\dfrac{1}{4}x^{4}$
\item $4r^{2}x^{2}-4rx^{3}+x^{4}$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}


\chapter{Álgebra}

\section{Operaciones con polinomios}
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 

\seccionDeEjercicios
\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.
\begin{multicols}{2}
\begin{enumerate}
\item $\left( x+\dfrac{1}{2}\right) ^{2}$
\item $\left( 3-2x\right) ^{2}$
\item $\left( x-\dfrac{2}{3}\right) ^{3}$
\item $\left( 2-x\right) ^{3}$
\item $\left( 2x^{2}-\dfrac{1}{2}+x^{2}\right) ^{2}$
\item $\left( -x-y\right) ^{2}$
\item $\left( -x-y\right) ^{3}$
\item $\left( -x-2y-4x\right) ^{3}$
\item $-\left( 2x^{3}-3t^{3}\right) ^{2}$
\item $\left(-2+x^{2}-3c-x^{2}\right) ^{2}$
\item $\left( \dfrac{x+2u^{2}}{3}\right) ^{2}$
\item $-\left( \dfrac{x^{2}-u^{2}}{2}\right) ^{2}$
\item $\left( \left( x-r\right)^{2}-r^{2}\right) ^{2}$
\item $3\left( x-2t\right) ^{4}-3\left(2t-x\right) ^{4}$
\end{enumerate}
\end{multicols}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item $x^{2}+x+\dfrac{1}{4}$ 
\item $4x^{2}-12x+9$ 
\item $ x^{3}-2x^{2}+\dfrac{4}{3}x-\dfrac{8}{27}$
\item $-x^{3}+6x^{2}-12x+8$
\item $ 9x^{4}-3x^{2}+\dfrac{1}{4}$
\item $ x^{2}+2xy+y^{2}$
\item $-x^{3}-3x^{2}y-3xy^{2}-y^{3}$
\item $-125x^{3}-150x^{2}y-60xy^{2}-8y^{3}$
\item $-9t^{6}+12t^{3}x^{3}-4x^{6}$
\item $9c^{2}+12c+4$
\item $\dfrac{4}{9}u^{4}+\dfrac{4}{9}u^{2}x+\dfrac{1}{9}x^{2}$
\item $-\dfrac{1}{4}u^{4}+\dfrac{1}{2}u^{2}x^{2}-\dfrac{1}{4}x^{4}$
\item $4r^{2}x^{2}-4rx^{3}+x^{4}$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}


\begin{ejer}
Determine el cociente y el residuo en cada caso.

\begin{enumerate}
\item $\left( 2x^{3}-x^{2}+2x-1\right) \div \left( x-2\right) $
\item $\left( 4x^{3}+2x^{2}-3x-5\right) \div \left( 2x-1\right) $
\item $\left( x^{8}+x^{6}+x^{4}-x^{2}+x\right) \div \left( x-3\right) $
\item $\left( x^{4}-x^{3}-x^{2}+x^{3}+1\right) \div \left( -x+1\right) $
\item $\left( x^{3}+x^{6}+2x^{5}-\dfrac{x^{2}}{2}+x\right) \div \left(x-1\right) $
\end{enumerate}
\end{ejer}

\newpage

\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.

\begin{enumerate}
\item $-(7x^{2}+3x-4)+(8-x^{2}+5x^{3})-(2x^{3}+3x^{2}-5+8x)$
\item $\left( 11x^{3}-x+7\right) -\left( 2x-4x^{3}-6\right) +\left(7x^{2}-9x+4\right) $
\item $\left( x^{2}+2xy+4y^{2}\right) \left( x-2y\right) $
\item $5a^{3}b^{2}\left( ab^{2}-b+4a\right) -(8a^{3}b^{3}-10a^{4}b^{4})$
\item $(3x^{2}-8x+7)(x^{3}+x)+(2x^{3}-6x+2)$
\item $\dfrac{-36x^{2}y^{2}+24x^{2}y^{2}}{-12x^{2}y^{2}}$
\item $\dfrac{2a^{4}b^{6}c-4a^{5}b^{3}c^{2}+5a^{3}b^{3}c^{3}}{2a^{2}b^{3}c}$
\item $19x^{2}-10x^{3}+x^{5}-14x+6)\div (x^{2}+1-2x)$
\item $(2x^{3}-31x+35-x^{2})\div (2x-7)$
\item $(2-x^{5})\div (x^{2}+1)$
\item $(3x-5x^{2}+9+x^{3})\div (3-x)$
\item $(2x+3)^{2}-(2x-3)^{2}$
\item $(3x+1)(x+4)-(x+2)^{2}$
\item $(7x^{2}-6)(x+1)+(3x-4)^{3}$
\item $-5(a-b^{2})^{2}+(3a+b)^{3}$
\item $(2x^{2}-3)(3x^{2}-5)-(5x^{2}+6)^{2}$
\item $3x(x-2)+(3x-1)(x+5)-(3-x)^{3}$
\item $\left( 7a+1\right) \left( 7a-1\right) -\left( 4a+1\right)^{3}+2a^{2}\left( 
a-\dfrac{1}{4}\right) ^{2}$
\end{enumerate}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item[1.] $3x^{3}-11x^{2}-11x+17$
\item[3.] $x^{3}-8y^{3}$
\item[5.] $3x^{5}-8x^{4}+12x^{3}-8x^{2}+x+2$
\item[7.] $-2a^{3}c+a^{3}b^{3}+\frac{5}{2}ac^{2}$
\item[9.] $x^{2}+3x+5$
\item[11.] $-x^{2}+2x+3$ 
\item[13.] $2x^{2}+9x$
\item[17.] $x^{3}-3x^{2}+35x-32$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}

\section{Operaciones con otros objetos}
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 
bla bla bla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla 

\seccionDeEjercicios
\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.
\begin{multicols}{2}
\begin{enumerate}
\item $\left( x+\dfrac{1}{2}\right) ^{2}$
\item $\left( 3-2x\right) ^{2}$
\item $\left( x-\dfrac{2}{3}\right) ^{3}$
\item $\left( 2-x\right) ^{3}$
\item $\left( 2x^{2}-\dfrac{1}{2}+x^{2}\right) ^{2}$
\item $\left( -x-y\right) ^{2}$
\item $\left( -x-y\right) ^{3}$
\item $\left( -x-2y-4x\right) ^{3}$
\item $-\left( 2x^{3}-3t^{3}\right) ^{2}$
\item $\left(-2+x^{2}-3c-x^{2}\right) ^{2}$
\item $\left( \dfrac{x+2u^{2}}{3}\right) ^{2}$
\item $-\left( \dfrac{x^{2}-u^{2}}{2}\right) ^{2}$
\item $\left( \left( x-r\right)^{2}-r^{2}\right) ^{2}$
\item $3\left( x-2t\right) ^{4}-3\left(2t-x\right) ^{4}$
\end{enumerate}
\end{multicols}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item $x^{2}+x+\dfrac{1}{4}$ 
\item $4x^{2}-12x+9$ 
\item $ x^{3}-2x^{2}+\dfrac{4}{3}x-\dfrac{8}{27}$
\item $-x^{3}+6x^{2}-12x+8$
\item $ 9x^{4}-3x^{2}+\dfrac{1}{4}$
\item $ x^{2}+2xy+y^{2}$
\item $-x^{3}-3x^{2}y-3xy^{2}-y^{3}$
\item $-125x^{3}-150x^{2}y-60xy^{2}-8y^{3}$
\item $-9t^{6}+12t^{3}x^{3}-4x^{6}$
\item $9c^{2}+12c+4$
\item $\dfrac{4}{9}u^{4}+\dfrac{4}{9}u^{2}x+\dfrac{1}{9}x^{2}$
\item $-\dfrac{1}{4}u^{4}+\dfrac{1}{2}u^{2}x^{2}-\dfrac{1}{4}x^{4}$
\item $4r^{2}x^{2}-4rx^{3}+x^{4}$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}


\begin{ejer}
Determine el cociente y el residuo en cada caso.

\begin{enumerate}
\item $\left( 2x^{3}-x^{2}+2x-1\right) \div \left( x-2\right) $
\item $\left( 4x^{3}+2x^{2}-3x-5\right) \div \left( 2x-1\right) $
\item $\left( x^{8}+x^{6}+x^{4}-x^{2}+x\right) \div \left( x-3\right) $
\item $\left( x^{4}-x^{3}-x^{2}+x^{3}+1\right) \div \left( -x+1\right) $
\item $\left( x^{3}+x^{6}+2x^{5}-\dfrac{x^{2}}{2}+x\right) \div \left(x-1\right) $
\end{enumerate}

\begin{respuesta}
\begin{multicols}{2}
\begin{enumerate}
\item[1.] $3x^{3}-11x^{2}-11x+17$
\item[3.] $x^{3}-8y^{3}$
\item[5.] $3x^{5}-8x^{4}+12x^{3}-8x^{2}+x+2$
\item[7.] $-2a^{3}c+a^{3}b^{3}+\frac{5}{2}ac^{2}$
\item[9.] $x^{2}+3x+5$
\item[11.] $-x^{2}+2x+3$ 
\item[13.] $2x^{2}+9x$
\item[17.] $x^{3}-3x^{2}+35x-32$
\end{enumerate}
\end{multicols}
\end{respuesta}
\end{ejer}

\newpage

\begin{ejer}
Efectúe las operaciones indicadas. Exprese el resultado como un
polinomio reducido.

\begin{enumerate}
\item $-(7x^{2}+3x-4)+(8-x^{2}+5x^{3})-(2x^{3}+3x^{2}-5+8x)$
\item $\left( 11x^{3}-x+7\right) -\left( 2x-4x^{3}-6\right) +\left(7x^{2}-9x+4\right) $
\item $\left( x^{2}+2xy+4y^{2}\right) \left( x-2y\right) $
\item $5a^{3}b^{2}\left( ab^{2}-b+4a\right) -(8a^{3}b^{3}-10a^{4}b^{4})$
\item $(3x^{2}-8x+7)(x^{3}+x)+(2x^{3}-6x+2)$
\item $\dfrac{-36x^{2}y^{2}+24x^{2}y^{2}}{-12x^{2}y^{2}}$
\item $\dfrac{2a^{4}b^{6}c-4a^{5}b^{3}c^{2}+5a^{3}b^{3}c^{3}}{2a^{2}b^{3}c}$
\item $19x^{2}-10x^{3}+x^{5}-14x+6)\div (x^{2}+1-2x)$
\item $(2x^{3}-31x+35-x^{2})\div (2x-7)$
\item $(2-x^{5})\div (x^{2}+1)$
\item $(3x-5x^{2}+9+x^{3})\div (3-x)$
\item $(2x+3)^{2}-(2x-3)^{2}$
\item $(3x+1)(x+4)-(x+2)^{2}$
\item $(7x^{2}-6)(x+1)+(3x-4)^{3}$
\item $-5(a-b^{2})^{2}+(3a+b)^{3}$
\item $(2x^{2}-3)(3x^{2}-5)-(5x^{2}+6)^{2}$
\item $3x(x-2)+(3x-1)(x+5)-(3-x)^{3}$
\item $\left( 7a+1\right) \left( 7a-1\right) -\left( 4a+1\right)^{3}+2a^{2}\left( 
a-\dfrac{1}{4}\right) ^{2}$
\end{enumerate}
\end{ejer}

\Closesolutionfile{solucionario}

\input{solucionario}
\end{document}

An image of the "Respuestas" ("Answers") section showing the desired result:

enter image description here

Gonzalo Medina
  • 505,128
  • Does this will work with fncychap? – leo Jul 23 '12 at 00:49
  • @leo The chapter headinngs in the Respuestas section are introduced using \paragraph* so it should (in principle) work with fncychap. I didn't use \chapter* for the chapter titles in the Respuestas section because then every chapter would start a new page and that seemed unnecessary. – Gonzalo Medina Jul 23 '12 at 00:56
  • Yes it is unnecessary indeed. I'm about to test it with fncychap – leo Jul 23 '12 at 01:04
  • Is there another to obtain the current nam of chapters and sections avoinding titlesec? – leo Jul 23 '12 at 01:53
  • @leo I don't know, perhaps there's another way, but why don't you want to use titlesec? If you want to, you can replicate any of the styles of fncychap (which are pretty ugly, by the way) or create a new nice customized format using titlesec. – Gonzalo Medina Jul 23 '12 at 01:56
  • :-) I agree with you, I don't like that styles, but it was a request. I'll edit the question to be more specific. – leo Jul 23 '12 at 02:06
  • I have updated my question adding the fncychap based chapters. By the way, if you can fix the little indentation of the sections headers, it would be great. – leo Jul 23 '12 at 17:04
  • @leo what do you mean with "fix"? Do you want to remove it? I kept it in my answer just because I wasn't sure, but I can easily remove it if that's what you want. – Gonzalo Medina Jul 23 '12 at 18:36
  • how do you deal with the different style of sections across chapters? I read the code, I can't find where? And please tell me how to delete the indentation of the sections. Your answer is great! – leo Jul 23 '12 at 20:02
  • @leo I removed the space in my updated answer (I simply removed the \hspace*{0.5em} before \thesection inside \titleformat{}section}). I don't quite understand what you mean with " the different style of sections across chapters"; could you please elaborate? – Gonzalo Medina Jul 23 '12 at 20:13
  • Look at the style of the sections of the chapter 1 and tha sections of chapter 2. They are different, however I don't see any conditional like in the egreg's answer in here – leo Jul 23 '12 at 20:24
  • @leo I don't see any changes... are you using the updated .tex and .cls files of my code? – Gonzalo Medina Jul 23 '12 at 20:30
  • Yes you are right. There are no changes. I want different sections starting from chapter 1. Look at this. In there, that was fixed (thanks to egreg) but not using titlesec. Can you help me to solve that problem? – leo Jul 23 '12 at 20:46
  • @leo Ah, yes, now I see. Give me some minutes and I'll update my answer. – Gonzalo Medina Jul 23 '12 at 21:04
  • @leo Answer updated. I also moved the formatting code from the .tex file to the .cls file. Additionally, seeing your original code, I saw that you were trying to include the title for each section in the title of its corresponding exercise section; I've also provided this feature in the new code. Let me know if things are OK now. – Gonzalo Medina Jul 23 '12 at 21:26
  • Things are very OK now, thanks for your time! I would like to upvote again :-) – leo Jul 23 '12 at 22:18