ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
@ 2021-10-09 15:40 Joey McCollum via ntg-context
  2021-10-09 16:50 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Joey McCollum via ntg-context @ 2021-10-09 15:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Joey McCollum


[-- Attachment #1.1: Type: text/plain, Size: 1429 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 2482 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
  2021-10-09 15:40 Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions Joey McCollum via ntg-context
@ 2021-10-09 16:50 ` Hans Hagen via ntg-context
  2021-10-10  3:42   ` Joey McCollum via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen via ntg-context @ 2021-10-09 16:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: 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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
  2021-10-09 16:50 ` Hans Hagen via ntg-context
@ 2021-10-10  3:42   ` Joey McCollum via ntg-context
  2021-10-10 10:34     ` Hans Hagen via ntg-context
  2021-10-10 10:40     ` Wolfgang Schuster via ntg-context
  0 siblings, 2 replies; 7+ messages in thread
From: Joey McCollum via ntg-context @ 2021-10-10  3:42 UTC (permalink / raw)
  To: Hans Hagen; +Cc: Joey McCollum, mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2094 bytes --]

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 <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 | www.pragma-pod.nl
> -----------------------------------------------------------------
>

[-- Attachment #1.2: Type: text/html, Size: 2925 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
  2021-10-10  3:42   ` Joey McCollum via ntg-context
@ 2021-10-10 10:34     ` Hans Hagen via ntg-context
  2021-10-10 10:40     ` Wolfgang Schuster via ntg-context
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen via ntg-context @ 2021-10-10 10:34 UTC (permalink / raw)
  To: Joey McCollum; +Cc: Hans Hagen, mailing list for ConTeXt users

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 <j.hagen@xs4all.nl 
> <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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
  2021-10-10  3:42   ` Joey McCollum via ntg-context
  2021-10-10 10:34     ` Hans Hagen via ntg-context
@ 2021-10-10 10:40     ` Wolfgang Schuster via ntg-context
  2021-10-10 13:40       ` Joey McCollum via ntg-context
  1 sibling, 1 reply; 7+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2021-10-10 10:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Joey McCollum via ntg-context
  Cc: Wolfgang Schuster


[-- Attachment #1.1: Type: text/plain, Size: 1105 bytes --]

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


[-- Attachment #1.2: Type: text/html, Size: 1610 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
  2021-10-10 10:40     ` Wolfgang Schuster via ntg-context
@ 2021-10-10 13:40       ` Joey McCollum via ntg-context
  2021-10-12  1:57         ` Joey McCollum via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Joey McCollum via ntg-context @ 2021-10-10 13:40 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: Joey McCollum, mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1968 bytes --]

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
>
>

[-- Attachment #1.2: Type: text/html, Size: 2614 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions
  2021-10-10 13:40       ` Joey McCollum via ntg-context
@ 2021-10-12  1:57         ` Joey McCollum via ntg-context
  0 siblings, 0 replies; 7+ messages in thread
From: Joey McCollum via ntg-context @ 2021-10-12  1:57 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: Joey McCollum, mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2513 bytes --]

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 <jmccollum20140511@gmail.com>
wrote:

> 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
>>
>>

[-- Attachment #1.2: Type: text/html, Size: 3469 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-10-12  1:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09 15:40 Unusual error with \doifinstring in \startbtxrenderingdefinitions ... \stopbtxrenderingdefinitions Joey McCollum via ntg-context
2021-10-09 16:50 ` Hans Hagen via ntg-context
2021-10-10  3:42   ` Joey McCollum via ntg-context
2021-10-10 10:34     ` Hans Hagen via ntg-context
2021-10-10 10:40     ` Wolfgang Schuster via ntg-context
2021-10-10 13:40       ` Joey McCollum via ntg-context
2021-10-12  1:57         ` Joey McCollum via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).