Упражнения по маркировке, созданные с помощью tcolorbox

Упражнения по маркировке, созданные с помощью tcolorbox

Я создаю упражнения в книжной среде, глава за главой, используя документ в последней версии tcolorbox. В этой версии метки создаются автоматически (с помощью команды label={exercise@\thetcbcounter}). Я хочу создавать свои собственные метки, как в предыдущей версии, тем же способом, что и команда , label={exe:#2}, где #2имя метки, которую я хочу определить. Как это сделать?

Я привожу пример файла с данными в документе и использую команду

The solution of the exercise \ref{[email protected]} is in the page \pageref{[email protected]}

поэтому я хочу вспомнить метки (найденные в файле .aux!) [email protected]и [email protected]по меткам exercise:mylabelи solution:mylabel, соответственно.

\documentclass{book}


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

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


 \tcbuselibrary{skins,xparse}
\NewTColorBox[auto counter,number within=chapter]{exercise}{+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@\thetcbcounter},
attach title to upper=\quad,
after upper={\par\hfill\textcolor{green!40!black}%
{\itshape Solution on page~\pageref{solution@\thetcbcounter}}},
lowerbox=ignored,
savelowerto=solutions/exercise-\thetcbcounter.tex,
record={\string\solution{\thetcbcounter}{solutions/exercise-\thetcbcounter.tex}},
#1
}
\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}
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{[email protected]} is in the page \pageref{[email protected]}
\vspace*{1cm}
\tcbstoprecording
\tcbinputrecords

\end{document}

что дает после компиляции с XeLatex: введите описание изображения здесь

решение1

Следующий код добавляет обязательный аргумент к exercise. Этот обязательный аргумент — метка, которая будет добавлена ​​к exercise:...и solution:....

Введение этой метки подразумевало изменение label, after upperи recordопределений опций в exercisetcolorbox. Также предыдущая #1была изменена на #2.

В solutionрамке нет новых аргументов, но есть изменения в titleи phantomlabel.

\documentclass{book}

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

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

\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

\end{document}

Результирующий и вспомогательный файлы не изменяются, только содержимое auxфайла будет отображать новый синтаксис меток и значения.

введите описание изображения здесь

Связанный контент