0

When I call the acronym "CAD" statically with my own command accad I can call the corresponding acronym indirectly without a problem.

But if I try to call it dynamically with the (in the MWE) commented out sections the compilation apparently stops at the definition of defGLS.

MWE:

\documentclass{scrartcl}

\usepackage[acronym]{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{ac:cad}{CAD}{Computer Aided Design}

\newcommand{\accad}{\gls{ac:cad}}

%\makeatletter %\newcommand{\defGLS}[1]{ % @namedef{#1}{\gls{ac:#1}} %\makeatother

%\defGLS{cad}

\begin{document}

\accad

%\cad

\printglossaries

\end{document}

I tried to use \expandafter in different positions in the line of \@namedef (before and/or after it as well as before \gls...) but to no avail.

Lukas
  • 659

1 Answers1

1

Try this code.

First define a \creator of new commands.

\create{<command name>}

Then call it to create the new commands with the desired result. In this example it is done 3 times, once for each defined acronym.

\documentclass{scrartcl}

\usepackage[acronym]{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{cad}{CAD}{Computer Aided Design}
\newacronym{AC}{AC}{Alternating Current}
\newacronym{saas}{SaaS}{Software as a Service}

%********************************************* added \newcommand{\create}[1]{% \create{<command name>} \expandafter\newcommand\csname #1\endcsname{\gls{#1}\par}
}

\create{cad} \create{AC} \create{saas}

%************************************************

\begin{document}

\textbf{First time}

\verb|\cad|:    \cad

\verb|\AC|: \AC

\verb|\saas|:   \saas

\bigskip

\textbf{Second time}

\verb|\cad|:    \cad

\verb|\AC|: \AC

\verb|\saas|:   \saas

\printglossaries

\end{document}

b

Your code using \@namedef will work after correcting the definition of \defGLS (a missing brace)

\makeatletter
\newcommand{\defGLS}[1]{%
   \@namedef{#1}{\gls{#1}}%
}% <<<<<<<<<<<<<<<<<<<<
\makeatother

\defGLS{cad}

Simon Dispa
  • 39,141
  • Thank you for your input. With your code I can call the acronym indirectly with the \defGLS command but unfortunately not with the \cad command I intended to create in my MWE. Is there any possibility to define this command \cad inside the \defGLS command? – Lukas Apr 27 '22 at 20:44
  • @Lukas Please explain me the purpose of \cad and its intended output. Thank you! – Simon Dispa Apr 27 '22 at 20:57
  • The command \cad which is dynamically created with \glsDEF{cad} should call the acronym \gls{ac:cad}. If this works as intended I can create different commands in relation to the respective acronym. – Lukas Apr 27 '22 at 21:09
  • The base solution with namedef I got from here: https://tex.stackexchange.com/a/34709/244141 and tried to adapt it for acronyms. – Lukas Apr 27 '22 at 22:05
  • 1
    @Lukas Please see the updated the answer. – Simon Dispa Apr 28 '22 at 03:26