Edit:
My objective is to sort a group of output strings, which are specified through names/codes.
- There are effectively 3 components, the 'memorable codes' (names like Xenia, Alex, etc), the 'sorting key' (numbers like 1, 2, etc), and the 'anonymized code' (Interview1, Interview2, etc). My example (below) conflates the sorting key and anonymized code and tries to sort on the anonymized code.
- The anonymized code and the sorting key are both subject to change between different drafts of the paper. Hence, they should be defined in one place and not be directly used anywhere in the text.
- The memorable code is what the authors will use in the body text when they want the anonymized code to be written in the output. Wherever the anonymized codes are to be output, they should be output in order, sorted by their sorting key.
I'm using Steven's second solution. The output I was seeking is captured with:
Sorted anonymous (input by interviewees): \sortinterviewees{John, Julia, Xenia, Lucy}\par
Original (was titled: Sorting macros containing alphanumeric subscript)
I'm trying to produce sorted output and am using the revised sort by David posted here. I would like to know how this can be adapted to work with mixed alpha-numeric text containing subscript characters.
Minimal example:
\documentclass{article}
\usepackage{xspace}
%%% -- Copied sort -- %%%
\newcommand\alphabubblesort[1]{\def\sortedlist{}\expandafter\sortlist#1,\cr,\relax}
\def\sortlist#1,#2,#3\relax{%
\let\next\relax
\ifx\cr#2\relax%
\edef\sortedlist{\sortedlist#1}%
\else
\picknext#1!,#2!\relax%
\if F\flipflop%
\edef\sortedlist{\sortedlist#1,}%
\def\next{\sortlist#2,#3\relax}%
\else%
\let\tmp\sortedlist%
\def\sortedlist{}%
\def\next{\expandafter\sortlist\tmp#2,#1,#3\relax}%
\fi%
\fi%
\next
}
\def\picknext#1#2,#3#4\relax{%
\ifnum\the\lccode`#1<\the\lccode`#3\relax
\xdef\flipflop{F}%
\else%
\ifnum\the\lccode`#1>\the\lccode`#3\relax%
\xdef\flipflop{T}%
\else%
\ZZfifi{\picknext#2!,#4!\relax}%
\fi%
\fi%
}
%%% ----------------- %%%
\newcommand\interview[1]{Interview$_{#1}$\xspace}
%% Edit: added in some additional interviews.
\newcommand\Julia{\interview{1}}
\newcommand\Lucy{\interview{2}}
\newcommand\Alex{\interview{3}}
\newcommand\Xenia{\interview{4}}
\newcommand\John{\interview{5}}
\newcommand\Jane{\interview{6}}
\begin{document}
How it should look:
\Julia, \Alex, \Xenia.
But I'd like to be able to type:
\Alex, \Julia, \Xenia
This sort works on words only:
\alphabubblesort{Alex, Xenia, Julia}\sortedlist
\end{document}
Example output:
In this example, please assume that it's also possible that in the future both the formatting and the numbering will change (which is of course why the dynamic numbering is desired in the first place), e.g., one possible variation is:
\newcommand\interview[1]{\textit{I$_{#1}$\xspace}}
\newcommand\Julia{\interview{3}}
\newcommand\Alex{\interview{2}}
\newcommand\Xenia{\interview{1}}



In the original context, human-readable names would not be output nor used for sorting, only as an alias for the author. It is the anonymized codes (in this example numbers) which are sorted on. At the points where the author wants to reference them, s/he knows by name which people were interviewed, but has no recollection of what code each might currently be anonymized under.
In such a situation the only solution would be to sort manually, redoing it each time the coding system changes?
– Ann Mar 27 '19 at 13:00\expandafter\def\csname interview1\endcsname{Jenia}, etc. – Steven B. Segletes Mar 27 '19 at 13:05Interview$_{#1}$) and a 'memorable name' (in this example, the people's names). There is a relationship between the sort code and the formatted output but I think I unnecessarily conflated them in my question. The 'sort code' and 'formatted output' are defined at one point in the document, and might be reformatted, renumbered, etc. The 'memorable name' is constant from one draft of the document to the next, can be remembered, and is the only one which is written post-preamble. – Ann Mar 27 '19 at 13:35\documentclass[10pt]{article} \usepackage{xspace,pgffor} \newcommand\interview[1]{\textit{Interview$_{#1}$\xspace} (\csname interview#1\endcsname)} \expandafter\def\csname interview1\endcsname{Xenia} \expandafter\def\csname interview2\endcsname{Alex} \expandafter\def\csname interview3\endcsname{Julia} \begin{document} \foreach\x in{1,...,3}{\ifnum\x=1\relax\else, \fi\interview{\x}} \end{document}– Steven B. Segletes Mar 27 '19 at 13:47