1

I had created a document with problems. Some feature I implemented is a click on the problem number, which leads to the answer at the end of the document and vice versa (look MWE).

My implementation based on ntheorem and answers packages.

But now I want to implemented such feature with tcolorbox (tcbtheorem) package. I have no idea how I can do with tcbtheorem something like this:

\item[\theorem@headerfont\hyperlink{solution:\@roman{##2}}

-

% !TeX program = pdflatex
% !TeX encoding = utf8

\documentclass{book}
\usepackage{ntheorem}
\usepackage{answers}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage[many]{tcolorbox}

\makeatletter

%========================================================================================================
%
%                                   Problem environment
%
%========================================================================================================
\newtheoremstyle{problemstyle}%
{%
    \hypertarget{problem:\@roman{##2}}{}%
    \ifcsname r@solution\@roman{##2}\endcsname
        \item[\theorem@headerfont\hyperlink{solution:\@roman{##2}}{##2\theorem@separator}]
    \else
        \item[\theorem@headerfont##2\theorem@separator]
    \fi
}%
{%
    \hypertarget{problem:\@roman{##2}}{}%
    \ifcsname r@solution\@roman{##2}\endcsname
        \item[\theorem@headerfont\hyperlink{solution:\@roman{##2}}{##2\theorem@separator}] (##3)
    \else
        \item[\theorem@headerfont##2\theorem@separator] (##3)
    \fi
}

\theoremstyle{problemstyle}

\newtheorem{problem}{}[chapter]


%========================================================================================================
%
%                                   Answer environment
%
%========================================================================================================


\Newassociation{solution}{Solution}{answer}
\renewenvironment{Solution}[1]{%
    \par%
    \addpenalty{-\@lowpenalty}%
    \noindent%
    \hypertarget{solution:\@roman{#1}}{\noindent\hyperlink{problem:\@roman{#1}}{#1.}\label{solution\@roman{#1}}}
}{%
    \par%
    \addpenalty{-\@lowpenalty}%
}


\makeatother

%========================================================================================================
%
%                                   Document
%
%========================================================================================================

\begin{document}


\chapter{Chapter}
\Opensolutionfile{answer}[Answers]

\begin{problem}
\lipsum[10]
\begin{solution}
\lipsum[20]
\end{solution}
\end{problem}

\Closesolutionfile{answer}
\newpage
\input{Answers}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.