在以下 MWE 中
\documentclass{article}
\usepackage{amsmath, xcolor, comment}
% \specialcomment{details}{\begingroup\color{gray}}{\endgroup} % This does not work with aligned
\includecomment{details}
% \excludecomment{details} % Uncomment to exclude details.
\begin{document}
This is my calculation:
\[\begin{aligned}
&X = Y\\
\begin{details}
&=Y_{1} \\ &\leq Y_{2}
\end{details}
&\le Z
\end{aligned}\]
\begin{details}
These are even more details: \[A = B\]
\end{details}
\end{document}
我定义了一个details
环境,用它来封装详细的计算,我可以选择性地隐藏这些计算(通过使用 取消注释该行excludecomment
)。以前的环境即使aligned
在使用comment
包的环境中也能很好地工作。但是,我想修改环境,使细节变成灰色。最明显的修改(使用specialcomment
)不适用于aligned
。我认为这是因为环境中的单元格aligned
不能用组来拆分。
有没有办法在继续工作的同时定义这样的环境aligned
?
编辑:任何解决方案都会受到欢迎,即使它不涉及评论。
答案1
details
如果你像这样定义特殊注释,那么它就会起作用:
\specialcomment{details}{%
\global\everymath{\color{gray}}%
\global\everydisplay{\color{gray}}%
\color{gray}%
}{%
\global\everymath{\normalcolor}%
\global\everydisplay{\normalcolor}%
\normalcolor
}
问题是,aligned
除非将单元格内的定义设为全局定义,否则单元格内的任何定义都是局部的。在一个单元格中打开一个组并在另一个单元格中关闭它不起作用。
详细信息包括:
排除的详细信息:
\documentclass{article}
\usepackage{amsmath, xcolor, comment}
\specialcomment{details}{%
\global\everymath{\color{gray}}%
\global\everydisplay{\color{gray}}%
\color{gray}%
}{%
\global\everymath{\normalcolor}%
\global\everydisplay{\normalcolor}%
\normalcolor
}
%\excludecomment{details} % Uncomment to exclude details.
\begin{document}
This is my calculation:
\[\begin{aligned}
&X = Y\\
\begin{details}
&=Y_{1} \\ &\leq Y_{2}
\end{details}
&\le Z
\end{aligned}\]
\begin{details}
These are even more details: \[A = B\]
\end{details}
\end{document}
答案2
根据@gernot 的解决方案,以及我在评论中提到的修复,该修复align
在第一次使用后不会中断details
,
\documentclass{article}
\usepackage{amsmath, xcolor, comment}
\makeatletter
\specialcomment{details}{%
\xdef\@oldeverymath{\the\everymath}%
\xdef\@oldeverydisplay{\the\everydisplay}%
\global\everymath\expandafter{\@oldeverymath\color{gray}}%
\global\everydisplay\expandafter{\@oldeverydisplay\color{gray}}%
\color{gray}%
}{%
\global\everymath\expandafter{\@oldeverymath}%
\global\everydisplay\expandafter{\@oldeverydisplay}%
\normalcolor%
}
\makeatother
%\excludecomment{details} % Uncomment to exclude details.
\begin{document}
This is my calculation:
\[\begin{aligned}
&X = Y\\
\begin{details}
&=Y_{1} \\ &\leq Y_{2}
\end{details}
&\le Z
\end{aligned}\]
\begin{details}
These are even more details: \[A = B\]
\end{details}
\begin{align}
A&=B\\
% \begin{details} % Not supported by comment package
% &=C\\
% \end{details}
&=D
\end{align}
\end{document}
另一方面,由于某种原因,使用comment
内部环境align
似乎不受支持,因此details
由于类似的原因在那里不起作用。