# Defining ‘commands’ or ‘macros’ with unicode names

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}$


producing

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?

Thanks!

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

\documentclass{article}
\begin{document}
\makeatletter
\@namedef{\detokenize{qty: β2 activity}}{bllb}

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

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

\end{document}


For brevity, you may define something like

\makeatletter
\newcommand\newshortcut[2]{\@namedef{\detokenize{#1}}{#2}}
\newcommand\shortcut[1]{\@nameuse{\detokenize{#1}}}
\makeatother


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