Customize todonotes not to be in the margin

formattingtcolorboxtikz-stylestodonotes

I would like to produce solved examples with comments like below.

enter image description here

I tried package todonotes with the following codes

\documentclass[12pt,openany,twoside,fleqn]{book}
\usepackage{amsmath}
%\usepackage[width=16cm,height=24cm,margin=5cm]{geometry}
\usepackage[textwidth=\marginparwidth,linecolor=red,bordercolor=yellow,backgr
oundcolor=yellow]{todonotes}
\usepackage{mathspec}
\setmainfont{Tekton Pro} 
\everymath{\displaystyle}
\setmathsfont(Digits,Greek,Latin){Tekton Pro} 
\usepackage{siunitx}
\begin{document}
\noindent
\(V=\frac{4}{3}\pi r^{3}\)\\[2ex] 
\(\frac{dV}{dr}=4\pi r^{2}\)\todo{{\fontspec{ITC Berkeley Oldstyle 
Std}Differentiate $V$ with respect to $r$. Remember that $\pi$ is a 
constant.}}\\[2ex]
When $ r=5$, \(\frac{dV}{dr}=4\pi\times 5^{2}\)\todo{{\fontspec{ITC Berkeley 
Oldstyle Std}Substitute $r=5$}}\\[2ex] 
\hspace*{3.2cm}\(=314\) (3 s.f.)\\[2ex] 
So the rate of change is 314 \si{\cubic\centi\meter} per 
\si{\centi\meter}\todo{{\fontspec{ITC Berkeley Oldstyle Std}Interpret the 
answer with units.}} 
\end{document}

On compiling I got

enter image description here

I also realized that todonotes cannot work inside tcolorbox yet it's part of the target.
Apologies for this is looking to me like many questions in one.
I would be greatly happy to receive any kind help from the community.

Best Answer

You can do what you need without todonotes, you can use TikZ overlay, remember picture.

I don't have your font, but it isn't a problem to add it.

\documentclass[12pt,openany,twoside,fleqn]{book}
%\usepackage[width=16cm,height=24cm,margin=5cm]{geometry}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
    mypoint/.style={
        fill=red, 
        circle, 
        inner sep=1pt, 
        xshift=5pt, yshift=3pt
        },
    myblock/.style={
        fill=yellow, 
        text width=4cm,
        },
    }
    
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\tcbset{
    enhanced,
    colframe=gray!30,
    colback=white,
    boxrule=10pt,
    sharp corners,
    width=.65\linewidth
    }

\usepackage{mathspec}
%\setmainfont{Tekton Pro}% I don't have this font 
\everymath{\displaystyle}
%\setmathsfont(Digits,Greek,Latin){Tekton Pro}% I don't have this font  
\usepackage{siunitx}

\begin{document}
\begin{tcolorbox}
\(\begin{aligned}
    V=\frac{4}{3}\pi r^{3}\\[2ex]
    \frac{dV}{dr}=4\pi r^{2}\tikz[overlay, remember picture]{\node[mypoint] (P1) {};}\\[2ex]
\end{aligned}\)

\(\begin{aligned}  
  \text{When } r=5\text{, } \frac{dV}{dr}&=4\pi\times 5^{2}\tikz[overlay, remember picture]{\node[mypoint] (P2) {};}\\[2ex]
    &=314  \text{ (3 s.f.)}\\[2ex]
\end{aligned}\)

So the rate of change is 314 \si{\cubic\centi\meter} per 
\si{\centi\meter}\tikz[overlay, remember picture]{\node[mypoint] (P3) {};} 
\begin{tikzpicture}[overlay, remember picture]
    \node[myblock, xshift=20em, yshift=3ex] (B1) at (P1) {Differentiate $V$ with respect to $r$. Remember that $\pi$ is a constant.};
    \node[myblock] (B2) at (P2 -| B1) {Substitute $r=5$};
    \node[myblock] (B3) at (P3 -| B1) {Interpret the answer with units.};
    \draw[red] (P1) -- ++(1,0) |- (B1.west);
    \draw[red] (P2) -- (B2.west);
    \draw[red] (P3) -- (B3.west);
\end{tikzpicture}
\end{tcolorbox}

\end{document}

enter image description here