2

I am trying to define a command that would easily create aliases for acronyms defined with the acro package. I would like to define dozens of aliases of different acronyms without having to duplicate the definitions, and the use of any alias would mark the acronym as used globally. Then, I want to keep the aliases and the original acronyms distinct, printing them with different commands, so that I can define i.e. an alias abc for xyz even there is an acronym abc independently defined.

Ideally, I would like to be able to type something like:

\DeclareAcronym{xyz}{short=xyz, long={X, X, and Z}}
\DeclareAcronymAlias{abc}{xyz}
\aliasac{abc}

with \aliasac{abc} producing the same result as \ac{xyz}.

My idea was to first create a command \DeclareAcronymAlias that takes 2 arguments and defines another command whose name includes argument #1 (\acroalias#1) and whose definition is argument #2, the target acronym's ID. Then another command \aliasac is defined: it takes 1 argument and passes the expanded command \acroalias#1 (i.e. the target acronym's ID) to the acronym printing command \ac. But I get an error.

Here is a minimal example:

\documentclass[a4paper,10pt]{article}
\usepackage{acro}
\DeclareAcronym{xyz}{short=xyz, long={X, X, and Z}}

\newcommand{\DeclareAcronymAlias}[2]{%
  \expandafter\newcommand\csname acroalias#1\endcsname{#2}%
}
\newcommand{\aliasac}[1]{%
  \expandafter\ac{\csname acroalias#1\endcsname}%
}
\DeclareAcronymAlias{abc}{xyz}

\begin{document}
\aliasac{abc}
\printacronyms
\end{document}

1 Answer 1

2

You need to expand the argument more.

\documentclass[a4paper,10pt]{article}
\usepackage{acro}
\DeclareAcronym{xyz}{short=xyz, long={X, X, and Z}}

\ExplSyntaxOn
\newcommand{\DeclareAcronymAlias}[2]
 {
  \tl_new:c{g_loto_acroalias_#1_tl}
  \tl_set:cn{g_loto_acroalias_#1_tl}{#2}
 }

\newcommand{\aliasac}[1]
{
 \exp_args:Nf\ac{\tl_use:c{g_loto_acroalias_#1_tl}}
}

\ExplSyntaxOff
\DeclareAcronymAlias{abc}{xyz}

\begin{document}
\aliasac{abc}
\printacronyms
\end{document}
4
  • Perfect! But how can I do that with standard LaTeX2e syntax?
    – lotomat
    Aug 20, 2018 at 18:31
  • 2
    With tons of \expandafter ;-). I'm using expl3 as it makes such things much better readable. As acro is using expl3 too, it fits imho quite well. Aug 20, 2018 at 18:33
  • Just out of curiosity, where in my code would I need those tons of \expandafter?
    – lotomat
    Aug 20, 2018 at 18:45
  • The solution works perfectly except if instead of \ac I use one of the more basic command defined by acro, like \acro_use:n
    – lotomat
    Aug 20, 2018 at 21:16

You must log in to answer this question.

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