14

This question led to a new package:
tagging

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:

\begin{tagged}{managers,library}
\chapter{A Simple Introduction}
...
\end{tagged}
\begin{tagged}{sysprogs,library}
\chapter{A Complex Introduction}
...
\end{tagged}
\begin{tagged}{sysprogs,administrators}
\chapter{How to erase the system}
...
\end{tagged}

where I could then do something at the start like:

\usetag{sysprogs}

to build the "System Programmer" edition.

Is there a package that will do something like this?


Accepted @Leo Liu's answer. Bril.

  • 1
    FWIW, in ConTeXt this feature is called modes. – Aditya May 17 '12 at 3:32
17

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

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=conditional


Here is what you want:

\documentclass{minimal}

\usepackage{verbatim}
\usepackage{etoolbox}

\newcommand\usetag[1]{%
  \def\do##1{\csdef{tagged@##1}{}}%
  \docsvlist{#1}}

\newenvironment{tagged}[1]%
  {\def\do##1{%
     \ifcsname tagged@##1\endcsname
       \let\comment\relax
       \let\endcomment\relax
     \fi}%
   \docsvlist{#1}
   \comment}%
  {\endcomment}

\begin{document}

\usetag{a,b,c}

\begin{tagged}{a}
aaaa
\end{tagged}

\begin{tagged}{x}
xxxx
\end{tagged}

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

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

\end{document}

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

  • 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
6

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.

  • 1
    Good job. I've just seen this package on CTAN-ann mailing list. – Leo Liu Aug 29 '11 at 17:31
  • I was very happy when I found tagging. Does this package have the ability to list the tags in use? Somewhat along the lines of tex.stackexchange.com/questions/37928/… – A Feldman Mar 19 '16 at 18:23
  • @AFeldman I'm sorry, I have good news: I'm in the process of freezing and deprecating tagging, in favour of Boris Veytsman's multiaudience, which I think does a better job. tagging will remain on CTAN, in order not to force current users to migrate, but there will no further development, and no bug or feature requests will be accepted. – Brent.Longborough Mar 19 '16 at 20:25
  • @Brent.Longborough much obliged for the response. I will take a look at multiaudience. – A Feldman Mar 20 '16 at 15:36
  • 1
    @Brent.Longborough the tagging documentation is very understandable. I found myself wishing that the same was true with multiaudience, which I found a little confusing. Is there a technical reason why multiaudience is better? – A Feldman Mar 20 '16 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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