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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question led to a new package:

I'm trying to work out options for configuring a large memoir to multiple audiences via multiple editions.

Obviously one method of doing this is by building a master set of sections and then combining them into several different master documents which are basically a string of \input{} commands.

Another might be to define a set of section id environments and then include or exclude them with \newcomment{} \commentson{} and commentsoff{}

Yet another way would be an inverse of this: to tag each section with one or more labels. Something like this:

\chapter{A Simple Introduction}
\chapter{A Complex Introduction}
\chapter{How to erase the system}

where I could then do something at the start like:


to build the "System Programmer" edition.

Is there a package that will do something like this?

Accepted @Leo Liu's answer. Bril.

share|improve this question
FWIW, in ConTeXt this feature is called modes. – Aditya May 17 '12 at 3:32
up vote 16 down vote accepted

There is a xcomment package, it isn't tagged, but useful for this kind of question. See also


Here is what you want:




     \ifcsname tagged@##1\endcsname





\begin{tagged}{a, x}
aaaa xxxx

\begin{tagged}{b, c, x}
bbbb cccc xxxx


It's not difficult to implement. Whitespace after commas is ignored.

share|improve this answer
That looks brilliant, and much simpler than I had feared. Going off to have a play with it, back soon... – Brent.Longborough Feb 13 '11 at 19:17
Accepted, +1. Brilliant. Worth an extra upvote just for the line \usepackage{etoolbox}. – Brent.Longborough Feb 13 '11 at 19:39
A previous version does not contain etoolbox. I used \@for and \@namedef, which is not more complex. I use etoolbox to ignore the extra spaces. However, unlike keyval, spaces before commas is not ignored. You can use \ForEach in forarray package or other trick to ignore more spaces. – Leo Liu Feb 13 '11 at 19:55

The `tagging' package is now on CTAN, providing the following commands:

\tagged{list}{yes}            % Conditional inclusion
\untagged{list}{no}           % Conditional exclusion
\iftagged{list}{yes}{no}      % Conditional inclusion/exclusion
\begin{taggedblock}{list}     % Conditionally included environment
    \end{taggedblock}         %
\begin{untaggedblock}{list}   % Conditionally excluded environment
    \end{taggedblock}         %
\usetag{list}                 % Turn tags on
\droptag{list}                % Turn tags off

My thanks to Leo Liu, for his original answer on which the work is based.

share|improve this answer
Good job. I've just seen this package on CTAN-ann mailing list. – Leo Liu Aug 29 '11 at 17:31
Thanks, @LeoLiu, the credit's largely yours... – Brent.Longborough Aug 29 '11 at 23:41

Your Answer


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.