Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I use the versions package to conditionally exclude content like this:

\documentclass{article}
\usepackage{color}% just as example

\usepackage[tracing]{versions}
\excludeversion{vers}% opposite to \includeversion{vers}

\newenvironment{test}{%
START%
\vers%
\color{red}%
}{%
\endvers%
END% is excluded but should not be excluded 
}

\begin{document}
before

\begin{test}
% content is excluded for \excludeversion{vers}
%        and included for \includeversion{vers} above
inside
\end{test}

after
\end{document}

I can exclude the content of the vers environment, as intended by the use of the versions package. But also END gets excluded (after \endvers), opposed to my intention. With \includeversion{vers} also END gets included (as intended). What do I do wrong, and how do I fix it?

It is possible to define

\newcommand{\afterendvers}{%
END% and all other stuff I want to have executed here
}

and replace \end{test} by \end{test}\afterendvers in the whole document, but a more "TeXnical" solution would be nice.

Related issue: With \includeversion{vers} END is printed in red, although

environments processed as if \begin{<version>} and \end{<version>} just were not present, however they form groups like \begin{relax} <code> \end{relax} or \begingroup <code> \endgroup

(from the versions manual), but

\vers%
\bgroup%
\color{red}%
}{%
\egroup%
\endvers%
END%

leads to END being written in black, as expected. I.e.: \vers and \endvers do not appear to act as \begingroup and \endgroup in this case.

share|improve this question
    
When excluded \vers contains a \let \end \fi and \iffalse, so will ignore everything until the next \end{<current environment>}, where the current environment is set by the last \begin, i.e. test here. I don't think this \end is expanded, so the \endvers% and END is never seen. –  Martin Scharrer Apr 20 '12 at 11:47
    
Looking further at the source code it looks to me that version doesn't support such a usage. –  Martin Scharrer Apr 20 '12 at 11:52
    
@MartinScharrer: Thanks for the explanation! Then I will probably have to write to Uwe Lück (versions author) to either improve the package to support such nesting (without an idea how to do so) or to write a warning into the documentation - if no ingenious answer is given later. –  Stephen Apr 20 '12 at 13:34
    
@MartinScharrer: I wrote an e-mail to Uwe Lück, the versions maintainer, and will give feed-back when I got an answer. –  Stephen Apr 29 '12 at 17:52
1  
@MartinScharrer: OK, I got feedback by Uwe Lück. You are right, and at the moment there is no update of the package planned. Could you turn your first comment into an answer, please? –  Stephen May 6 '12 at 17:52
show 2 more comments

2 Answers

up vote 3 down vote accepted

The problem occurs because when excluded \vers contains a \let\end\fi and \iffalse, so will ignore everything until the next \end{<current environment>}, where the current environment is set by the last \begin, i.e. test here. I don't think this \end is expanded, so the \endvers% and END in it is never seen.

I tried to figure out a way for this by looking at the source code of the versions package, but this just confirmed that such a usage is not supported by it. Larger rewrites of this package would be required for this.

share|improve this answer
add comment

I'm not sure what your actual use case is, but it seems like your MWE is supposed to conditionally color some text based on the version. This works for me:

\documentclass{article}
\usepackage{color}% just as example
\usepackage[tracing]{versions}
\excludeversion{vers}

\def\colorbyversion{\normalcolor}
\begin{vers}
\gdef\colorbyversion{\color{red}}
\end{vers}

\newenvironment{test}{
START
\bgroup\colorbyversion}{%
\egroup
END% should not be excluded
}

\begin{document}
before

\begin{test}
inside
\end{test}

after
\end{document}

With \includeversion{vers}:

sample document with vers included

With \excludeversion{vers}:

sample document with vers excluded

The \gdef is needed to make the redefinition of \colorbyversion global. Otherwise, the definition inside the vers environment dies at \end{vers}.

share|improve this answer
1  
You should add \ignorespaces after \colorbyversion in the definition of test. –  egreg Apr 20 '12 at 12:40
    
@Matthew Leingang: Unfortunately not. color really was an example. Your solution does not exclude inside with \excludeversion{vers}, as you wrote yourself. –  Stephen Apr 20 '12 at 12:43
    
@egreg: you are right. –  Matthew Leingang Apr 20 '12 at 12:57
1  
@Stephen: Sorry about that. Could you edit your question emphasizing the effect you want (and not just the implementation that isn't working)? –  Matthew Leingang Apr 20 '12 at 12:59
2  
@Stephen: Thanks. Asking questions is tough. I try to stick ESR's FAQ on how to ask a question, especially this part: Describe the goal, not the step –  Matthew Leingang Apr 20 '12 at 14:41
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.