Lösungen zu den mit tcolorbox erstellten Übungen

Lösungen zu den mit tcolorbox erstellten Übungen

bookIch erstelle im Unterricht kapitelweise Übungen mit Lösungen und verwende dazu das Dokument in der letzten Version von tcolorbox. Ich möchte die Antworten gruppiert am Ende des Buches erstellen. Dies kann ich tun, indem ich \tcbstartrecordingam Anfang und \tcbstoprecordingam Ende der Datei verwende. Am Ende \tcbinputrecordsgibt der Befehl die Antworten in derselben Reihenfolge aus. Ich möchte die Antworten gruppiert nach Kapiteln erhalten, mit einem Titel für jede Gruppe, „Lösungen der Übungen des Kapitels 1“ für die des ersten Kapitels, „Lösungen der Übungen des Kapitels 2“ für die des zweiten Kapitels und so weiter.

Ich gebe Seite 4 der PDF-Datei ein, die ich erhalte. Ich möchte den Titel „Lösungen der Übungen des Kapitels 1“ vor dem Feld mit dem Titel „Lösung der Übung 1.1 auf Seite 1“ und den Titel „Lösungen der Übungen des Kapitels 2“ vor dem Feld mit dem Titel „Lösung der Übung 2.1 auf Seite 3“. Wie kann ich das erreichen?

Hier ist die .texverwendete Datei:

\documentclass{book}

\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,breakable}

\usepackage{polyglossia}
\setmainlanguage{english}

\tcbuselibrary{skins,xparse}

\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
    enhanced,
    colframe=green!20!black,
    colback=yellow!10!white,
    coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=green!80!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
    title={Exercise~ \thetcbcounter:},
    label={exercise:#1},
    attach title to upper=\quad,
    after upper={\par\hfill\textcolor{green!40!black}%
        {\itshape Solution on page~\pageref{solution:#1}}},
    lowerbox=ignored,
    savelowerto=solutions/exercise-\thetcbcounter.tex,
    record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
    #2
}

\NewTotalTColorBox{\solution}{mm}{%
    enhanced,
    colframe=red!20!black,
    colback=yellow!10!white,
    coltitle=red!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=red!50!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
    title={Solution of Exercise~\ref{exercise:#1} on page~\pageref{exercise:#1}:},
    phantomlabel={solution:#1},
    attach title to upper=\par,
}{\input{#2}}

\tcbset{no solution/.style={no recording,after upper=}}

\begin{document}
\chapter{The first chapter}

\tcbstartrecording
\begin{exercise}{Ex1}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( \sin((\sin x)^2) \right)’
=\cos((\sin x)^2) 2\sin x \cos x.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex1} is in the page \pageref{solution:Ex1}
\vspace*{1cm}
%\tcbstoprecording
%\tcbinputrecords
\chapter{The second chapter}

%\tcbstartrecording
\begin{exercise}{Ex2}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=(x^2+1) \sqrt{x^4+1}
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( (x^2+1) \sqrt{x^4+1} \right)’
= 2x\sqrt{x^4+1} + \frac{2x^3(x^2+1)}{\sqrt{x^4+1}}.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex2} is in the page \pageref{solution:Ex2}
\vspace*{1cm}
\tcbstoprecording
\newpage
\section{Solutions of the exercices}
\tcbinputrecords
\end{document}

und Seite 4 der Zusammenstellung mit Xelatex:

Bildbeschreibung hier eingeben

Antwort1

Es ist möglich, dem \chapterBefehl einige Informationen über das Kapitel voranzustellen, um sie in die Aufnahmedatei zu schreiben. Dies schlägt beim ersten Kapitel fehl, da die Aufnahme dann noch nicht begonnen hat.

Es schlägt auch fehl, wenn die Kapitelnummer zurückgesetzt wird.

Da das Voranstellen vor der Erhöhung der Kapitelnummer erfolgt, habe ich mich entschieden, trick \c@chapterinnerhalb einer Gruppe eine um eins erhöhte Zahl zu verwenden TeX, sodass der Zählerwert nicht wirklich geändert wird, sondern \thechapterder manipulierte Wert für eine Weile verwendet wird und das korrekte Format wie für definiert angewendet wird . Meiner Meinung nach \thechapterist das besser, als etwas wie usw. zu verwenden .\arabic{chapter}

Ändern Sie das \solutionchapterformatMakro nach Belieben, um eine beliebige nette/ausgefallene Überschrift für die Lösungskapitelgruppe zu erstellen (aber lassen Sie das \bgroup... \egroup)

\documentclass{book}

\usepackage[most]{tcolorbox}

\usepackage{xpatch}

% Formatting command as a 'headline' of the solutions of chapter X
\NewDocumentCommand{\solutionchapterformat}{m}{%
  \noindent \bgroup\bfseries Solutions of the exercises of the chapter #1\egroup%
}
\makeatletter


\xpretocmd{\chapter}{%
  \begingroup
  \ifnum\value{chapter}>0\relax
  \tcbrecord{\string\clearpage}% Write a clearpage after the first chapter for each new chapter
  \fi
  \c@chapter \numexpr\c@chapter+1% Increase the count register `\@chapter` by one to trick `\thechapter` using the 'correct' chapter number
  \tcbrecord{%
    \solutionchapterformat{\thechapter}}%
  \endgroup
}{}{}

\NewDocumentCommand{\extrasolutioncontent}{+m}{%
  \tcbrecord{Extra solution stuff\par}% Remove this later on!
  \tcbrecord{\detokenize{#1}}%
}

\newcommand{\fetchsolutions}{%
%For the first chapter
\begingroup
\c@chapter1%
\solutionchapterformat{\thechapter}%
\endgroup% Now get the rest of the stuff
\tcbinputrecords
}
\makeatother

%\tcbuselibrary{skins,breakable}

%\usepackage{polyglossia}
%\setmainlanguage{english}
%\usepackage{fontspec}
%\setmainfont{Times New Roman}
%\setsansfont{Arial}
%\setmonofont{Courier New}


\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
    enhanced,
    colframe=green!20!black,
    colback=yellow!10!white,
    coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=green!80!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
    title={Exercise~ \thetcbcounter:},
    label={exercise:#1},
    attach title to upper=\quad,
    after upper={\par\hfill\textcolor{green!40!black}%
        {\itshape Solution on page~\pageref{solution:#1}}},
    lowerbox=ignored,
    savelowerto=solutions/exercise-\thetcbcounter.tex,
    record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
    #2
}

\NewTotalTColorBox{\solution}{mm}{%
    enhanced,
    colframe=red!20!black,
    colback=yellow!10!white,
    coltitle=red!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=red!50!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
    title={Solution of Exercise~\ref{exercise:#1} on page~\pageref{exercise:#1}:},
    phantomlabel={solution:#1},
    attach title to upper=\par,
}{\input{#2}}

\tcbset{no solution/.style={no recording,after upper=}}

\begin{document}
\chapter{The first chapter}

\tcbstartrecording
\begin{exercise}{Ex1}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( \sin((\sin x)^2) \right)’
=\cos((\sin x)^2) 2\sin x \cos x.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex1} is in the page \pageref{solution:Ex1}
\vspace*{1cm}
%\tcbstoprecording
%\tcbinputrecords
\chapter{The second chapter}

%\tcbstartrecording
\begin{exercise}{Ex2}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=(x^2+1) \sqrt{x^4+1}
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( (x^2+1) \sqrt{x^4+1} \right)’
= 2x\sqrt{x^4+1} + \frac{2x^3(x^2+1)}{\sqrt{x^4+1}}.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex2} is in the page \pageref{solution:Ex2}
\vspace*{1cm}

\chapter{The third chapter}

\begin{exercise}{Ex3}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=(x^2+1) \sqrt{x^4+1}
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( (x^2+1) \sqrt{x^4+1} \right)’
= 2x\sqrt{x^4+1} + \frac{2x^3(x^2+1)}{\sqrt{x^4+1}}.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex3} is in the page \pageref{solution:Ex3}
\vspace*{1cm}


\extrasolutioncontent{$\textcolor{blue}{E=mc^2}$}

\begin{exercise}{Ex31}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=(x^2+1) \sqrt{x^4+1}
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( (x^2+1) \sqrt{x^4+1} \right)’
= 2x\sqrt{x^4+1} + \frac{2x^3(x^2+1)}{\sqrt{x^4+1}}.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex31} is in the page \pageref{solution:Ex31}
\vspace*{1cm}


\chapter{The fourth chapter}

\begin{exercise}{Ex4}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=(x^2+1) \sqrt{x^4+1}
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f’(x) &= \left( (x^2+1) \sqrt{x^4+1} \right)’
= 2x\sqrt{x^4+1} + \frac{2x^3(x^2+1)}{\sqrt{x^4+1}}.
\end{align*}
\end{exercise}
\vspace*{1cm}
The solution of the exercise \ref{exercise:Ex4} is in the page \pageref{solution:Ex3}
\vspace*{1cm}




\tcbstoprecording
\newpage
\section{Solutions of the exercices}
\fetchsolutions
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen