可选用其他颜色打印的文本

可选用其他颜色打印的文本

我想扩展该version包以打印一些可选添加的不同颜色的文本。如以下示例所示:

\documentclass{article}
\usepackage{version}
\usepackage{xcolor}
\includeversion{mynote} % Like this it works.
%\excludeversion{mynote} % Like this it doesn't work.
\newenvironment{note}{\begin{mynote}\color{red}}{\end{mynote}}
\begin{document}
Some text. \begin{note}And a note.\end{note} And some more text.
\end{document}

如果我在该\includeversion{mynote}行中发表评论,它就会起作用:

输出

但如果我切换到该\excludeversion{mynote}行,我会得到以下信息:

Runaway argument?


! File ended while scanning use of \@Vii@ExcludeToEnd.
<inserted text> 
                \par 

答案1

您的\end{mynote}不被视为输入流的一部分,因为它隐藏在 中\end{note}。您可以使用不同的技术并捕获整个note环境内容,然后将其传递到“干净”(或更可见)的mynote环境:

\documentclass{article}
\usepackage{version,xcolor,environ}
%\includeversion{mynote} % Like this it works.
\excludeversion{mynote} % Like this it works.
%\newenvironment{note}{\begin{mynote}\color{red}}{\end{mynote}}
\NewEnviron{note}{\begin{mynote}\color{red}\BODY\end{mynote}}
\begin{document}
Some text. \begin{note}And a note.\end{note} And some more text.
\end{document}

environ允许您捕获里面的环境内容\BODY

相关内容