Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
Hi, I'm trying to define concise biblatex-style citation macros for a custom bibliographic style specification with support for intelligent placement of trailing punctuation, and I've encountered an unusual error. If I try to define the macros within the btxrenderingdefinitions environment, then the code for handling trailing punctuation with the \doifinstring and \doifnotinstring macros fails in some cases. Specifically, it correctly detects when the trailing punctuation is a period, comma, or semicolon, but not when it is a colon, exclamation point, or question mark. The following MWE reproduces the error: ``` \startbtxrenderingdefinitions[myspec] \def\autopuncttest#1#2{% \removeunwantedspaces% \doifinstring{#2}{,.!?;:}{#2}% \footnote{#1}% \doifnotinstring{#2}{,.!?;:}{#2}% } \stopbtxrenderingdefinitions \usebtxdefinitions[myspec] \starttext This works \autopuncttest{Footnote 1}, as does this \autopuncttest{Footnote 2}; and so does this \autopuncttest{Footnote 3}.\blank But this one fails if defined in the bib spec \autopuncttest{Footnote 4}!\blank And why does this one fail in the bib spec too \autopuncttest{Footnote 5}?\blank \stoptext ``` Everything works as expected if the macro definition is outside of the btxrenderingdefinitions environment. But within the environment, do certain punctuation marks need to be escaped in the second argument of \doifinstring? Or is this a bug? Joey
On 10/9/2021 5:40 PM, Joey McCollum via ntg-context wrote:
Hi,
I'm trying to define concise biblatex-style citation macros for a custom bibliographic style specification with support for intelligent placement of trailing punctuation, and I've encountered an unusual error. If I try to define the macros within the btxrenderingdefinitions environment, then the code for handling trailing punctuation with the \doifinstring and \doifnotinstring macros fails in some cases. Specifically, it correctly detects when the trailing punctuation is a period, comma, or semicolon, but not when it is a colon, exclamation point, or question mark. The following MWE reproduces the error:
``` \starttext
test,\removepunctuation -test test;\removepunctuation -test test:\removepunctuation -test test?\removepunctuation -test test!\removepunctuation -test test.\removepunctuation -test \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
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.
Joey
On Sat, Oct 9, 2021 at 12:50 PM Hans Hagen
On 10/9/2021 5:40 PM, Joey McCollum via ntg-context wrote:
Hi,
I'm trying to define concise biblatex-style citation macros for a custom bibliographic style specification with support for intelligent placement of trailing punctuation, and I've encountered an unusual error. If I try to define the macros within the btxrenderingdefinitions environment, then the code for handling trailing punctuation with the \doifinstring and \doifnotinstring macros fails in some cases. Specifically, it correctly detects when the trailing punctuation is a period, comma, or semicolon, but not when it is a colon, exclamation point, or question mark. The following MWE reproduces the error:
``` \starttext
test,\removepunctuation -test test;\removepunctuation -test test:\removepunctuation -test test?\removepunctuation -test test!\removepunctuation -test test.\removepunctuation -test
\stoptext
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 10/10/2021 5:42 AM, Joey McCollum wrote:
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 \poppunctuationmethods 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.
maybe you're in protected mode % assumes \protect earlier \unprotect \def\autopuncttest#1#2{% \removeunwantedspaces% \doifinstring{#2}{,.!?;:}{#2}% \footnote{#1}% \doifnotinstring{#2}{,.!?;:}{#2}% } \protect % assumes \unprotect later or something \pushcatcodetable \setcatcodetable\ctxcatcodes \def\autopuncttest#1#2{% \removeunwantedspaces% \doifinstring{#2}{,.!?;:}{#2}% \footnote{#1}% \doifnotinstring{#2}{,.!?;:}{#2}% } \popcatcodetable
Joey
On Sat, Oct 9, 2021 at 12:50 PM Hans Hagen
mailto:j.hagen@xs4all.nl> wrote: On 10/9/2021 5:40 PM, Joey McCollum via ntg-context wrote: > Hi, > > I'm trying to define concise biblatex-style citation macros for a custom > bibliographic style specification with support for intelligent placement > of trailing punctuation, and I've encountered an unusual error. If I try > to define the macros within the btxrenderingdefinitions environment, > then the code for handling trailing punctuation with the > \doifinstring and \doifnotinstring macros fails in some cases. > Specifically, it correctly detects when the trailing punctuation is a > period, comma, or semicolon, but not when it is a colon, exclamation > point, or question mark. The following MWE reproduces the error: > > ``` \starttext
test,\removepunctuation -test test;\removepunctuation -test test:\removepunctuation -test test?\removepunctuation -test test!\removepunctuation -test test.\removepunctuation -test
\stoptext
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl http://www.pragma-ade.nl | www.pragma-pod.nl http://www.pragma-pod.nl -----------------------------------------------------------------
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
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 \poppunctuationmethods 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
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
An alternative solution is to isolate the setting of the
autopunctuation btx option:
```
% Because some common punctuation characters are escaped in publ-ini.mkiv,
% we have to set this option separately
\pushcatcodetable
\setcatcodetable\ctxcatcodes
\setupbtx[sbl][autopunctuation={!,.:;?}]% undelimited list of trailing
punctuation to move before footnote citations
\popcatcodetable
```
Joey
On Sun, Oct 10, 2021 at 9:40 AM Joey McCollum
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
participants (3)
-
Hans Hagen
-
Joey McCollum
-
Wolfgang Schuster