I want to let the users of a package define the name of command into which some unique content will be stuffed, so that they can then recall that content using the command name that they prefer. Is it a better practice to make them provide me a string, from which I create the command and stuff the content (as in \tokify
in my MWE) or is it preferable to let them tell me the actual (as yet undefined) command name and merely have me stuff the content (as in \populate
in my MWE)?
The MWE is simple enough that you might say "just let them create the \def
", but for the actual application, it will save them more keystrokes to let me create the content of the command.
\documentclass{article}
\usepackage{stringstrings}
\makeatletter
\newcommand\tokify[1]{%
\expandafter\def\csname#1\endcsname{Content: #1}%
}
\newcommand\populate[1]{%
\edef\sv@name{\expandafter\@gobble\detokenize{#1}}%
\noblanks[q]{\sv@name}%
\expandafter\def\csname\thestring\endcsname{Content: \thestring}%
}
\makeatother
\begin{document}
\tokify{xyz}
\xyz
\populate{\abc}
\abc
\end{document}