1

I am trying to pass some tags to the command \iftagged from the package tagging. See the MWE below.

From what I understand, my macro \mytags does not get expanded. I found a lot of similar questions here, but still cannot figure it out. Please help!

\documentclass[10pt]{article}

\usepackage{tagging}

\begin{document}

\newcommand{\mytags}{%
tagone,
tagtwo,
tagthree
}

\usetag{tagone}

% Command
\iftagged{\mytags}{Tags passed to the command successfully!}{Tags not passed to the command!}

% Environment
\begin{taggedblock}{\mytags}
    Tags passed to the environment successfully!
\end{taggedblock}

\begin{taggedblock}{tagone,tagtwo,tagthree}
    Tags passed directly successfully!
\end{taggedblock}

\end{document}

The result I get:

Tags not passed to the command!
Tags passed directly successfully!

Edit:

\iftagged and \begin{taggedblock} are commands from the package tagging.

Basically, I need to have \iftagged{\mytags} replaced with \iftagged{tagone,tagtwo,tagthree} during compilation. The same with \begin{taggedblock}{\mytags}.

4
  • You need to specify the number of variables passed, and use their "names" #1, #2, ... See here for details: en.wikibooks.org/wiki/LaTeX/Macros . It's still a macro-system, which does not use (undeclared!) variable names as we are used to from (some) programming languages.
    – MS-SPO
    Apr 27, 2022 at 8:40
  • @MS-SPO Thank you! Tried adding the [num] argument, but it did not help. And this argument seems to be optional. I just need to pass the string of tags as one variable.
    – f-hollow
    Apr 27, 2022 at 8:48
  • Please update your code using the Edit button, perhaps you still miss a point. Unlike in other fori here is little room for discussions ;)
    – MS-SPO
    Apr 27, 2022 at 9:41
  • Sorry, I am not sure what you mean. Maybe the title confused you. I just need to have \mytags replaced with the string tagone,tagtwo,tagthree. I don't need to pass variables as #1, #2 anywhere. If I am still missing your point, can you please provide an answer? :)
    – f-hollow
    Apr 27, 2022 at 10:12

1 Answer 1

1

The command \iftagged does no expansion on its first argument.

You might want to do

\expandafter\iftagged\expandafter{\mytags}{...}{...}

or take a bigger step and do the expansion right away (it should not be risky, because tags are simple strings of characters). Do the same also to \taggedblock.

\documentclass[10pt]{article}

\usepackage{tagging}
\usepackage{etoolbox}

% replace \docsvlist in \iftagged with \xdocsvlist
\patchcmd{\iftagged}{\docsvlist}{\xdocsvlist}{}{}
\patchcmd{\taggedblock}{\docsvlist}{\xdocsvlist}{}{}
% \xdocsvlist fully expands its argument before passing it to \docsvlist
\newcommand{\xdocsvlist}[1]{%
  \expandafter\docsvlist\expandafter{\expanded{#1}}%
}

\begin{document}

\newcommand{\mytags}{%
tagone,
tagtwo,
tagthree
}

\usetag{tagone}

% Command
\iftagged{\mytags}{Tags passed to the command successfully!}{Tags not passed to the command!}

% Environment
\begin{taggedblock}{\mytags}
    Tags passed to the environment successfully!
\end{taggedblock}

\begin{taggedblock}{tagone,tagtwo,tagthree}
    Tags passed directly successfully!
\end{taggedblock}

\end{document}

enter image description here

4
  • \iftagged works! Now I am not sure how to apply this approach to \begin{taggedblock}{\mytags} ... \end{taggedblock}. Is it possible?
    – f-hollow
    Apr 27, 2022 at 11:14
  • @f-hollow Added as requested
    – egreg
    Apr 27, 2022 at 11:47
  • Everything works perfectly! I will try to wrap my head around it. Thank you so much!
    – f-hollow
    Apr 27, 2022 at 12:11
  • For future references: When using \begin{taggedblock}{\mytags} ... \end{taggedblock}, LaTeX throws an error 'not enough arguments for \begin{taggedblock} sometimes. My solution was to switch from the taggedblock environment to the command \tagged{\mytags}{...}.
    – f-hollow
    May 5, 2022 at 5:20

You must log in to answer this question.

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