# Comment Box for Substitution Method of Integrals

I want to make a comment box like the image below that adjusts in size as I write up different examples. My MWE is not much

\documentclass{article}
\usepackage{amsmath, mathtools,tikz}

\begin{document}

\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\ dx &=\int (\textcolor{red}
{x^{3}+1})^{10} \textcolor{blue}{3x^{2}\ dx} \\
&=\int \textcolor{red}{u}^{10}
\textcolor{blue}{du}
\end{align*}

\end{document}


This outputs:

I am trying to recreate with a black box drawn around the orange shaded area.

Using tikzmark, it is not so difficult:

\documentclass{article}
\usepackage{amsmath, mathtools,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}

\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\ dx &=\int (\textcolor{red} {x^{3}+1})^{10} \textcolor{blue}{3x^{2}\ dx} \tikzmark{eqt}\\
&=\int \textcolor{red}{u}^{10}\textcolor{blue}{du}
\end{align*}

\begin{tikzpicture}[overlay, remember picture]
\coordinate (x) at ($(pic cs:eqt)+(1,0)$);
\draw (x)--($(x)+(3,0)$);
\draw[red] (x) node[above right] {Substitution};
\draw ($(x)+(3,0)$) node[right,draw,fill=orange!50] {%
% Remove draw' option if you don't want the box
\begin{aligned} u&=x^3+1,\\ du&=3x^2dx \end{aligned}};
\end{tikzpicture}

\end{document}


This very nice and creative solution is by @marmot:

\documentclass[fleqn]{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\,\mathrm{d}x
&\tikzmarknode{eq1}{=}\int (\textcolor{red} {x^{3}+1})^{10}
\textcolor{blue}{3x^{2}\, \mathrm{d}x} \\
&\tikzmarknode{eq2}{=}\int \textcolor{red}{u}^{10}\,\textcolor{blue}{\mathrm{d}u}
\end{align*}

\begin{tikzpicture}[overlay, remember picture]
\path (eq1) -- (eq2) coordinate[midway] (aux);
\draw[latex-] (eq2) -- (aux) -- ++ (5,0) node[above left] {substitute}
node[right,fill=orange!30] {%
\begin{aligned} u&=x^3+1\\ \mathrm{d}u&=3x^2\,\mathrm{d}x \end{aligned}};
\end{tikzpicture}
\end{document}


Without tikz, I define an extensible \xmathline, centred on the math axis, which accepts writing above and below it, like \xrightarrow, and add a simple \colorbox:

\documentclass[svgnames]{article}
\usepackage{amsmath, mathtools,tikz}
\usepackage{xcolor}
\usepackage{bigstrut}

\newcommand{\xmathline}[2][]{%
\ext@arrow 0099\xmathlinefill@{#1}{#2}}%
\newcommand{\xmathlinefill@}{%
\arrowfill@{\relbar\bigstrut}\relbar\relbar}
\makeatother

\begin{document}

\begin{align*}
\displaystyle\int 3x^{2}(x^{3}+1)^{10}\ dx &=\int (\textcolor{red}
{x^{3}+1})^{10} \textcolor{blue}{3x^{2}\ dx}
\quad\xmathline{\text{\color{Crimson}substitution\quad}}\colorbox{NavajoWhite! 60}{\begin{aligned} u & = x^3 + 1 \\ du & =3x^2\,dx \end{aligned}} \\%
&=\int \textcolor{red}{u}^{10}
\textcolor{blue}{du}
\end{align*}

\end{document}
`