I was afraid that might be the problem. I've described some of the intended purpose of this code near the end of the "Checking for a macro in a string without expanding it" thread on the mailing list, but I will get into more detail here. I'm working on a ConTeXt implementation of citation style language (CSL) locators, particularly for the SBL citation rendering (although the code could easily be adapted for use in general or with other bibliographic renderings). This would allow for a consistent, language-sensitive syntax that could be used within citations or in any part of a text and could accommodate changes in bibliographic style without requiring the user to reformat all their page number citations. In SBL style, for instance, volume, part, and page numbers are not prefixed by abbreviations like "vol.", "pt." and "p.", but in other styles, they might be. The locator syntax
```
\loc[vol=33,pt=1,p=86]
```
would be defined in the SBL rendering file to output
```
33.1:86
```
while in some other style, it might be defined to output
```
vol. 33, pt. 1, p. 86
```
To accommodate the use of these macros within citations, I've added "loctext" (locator text) and "altloctext" (alternate locator text) arguments to the set of parameters used by the \cite macro, because in some bibliographic categories, different locators can be specified for different parts of a citation (e.g., one for a passage in an ancient text and another for the book reproducing it), and therefore cannot just be specified in the "righttext" parameter. So now we can do something like
```
\cite[lefttext={See},altloctext={1.3},loctext={8:223},righttext={for further details}][clementinehomilies]
```
to get
See The Clementine Homilies 1.3 (ANF 8:223) for further details.
or
```
\cite[lefttext={See},loctext={\loc[p=8]},righttext={; but there are also contradictory statements, e.g. \loc[p=12].}][Doe:Title]
```
to get
See Doe, Title, 8; but there are also contradictory statements, e.g. 12.
The main problem is determining when to include a comma before printing the "loctext" and when not to include one. In the first example above, we don't want a comma between ANF and 8:223 (SBL style does not add a comma between a multivolume set abbreviation and a volume number), but in the second example, we do want one between Title and 8. Similarly, we want to remove the comma if the first locator in the loctext is a section marker (§) or paragraph marker (¶). This is why I want to check the beginning of the \currentloctext macro for the presence of a volume number (a number followed by a colon), a section mark, or a paragraph mark.
While storing the locator parameters as btx parameters would allow for another solution to this problem, it would complicate defining the \loc macro in a way that would be suitable outside of citations or for multiple uses in the same citation (notice how a second \loc invocation occurs in the righttext of the second example above). Parsing the output of \loc seemed like the simplest solution, but as you've pointed out, it has its own difficulties. I'm inclined to try one of the TeX-based solutions you describe above to avoid complicating other things, but if my description of the intended use gives you any better ideas, please suggest them!
Thanks again!
Joey