0

I have already read several questions on this site about the Solution of the exercises. But unfortunately they didn't help me.

This is my goal: I would like to create a new tcolorbox environment in which I have 2 mandatory arguments, the first is the \Exref so defined,

\newcommand{\Exref}[1]{Exercise \ref{ex:#1}}

The second one must label the whole environment (this label must have a kind of prefix, that is "solex" ) and must be of this type \label{solex:<Solution of the Exercise to which it refers>}. How can I do? In the code I posted below I tried somehow and it works (in the sense that every time I have to build it manually and I waste a lot of time). Thank you so much, the Code (I hope my question is clear)

\documentclass{book}
%\usepackage[italian]{babel}
\usepackage[english]{babel}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage[svgnames,x11names]{xcolor}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{stix}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{imakeidx}
\usepackage[tight,english]{minitoc}

%New Tcolorboxed Exercise

% New Exercises

\newtcbtheorem[number within=subsection] {exercise}{Esercizio}{% enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable, fonttitle=\bfseries, coltitle=green, separator sign={\ ---},#1, description delimiters={$\bigl($}{$\bigr)$}}{ex}

\newtcbtheorem[use counter from=exercise] {solex}{}{enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable, separator sign none, fonttitle=\bfseries, coltitle=green, #1}{solex}

\newtheorem{esercizio}{Esercizio}[subsection]

% Per le soluzioni

\tcbset{exercise ref/.initial=,}

\newtcbox{\SolEx}[1]{enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable, fonttitle=\bfseries, coltitle=green, title={#1}}

%\newtcbtheorem[use counter from=exercise] {solex}{Soluzione dell'\Exref{\pgfkeysvalueof{/tcb/exercise ref}}}{enhanced, colback=red!5!white, colframe=gray, sharpish corners, breakable fonttitle=\bfseries, coltitle=green, exercise ref={#1}}{ex}

% New ref

\newcommand{\Exref}[1]{Exercise \ref{ex:#1}}

\begin{document}

\title{\Huge\textcolor{red}{\textbf{Proof Book}}} \author{\color{blue}{\Huge{\textbf{???}}}} \maketitle

\dominitoc

\begin{tcolorbox}[enhanced,title=\Huge{Contents},colframe=orange,colback=Silver!75,colbacktitle=Gold1,fonttitle=\bfseries,coltitle=red,attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},boxed title style={boxrule=0.5mm, frame code={ \pathtcb fill frame -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east) -- (frame.south east) -- (frame.south west) -- cycle; },interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east) -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;} }] %\csname @starttoc\endcsname{toc} \makeatletter @starttoc{toc} \makeatother \end{tcolorbox}

%\tableofcontents

\part[Second Example Part]{\Huge\textcolor{red}{Second Example Part}}

\chapter[Tcolorboxed Exerxises]{\huge Tcolorboxed Exercises} \minitoc \mtcskip

\section[Exercise: \LaTeX--function]{\Large Exercise: \LaTeX--function}

\subsection[With Tcolorbox--package]{\large With Tcolorbox--package}

\begin{exercise}{Exercise example}{Exercise example} Un Exercise example with Tcolorbox--package. \end{exercise}

\begin{exercise}{How much $1+1$ ?}{1+1} Calculate $1+1$. \end{exercise}

\begin{solex}{Solution of \Exref{1+1} at page \pageref{ex:1+1}} %{Solex 1+1} Answer: 2 \end{solex}

\end{document}

At the end an image to simplify my question:

enter image description here

Puck
  • 1,208
  • Is https://tex.stackexchange.com/a/224429/1952 or https://tex.stackexchange.com/a/350005/1952 useful for you? – Ignasi Mar 29 '22 at 08:11
  • Already read, but I have FATAL ERROR, thanx (I'm using Overleaf) – Puck Mar 29 '22 at 09:43
  • I've tested on Overleaf and it seem that the problem is using solutions folder. If you avoid this and place all files in main folder, my codes work for me. – Ignasi Mar 29 '22 at 10:41
  • I am not be able to use solution folder. How should I do? Thx – Puck Mar 29 '22 at 11:42
  • Change the code and avoid using solutions folder. – Ignasi Mar 29 '22 at 13:09
  • This is the first example on Overleaf working without solutions folder: https://www.overleaf.com/1164823871qvvckdypjbwj – Ignasi Mar 29 '22 at 14:45
  • I would like solutions written manually like this: \begin{SolEx}[exercise ref = {}]...\end {SolEx}. Is it possible? – Puck Mar 29 '22 at 17:45

0 Answers0