How can I implement the rough equivalent of \def\macro{expansion} so that the macro name can contain spaces and other unicode characters? I’d like to be able to do the following, for example:

\defineinsert{qty: β2 activity}{\SI{1.85}{\mega\becquerel}}
The measured activity was \insert{qty: β2 activity}.
$R_\beta = \insert{qty: β2 activity}$


The measured activity was \SI{1.85}{\mega\becquerel}.
$R_\beta = \SI{1.85}{\mega\becquerel}$

The motivation is to be able to pre-define many orderly ‘macros’ in to be used throughout a document, without the restriction that characters must only be [a-zA-Z], as imposed by using \def to define actual commands.

I have no idea how to implement this, since I don’t know how one would create key-value mappings with TeX… or if that would be the right approach.

Perhaps there is another way of filling this need? Should I start using LuaTeX to accomplish this? (I am presently using XeLaTeX.) Perhaps there exists a package for this?



You can use \csname ...\endcsname for this. E.g with the help of \@namedef:

\@namedef{\detokenize{qty: β2 activity}}{bllb}

The beta activity \@nameuse{\detokenize{qty: β2 activity}}

The beta activity \@nameuse{\detokenize{qty: β2  activity}}


For brevity, you may define something like


which may be used like so:

\newshortcut{qty: β}{lola}
Hello \shortcut{qty: β}.
  • Furthermore, by defining \newcommand\shortcut[1]{\@nameuse{\detokenize{#1}}}, one may use \shortcut{qty: β} in the place of \@nameuse{\detokenize{qty: β}} for brevity! This is perfect. – Jollywatt May 1 '17 at 11:39

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.