4

I have a document which I want to print in several (let's say 10) different versions. Some parts are just a draft, others are more or less finished, some are ready for publication and so on. I would like to associate a number between 1 and 10, called Release Level, to each part of the text. In the beginning I would like to specify a global Publication Level, let's say 5, and I want all parts of the text printed, which have a Release Level >=5.

Since there are already multiple packages available dealing with conditional printing I would like to use them to solve the problem. The following code uses comment.

Using \rlcheckstatus and rltext works fine as described below, but the environment rlctxt, which just combines both commands produces the error: ! File ended while scanning use of \next.<inserted text> \par

I tried to use versions instead, but this produces the same problem. Is there any way around that problem?

\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 Answer 1

1

I believe this is a standard problem with verbatim/comment like macros that require the \begin and \end to appear explicitly in the code and things get complicated when they are are wrapped in an environment.

I would use the environ package to do this since you are already wrapping the content within an environment:

\NewEnviron{rlctxt}[1]{%
    \addtocounter{rlpublvl}{-1}%
    \ifthenelse{#1 > \value{rlpublvl}}%
        {\BODY}%
        {} %
    \addtocounter{rlpublvl}{1}%
}%

The \BODY is the body of the environment that only gets typeset under the appropriate condition.

Note:

Code:

\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}
3
  • Well.. I used it for a while and came across a new problem: I use synctex to jump between my editor and the pdf-file. And apparantly synctex synchronizes the document only up to environments. Therefore, if you use this package and have huge environments, synctex becomes quite useless. This is rather annoying. Is there anyway around this?
    – Meneldur
    Mar 25, 2012 at 18:23
  • @Meneldur: That seems like a very good question, so please new post a new question. You can link to this question if needed. That way it can benefit others who encounter a similar problem. Also, please keep in mind that it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Mar 25, 2012 at 18:53
  • Good idea, I did exactly that: tex.stackexchange.com/questions/50194/synctex-and-environments
    – Meneldur
    Mar 31, 2012 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .