This is a followup question to yesterdays question here.
I want to be able to generate my document in two different levels of detail.
- (When draft is not set): normal version
- (When draft option is used): more detailed version. Some additional explanation text is given. Some calculations include extra steps to make it more easy to follow. The additions should be colored differently (gray).
@JasperHabicht
Gave a nice solution if the only additions are lines in the aligned
environment.
Now I want my additions to be more flexible, i.e., insert text and equations. I already admitted that I did not understand the solution of @Jasper Habicht in the older question and that is why I cannot modify it to work as I want.
I modified the MWE to include the "old" solution:
\documentclass[
draft,
]{article}
\usepackage{amsmath}
\usepackage{ifdraft}
\usepackage{xcolor}
\ExplSyntaxOn
\NewDocumentCommand{\insertexplaincolor} { m } {
\tl_set:Nn \l__myexplcol_explcolbody_tl { #1 }
\regex_replace_all:nnN { \& } { \& \c{explaincolor} } \l__myexplcol_explcolbody_tl
\regex_replace_all:nnN { \c{\\} } { \c{\\} \c{explaincolor} } \l__myexplcol_explcolbody_tl
\tl_use:N \l__myexplcol_explcolbody_tl
}
\ExplSyntaxOff
\newcommand{\explaincolor}{\color{gray}}
\newcommand{\explain}[1]{%
\ifdraft{\insertexplaincolor{#1}}{}%
}
\begin{document}
\begin{equation}
\begin{aligned}
{(a + b)}^2
\explain{
& = (a + b)(a + b) \\
& = a^2 + ab + ba + b^2 \\
}
& = a^2 + 2ab + b^2
\end{aligned}
\end{equation}
It follows
\explain{%
using \(-b\) in the place of \(b\)
}
that
\begin{equation}
{(a - b)}^2 = a^2 - 2ab + b^2.
\end{equation}
\explain{%
There is also the third version
\begin{equation}
(a + b)(a - b) = a^2 - b^2.
\end{equation}
}
\end{document}
The insertions are made correctly depending on the draft
option. The color however is only correct within the first aligned
.
Ty once more for your help. Franz