Thanks for these replies! Adding \unexpanded or \protected before \def didn't fix the problem, and surrounding the definition with \unprotect ... \protect didn't work either. But surrounding it with \pushcatcodetable \setcatcodetable\ctxcatcodes ... \popcatcodetable worked.

I've never seen these commands before, but I gather from the existing documentation that the current catcode governs which characters are treated as special when a buffer is being processed. So here, it looks like I'm temporarily switching from some other catcode set (it looks like in publ-ini.mkiv, \catcode\commentasciicode\othercatcode gets invoked in \publ_set_publication, so perhaps that's what's happening?) to the default ConTeXt catcodes and then back.

Thanks again!

Joey

On Sun, Oct 10, 2021 at 6:40 AM Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
Joey McCollum via ntg-context schrieb am 10.10.2021 um 05:42:
The test using \removepunctuation that you provided does what it should be doing (it produces 6 instances of "test-test" with the intervening punctuation mark in each case removed), but it doesn't do what I'm trying to do in the MWE above. I'm trying to take certain punctuation marks that follow the \autopuncttest macro and place them before it instead. Looking at the typo-chr .lua and .mkiv files, I see that there are \pushpunctuation and \poppunctuation methods in addition to the \removepunctuation method. These might be useful for this purpose, but in any case, I still have to check if the trailing character is one of the characters in a specified set/string, and this is where the error is arising.

Add \protected (or \unexpanded) to your command definition.

\startbtxrenderingdefinitions[myspec]
\protected\def\autopuncttest#1#2%
  {\removeunwantedspaces%
   \doifinstring{#2}{,.!?;:}{#2}%
   \footnote{#1}%
   \doifnotinstring{#2}{,.!?;:}{#2}}
\stopbtxrenderingdefinitions

Wolfgang