2

We would like to use package tagging with xcookybooky to list recipes into categories based on multiple parameters (tags). The desired outcome would be two sections of soups:

a) soup AND meat

b) soup AND vegetable.

The tagging package support sorting with multiple tags, which behaves as OR operator for multiple tags. This results in listing all recipes containing tag soup or meat.

I looked into to package itself, but I do not understand enough to redefine new command which would perform AND operation between two lists.

Original code

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

How would you apply a filter on multiple tags (tag1 AND tag2) to a list of tagged recipes?

1 Answer 1

1

To achieve what you want it is necessary to rewrite essential parts of tagging.sty, therefore I suggest to create a file taggingx.sty with the following contents.

% Copyright 2021 Gernot Salzer
% Extension of tagging.sty v1.1.0.1 by Brent Longborough
% For the license, see tagging.sty
% ------------------------------------------------------
\ProvidesPackage{taggingx}[2021/01/11]
\RequirePackage{etoolbox,verbatim}

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

\newcommand\numberOfTagsToMatch[1]{\def\@numberOfTagsToMatch{#1}}
\numberOfTagsToMatch{1}
\newcounter{tagsMatched}

\newcommand{\iftagged}[3]{%
  \setcounter{tagsMatched}{1}%
  \def\do##1{%
    \ifcsname tagged@##1\endcsname
      \stepcounter{tagsMatched}%
    \fi
  }%
  \docsvlist{#1}%
  \ifnum\value{tagsMatched}>\@numberOfTagsToMatch
    \def\@tempa{#2}%
  \else
    \def\@tempa{#3}%
  \fi
  \@tempa
}
\newcommand{\tagged}[2]{\iftagged{#1}{#2}{}}
\newcommand{\untagged}[2]{\iftagged{#1}{}{#2}}

\newenvironment{taggedblock}[1]{%
  \tagged{#1}{%
    \let\comment\relax%
    \let\endcomment\relax%
  }%
  \comment\ignorespaces
}{%
  \endcomment\ignorespacesafterend
}
\newenvironment{untaggedblock}[1]{%
  \untagged{#1}{%
    \let\comment\relax
    \let\endcomment\relax
  }%
  \comment\ignorespaces
}{
  \endcomment\ignorespacesafterend
}

\DeclareOption*{\usetag{\CurrentOption}}
\ProcessOptions

This extension of the original package adds a command

\numberOfTagsToMatch{number}

which specifies the number of tags that have to be matched. The default is

\numberOfTagsToMatch{1}

which corresponds to the behavior of the original package.

To match two tags at the same time ('and' connective), define the tags and set this value to two.

\usetag{tag1,tag2}
\numberOfTagsToMatch{2}

Example: In the following document, all parts are included that are tagged with soup AND meat.

\documentclass{article}
\usepackage{taggingx}
\begin{document}
\usetag{soup,meat}
\numberOfTagsToMatch{2}

\begin{taggedblock}{soup,meat}
  Soup with meat.
\end{taggedblock}

\begin{taggedblock}{soup,vegetables}
  Soup with vegetables.
\end{taggedblock}

\begin{taggedblock}{soup,meat,vegetable}
  Soup with meat and vegetables.
\end{taggedblock}

\end{document}

enter image description here

You must log in to answer this question.

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