Generaltoken in \@for:= loop not being expanded

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
demac
Posts: 6
Joined: Thu Jun 17, 2010 9:27 pm

token in \@for:= loop not being expanded

Post by demac »

I am trying to define a macro that will take a comma separated list of strings and create macros based on the string. The problem is that it does not expand the iteration variable (\@@a) in this case when put into the list.

Here is the code:

Code: Select all

\documentclass[12pt]{article}
\usepackage{xfor}

\gdef\ac#1{\bfseries #1!!!}

\gdef\setOneAcronym#1{\expandafter\newcommand\csname#1\endcsname{\ac{#1}}}

\makeatletter
\gdef\setAcronyms#1{\@for\@@a:={#1}\do{\setOneAcronym\@@a}}
\setAcronyms{GR,UZ,LZ}
\makeatother

\begin{document}

The acronym for GR is \GR\ or (\ac{GR}).

\end{document} 
The \setOneAcronym works by itself, but when the control sequence is called in the document I get
! Undefined control sequence.
\@@a->\@nil

l.17 The acronym for GR is \GR
\or (\ac{GR}}.

What do I need to change to get the \@@a to expand.

Thanks
Jeff

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

token in \@for:= loop not being expanded

Post by josephwright »

I think you are after

Code: Select all

\documentclass[12pt]{article}
\usepackage{xfor}

\gdef\ac#1{\bfseries #1!!!}

\gdef\setOneAcronym#1{\expandafter\newcommand\csname#1\endcsname{\ac{#1}}}

\makeatletter
\gdef\setAcronyms#1{%
  \@for\@@a:=#1\do{\expandafter\setOneAcronym\expandafter{\@@a}}}
\setAcronyms{GR,UZ,LZ}
\makeatother

\begin{document}
\sh
The acronym for GR is \GR\ or (\ac{GR}).

\end{document} 
Joseph Wright
Post Reply