I want to have a keyword / tag / label / token system for my documents. There will be a hard coded list of allowed keywords and all theorems/examples/exercises will (optionally) be tagged with one of those keywords. Compiling the document should check whether a valid keyword is used as tag and (if required) print it.
I am trying to implement using the arrayjob
package. All my tags will be stored in a array called tagtoken
and a command \tagit
will do the job of actual tagging. I tried to hack the code with bits and pieces cargo-cult-lifted from various questions of tex.stackexchange. However I have no real knowledge of expl3
.
This is my MWE
\documentclass{article}
\usepackage{arrayjob,expl3,xparse,pgffor}
\newtheorem{theorem}{Theorem}
\newarray\tagtoken
\readarray{tagtoken}{RAG&TAG&BAG} % should be case insensitive
\newarray\tokenlist
\ExplSyntaxOn
\NewDocumentCommand{\tagit}{m}
{
\tl_set:Nn \l_tmpa_tl {\tl_lower_case:n{#1}}
\regex_replace_all:nnN {,} {&} \l_tmpa_tl
\regex_replace_all:nnN {\s+} {} \l_tmpa_tl
\readarray{tokenlist}{\l_tmpa_tl} % does not work
\regex_replace_all:nnN {&} {, } \l_tmpa_tl % just for displaying
\newline Keywords = \tl_use:N \tl_upper_case:n{\l_tmpa_tl}
}
\ExplSyntaxOff
\begin{document}
\begin{theorem}
Dummy theorem \tagit{g,h , k, rag, TAG} % should throw an error and stop compilation till invalid tokens are purged.
\end{theorem}
%\foreach\x in {1,...,3} {\noindent tagtoken(\x) = \tagtoken(\x)\hfil\\}
one = \tokenlist(1) % no output
\begin{theorem}
two \tagit{rag,TaG} % no error
\end{theorem}
\begin{theorem}
three \tagit{rag, RAg} % should produce a warning for repeated tags
\end{theorem}
\end{document}
How do I make it work? Sorry for asking a cargo-cult question.
\tagit
command should check if the tags are valid, check for duplicates and then print a list of keys a the end of the environment. Is that right? If this is all that you want then this is easy to do with LaTeX3 sequences -- and I don't understand the use/need for the regular expressions in the definition of the\tagit
macro.