我有一份文档,我想打印几个(比如说 10 个)不同的版本。有些部分只是草稿,其他部分或多或少已经完成,有些已经准备好出版等等。我想关联一个介于 1 和 10 之间的数字,称为发布级别,到文本的每个部分。一开始我想指定一个全局的出版级别,假设为 5,我想要打印文本的所有部分,其发布级别 >=5。
由于已经有多个可用于处理条件打印的包,因此我想使用它们来解决这个问题。以下代码使用comment
。
按照如下所述,使用\rlcheckstatus
和rltext
可以正常工作,但仅结合两个命令的环境rlctxt
会产生错误:! File ended while scanning use of \next.<inserted text> \par
我尝试使用versions
其他方法,但还是出现了同样的问题。有没有什么方法可以解决这个问题?
\documentclass{scrartcl}
\usepackage{ifthen}
\usepackage{comment}
\newcounter{rlpublvl} %this counter stores the publication level
\newcommand{\rlstetpublvl}[1]{\setcounter{rlpublvl}{#1}} %sets the publication level to #1
\newenvironment{rltext}{}{}
\newcommand{\rlcheckstatus}[1]{ %activates the environment rltext if #1 >= rlpublvl
\addtocounter{rlpublvl}{-1}
\ifthenelse{#1 > \value{rlpublvl}}
{\includecomment{rltext}}
{\excludecomment{rltext}}
\addtocounter{rlpublvl}{1}
}
\newenvironment{rlctxt}[1]{\rlcheckstatus{#1}
\begin{rltext}}{\end{rltext}}
\begin{document}
\rlstetpublvl{5} %global publication level set to 5
\rlcheckstatus{5} %this is printed
\begin{rltext}
This is ready for publication.
\end{rltext}
\rlcheckstatus{0} %this is not printed
\begin{rltext}
This part is still under construction.
\end{rltext}
\rlcheckstatus{7} %this is again printed
\begin{rltext}
This part is good again.
\end{rltext}
\begin{rlctxt}{3} %this does not work
foo
\end{rlctxt}
\end{document}
答案1
我相信这是逐字/注释之类的宏的一个标准问题,这些宏要求\begin
和\end
明确出现在代码中,并且当它们被包装在环境中时事情就会变得复杂。
我会用包裹environ
由于您已经将内容包装在环境中,因此可以这样做:
\NewEnviron{rlctxt}[1]{%
\addtocounter{rlpublvl}{-1}%
\ifthenelse{#1 > \value{rlpublvl}}%
{\BODY}%
{} %
\addtocounter{rlpublvl}{1}%
}%
是\BODY
只有在适当条件下才会排版的环境主体。
笔记:
代码:
\documentclass{scrartcl}
\usepackage{environ}
\usepackage{ifthen}
\usepackage{comment}
\newcounter{rlpublvl}% %this counter stores the publication level
\newcommand{\rlstetpublvl}[1]{\setcounter{rlpublvl}{#1}}% %sets the publication level to #1
\newenvironment{rltext}{}{}%
\newcommand{\rlcheckstatus}[1]{% %activates the environment rltext if #1 >= rlpublvl
\addtocounter{rlpublvl}{-1}%
\ifthenelse{#1 > \value{rlpublvl}}%
{\includecomment{rltext}}%
{\excludecomment{rltext}} %
\addtocounter{rlpublvl}{1}%
}%
%\newenvironment{rlctxt}[1]{\rlcheckstatus{#1}
% \begin{rltext}}{\end{rltext}}
\NewEnviron{rlctxt}[1]{%
%\rlcheckstatus{#1}%
\addtocounter{rlpublvl}{-1}%
\ifthenelse{#1 > \value{rlpublvl}}%
{\BODY}%
{} %
\addtocounter{rlpublvl}{1}%
}%
\begin{document}
\rlstetpublvl{5} %global publication level set to 5
\rlcheckstatus{5} %this is printed
\begin{rltext}
This is ready for publication.
\end{rltext}
\rlcheckstatus{0} %this is not printed
\begin{rltext}
This part is still under construction.
\end{rltext}
%-------
\begin{rlctxt}{5}% %this is printed
This is ready for publication.
\end{rlctxt}
\begin{rlctxt}{0}% %this is not printed
This part is still under construction.
\end{rlctxt}
\end{document}