I'm trying to make a class following my school's standard for thesis and I got a problem when I tried to implement a list of acronyms, because this list should be alphabetically sorted and the packages that I found were incompatible with my implemented class. So I decide to make my own implementation using arrays.
I can create arrays as \foo#1
(in which each element of array receive as new index in #1
, using \csname foo#1 \endcsname
), but to sort this array I need to insert an element in a specific position of the array.
An example of my code at now is:
\documentclass[]{report}
\newcounter{countArrayTest}
\setcounter{countArrayTest}{0}
\newcommand{\appendElement}[1]{%
\expandafter\newcommand\csname arraytest\the\value{countArrayTest} \endcsname{#1}
\stepcounter{countArrayTest}
}
\newcommand{\getIndexElement}[1]{
\csname arraytest#1 \endcsname
}
\newcommand{\testInsert}{%
\expandafter\renewcommand\csname arraytest1 \endcsname{\getIndexElement{0}}
\expandafter\renewcommand\csname arraytest0 \endcsname{Test1}
}
\newcounter{CountTempAux}
\newcommand{\showAll}{%
\setcounter{CountTempAux}{0}
\loop\ifnum\value{CountTempAux}<\value{countArrayTest}
\csname arraytest\the\value{CountTempAux} \endcsname
\stepcounter{CountTempAux}
\repeat
}
\begin{document}
\appendElement{Element1}
\appendElement{Element2}
\testInsert
\showAll
\end{document}
The problem is, I expected the answer "Test1 Element1", but I got "Test1 Test1".
Any suggestion to solve this problem?
\testInsert
to\newcommand{\testInsert}{\expandafter\edef\csname arraytest1 \endcsname{\getIndexElement{0}} \expandafter\edef\csname arraytest0 \endcsname{Test1} }
yields the desired result, but not sure if that shows what you are trying to do is working correctly.\g@addto@macro
as described in How keep a running list of strings and then process them one at a time and then sort via Sorting Comma Separated Lists defined with, or without macro.