tcolorbox로 제작된 연습문제 솔루션

tcolorbox로 제작된 연습문제 솔루션

나는 book마지막 버전의 문서를 사용하여 수업 시간에 장별로 솔루션이 포함된 연습 문제를 작성합니다 tcolorbox. 나는 책의 마지막 부분에 답변을 정리하고 싶습니다. \tcbstartrecording파일의 시작 부분과 \tcbstoprecording파일 끝 부분을 사용하여 이 작업을 수행할 수 있습니다 . 마지막에 명령은 \tcbinputrecords동일한 순서로 답변을 제공합니다. 첫 번째 장의 경우 "1장의 연습 문제 해결", 두 번째 장의 경우 "2장의 연습 문제 해결"이라는 제목으로 장별로 그룹화된 답변을 얻고 싶습니다. , 등등..

나는 내가 얻은 PDF 파일의 4페이지를 제공합니다. "1 페이지의 연습 1.1 풀이" 상자 앞에 "1 장의 연습 풀이"라는 제목을 원하고 "1 페이지의 연습 1.1 풀이" 상자 앞에 "2 장의 연습 풀이"라는 제목을 원합니다. 3페이지." 어떻게 해야 하나요?

사용된 파일 은 다음과 같습니다 .tex.

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

Xelatex를 사용한 컴파일의 4페이지는 다음과 같습니다.

여기에 이미지 설명을 입력하세요

답변1

\chapter해당 장에 대한 일부 정보를 기록 파일에 기록하는 명령을 앞에 추가할 수 있습니다 . 녹화가 시작되지 않았기 때문에 첫 번째 챕터에서는 실패합니다.

장 번호를 재설정해도 실패합니다.

trick \c@chapter챕터 번호가 증가하기 전에 앞에 추가가 발생하므로 그룹 내에서 1씩 증가한 숫자를 사용하기 로 결정했기 TeX때문에 카운터 값은 실제로 변경되지 않지만 \thechapter잠시 동안은 속인 값을 사용하고 정의된 대로 올바른 형식을 적용합니다. \thechapter. \arabic{chapter}내 관점에서는 이것이 등을 사용하는 것보다 낫습니다 .

\solutionchapterformat솔루션-장-그룹의 멋진/멋진 제목을 생성하려면 매크로를 마음대로 변경하십시오 (그러나 는 그대로 두십시오 \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}

여기에 이미지 설명을 입력하세요

관련 정보