ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Bad interaction between new interpretation of underscore and modules
@ 2011-01-13 16:18 Mathieu Boespflug
  2011-01-13 21:50 ` Wolfgang Schuster
  0 siblings, 1 reply; 9+ messages in thread
From: Mathieu Boespflug @ 2011-01-13 16:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi all,

today's beta introduced a really strange problem. Consider two source files:

definitions.tex:
\startmodule[definitions]
\def\lambdax{\lambda_x}
\stopmodule[definitions]

main.tex:
\usemodule[definitions]
\starttext
blah $\lambdax$ blah.
\stoptext

This results in the following compile error:

! Undefined control sequence.
\lambdax ->\lambda_x

l.5 blah $\lambdax
                  $ blah.
?

However, if you change "\usemodule[definitions]" into "\input
definitions" instead, then there is no compile error! My understanding
is that the underscore is a valid character for macro names now
outside of math mode, which is what is causing the problem. But I
really don't understand what magic is going on in the modules code to
trigger this.

I would be very interested in an explanation of what is going on.

Many thanks,

Mathieu
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-13 16:18 Bad interaction between new interpretation of underscore and modules Mathieu Boespflug
@ 2011-01-13 21:50 ` Wolfgang Schuster
  2011-01-13 22:43   ` Aditya Mahajan
  2011-01-14  9:15   ` Mathieu Boespflug
  0 siblings, 2 replies; 9+ messages in thread
From: Wolfgang Schuster @ 2011-01-13 21:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 13.01.2011 um 17:18 schrieb Mathieu Boespflug:

> Hi all,
> 
> today's beta introduced a really strange problem. Consider two source files:
> 
> definitions.tex:
> \startmodule[definitions]
> \def\lambdax{\lambda_x}
> \stopmodule[definitions]
> 
> main.tex:
> \usemodule[definitions]
> \starttext
> blah $\lambdax$ blah.
> \stoptext
> 
> This results in the following compile error:
> 
> ! Undefined control sequence.
> \lambdax ->\lambda_x
> 
> l.5 blah $\lambdax
>                  $ blah.
> ?
> 
> However, if you change "\usemodule[definitions]" into "\input
> definitions" instead, then there is no compile error! My understanding
> is that the underscore is a valid character for macro names now
> outside of math mode, which is what is causing the problem. But I
> really don't understand what magic is going on in the modules code to
> trigger this.
> 
> I would be very interested in an explanation of what is going on.

You need \normalsubscript in your module. You define a command and
in this case it doesn’t matter that you plan to use it in math mode,
the _ is now a normal letter like “a” and this won’t change when you
call \lambdax in your document.

Write

  \def\lambdax{\lambda\normalsubscript x}

and it will work again.

Wolfgang

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-13 21:50 ` Wolfgang Schuster
@ 2011-01-13 22:43   ` Aditya Mahajan
  2011-01-14  0:14     ` Wolfgang Schuster
  2011-01-14  9:15   ` Mathieu Boespflug
  1 sibling, 1 reply; 9+ messages in thread
From: Aditya Mahajan @ 2011-01-13 22:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1462 bytes --]

On Thu, 13 Jan 2011, Wolfgang Schuster wrote:

>
> Am 13.01.2011 um 17:18 schrieb Mathieu Boespflug:
>
>> Hi all,
>>
>> today's beta introduced a really strange problem. Consider two source files:
>>
>> definitions.tex:
>> \startmodule[definitions]
>> \def\lambdax{\lambda_x}
>> \stopmodule[definitions]
>>
>> main.tex:
>> \usemodule[definitions]
>> \starttext
>> blah $\lambdax$ blah.
>> \stoptext
>>
>> This results in the following compile error:
>>
>> ! Undefined control sequence.
>> \lambdax ->\lambda_x
>>
>> l.5 blah $\lambdax
>>                  $ blah.
>> ?
>>
>> However, if you change "\usemodule[definitions]" into "\input
>> definitions" instead, then there is no compile error! My understanding
>> is that the underscore is a valid character for macro names now
>> outside of math mode, which is what is causing the problem. But I
>> really don't understand what magic is going on in the modules code to
>> trigger this.
>>
>> I would be very interested in an explanation of what is going on.
>
> You need \normalsubscript in your module. You define a command and
> in this case it doesn’t matter that you plan to use it in math mode,
> the _ is now a normal letter like “a” and this won’t change when you
> call \lambdax in your document.
>
> Write
>
>  \def\lambdax{\lambda\normalsubscript x}
>
> and it will work again.

Untested:

\def\lambdax{\math{\lambda_x}}

should also work.

Aditya

[-- Attachment #2: Type: text/plain, Size: 486 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-13 22:43   ` Aditya Mahajan
@ 2011-01-14  0:14     ` Wolfgang Schuster
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Schuster @ 2011-01-14  0:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 13.01.2011 um 23:43 schrieb Aditya Mahajan:

> Untested:
> 
> \def\lambdax{\math{\lambda_x}}
> 
> should also work.

Not, this won’t work in a module because _ has catcode 11 when you define
the \lambdax command and it doesn’t matter whether you use \math, $ or
\Ustartmath. What happens is that TeX tries to expand the not existent
command “\lambda_x”.

Wolfgang

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-13 21:50 ` Wolfgang Schuster
  2011-01-13 22:43   ` Aditya Mahajan
@ 2011-01-14  9:15   ` Mathieu Boespflug
  2011-01-14  9:32     ` Wolfgang Schuster
  2011-01-14 11:01     ` Hans Hagen
  1 sibling, 2 replies; 9+ messages in thread
From: Mathieu Boespflug @ 2011-01-14  9:15 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thank you for the solution, Wolfgang.  But it seems rather painful to
have to replace every occurrence of _ in my definitions module with
the very verbose \normalsubscript just because it's a module. The new
default catcode for _ introduces extra difficulty when defining math
macros. Would it be possible to at least have a macro to revert to the
old behaviour? Also, I'm still stumped as to why modules make any
difference here. I would have expected this problem to also show up if
the definitions were made inline at the top of the source file for the
document.

All the best,

Mathieu


On Thu, Jan 13, 2011 at 10:50 PM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
>
> Am 13.01.2011 um 17:18 schrieb Mathieu Boespflug:
>
>> Hi all,
>>
>> today's beta introduced a really strange problem. Consider two source files:
>>
>> definitions.tex:
>> \startmodule[definitions]
>> \def\lambdax{\lambda_x}
>> \stopmodule[definitions]
>>
>> main.tex:
>> \usemodule[definitions]
>> \starttext
>> blah $\lambdax$ blah.
>> \stoptext
>>
>> This results in the following compile error:
>>
>> ! Undefined control sequence.
>> \lambdax ->\lambda_x
>>
>> l.5 blah $\lambdax
>>                  $ blah.
>> ?
>>
>> However, if you change "\usemodule[definitions]" into "\input
>> definitions" instead, then there is no compile error! My understanding
>> is that the underscore is a valid character for macro names now
>> outside of math mode, which is what is causing the problem. But I
>> really don't understand what magic is going on in the modules code to
>> trigger this.
>>
>> I would be very interested in an explanation of what is going on.
>
> You need \normalsubscript in your module. You define a command and
> in this case it doesn’t matter that you plan to use it in math mode,
> the _ is now a normal letter like “a” and this won’t change when you
> call \lambdax in your document.
>
> Write
>
>  \def\lambdax{\lambda\normalsubscript x}
>
> and it will work again.
>
> Wolfgang
>
> ___________________________________________________________________________________
> 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://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-14  9:15   ` Mathieu Boespflug
@ 2011-01-14  9:32     ` Wolfgang Schuster
  2011-01-14 10:09       ` Mathieu Boespflug
  2011-01-14 11:01     ` Hans Hagen
  1 sibling, 1 reply; 9+ messages in thread
From: Wolfgang Schuster @ 2011-01-14  9:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 14.01.2011 um 10:15 schrieb Mathieu Boespflug:

> Thank you for the solution, Wolfgang.  But it seems rather painful to
> have to replace every occurrence of _ in my definitions module with
> the very verbose \normalsubscript just because it's a module. The new
> default catcode for _ introduces extra difficulty when defining math
> macros. Would it be possible to at least have a macro to revert to the
> old behaviour? Also, I'm still stumped as to why modules make any
> difference here. I would have expected this problem to also show up if
> the definitions were made inline at the top of the source file for the
> document.

When you write a module you put \unprotect and \protect at the begin and
end of the file because they make @, !, ? and _ to a normal letter like abc
which can be used in macros. When you load a file with \usemodule or
\environment this isn’t necessary because context adds already calls
both commands when the file is opened and closed for reading and this
mechanism is used even if you aren’t aware of this.

PS  For \environment this is only true when you use it in a document
with \starttext or when you write it before \startproduct, \startcomponent etc.

PPS  You can abuse \nonknuthmode to make your module to work

\startbuffer[definitions]
\pushcatcodes\nonknuthmode % \startnonknuthmode
\def\lambdax{\lambda_x}
\popcatcodes               % \stopnonknuthmode
\stopbuffer

\savebuffer[definitions][p-definitions.tex]

\startbuffer[more]
\def\morex{\more_x}
\stopbuffer

\savebuffer[more][p-more.tex]

\usemodule[definitions,more]

\starttext
blah $\lambdax$ blah. \morex
\stoptext

Wolfgang

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-14  9:32     ` Wolfgang Schuster
@ 2011-01-14 10:09       ` Mathieu Boespflug
  0 siblings, 0 replies; 9+ messages in thread
From: Mathieu Boespflug @ 2011-01-14 10:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Wolfgang,

thank you for the explanation and the solution.

Best,

Mathieu

On Fri, Jan 14, 2011 at 10:32 AM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> wrote:
>
> Am 14.01.2011 um 10:15 schrieb Mathieu Boespflug:
>
>> Thank you for the solution, Wolfgang.  But it seems rather painful to
>> have to replace every occurrence of _ in my definitions module with
>> the very verbose \normalsubscript just because it's a module. The new
>> default catcode for _ introduces extra difficulty when defining math
>> macros. Would it be possible to at least have a macro to revert to the
>> old behaviour? Also, I'm still stumped as to why modules make any
>> difference here. I would have expected this problem to also show up if
>> the definitions were made inline at the top of the source file for the
>> document.
>
> When you write a module you put \unprotect and \protect at the begin and
> end of the file because they make @, !, ? and _ to a normal letter like abc
> which can be used in macros. When you load a file with \usemodule or
> \environment this isn’t necessary because context adds already calls
> both commands when the file is opened and closed for reading and this
> mechanism is used even if you aren’t aware of this.
>
> PS  For \environment this is only true when you use it in a document
> with \starttext or when you write it before \startproduct, \startcomponent etc.
>
> PPS  You can abuse \nonknuthmode to make your module to work
>
> \startbuffer[definitions]
> \pushcatcodes\nonknuthmode % \startnonknuthmode
> \def\lambdax{\lambda_x}
> \popcatcodes               % \stopnonknuthmode
> \stopbuffer
>
> \savebuffer[definitions][p-definitions.tex]
>
> \startbuffer[more]
> \def\morex{\more_x}
> \stopbuffer
>
> \savebuffer[more][p-more.tex]
>
> \usemodule[definitions,more]
>
> \starttext
> blah $\lambdax$ blah. \morex
> \stoptext
>
> Wolfgang
>
> ___________________________________________________________________________________
> 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://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-14  9:15   ` Mathieu Boespflug
  2011-01-14  9:32     ` Wolfgang Schuster
@ 2011-01-14 11:01     ` Hans Hagen
  2011-01-14 11:13       ` Wolfgang Schuster
  1 sibling, 1 reply; 9+ messages in thread
From: Hans Hagen @ 2011-01-14 11:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Mathieu Boespflug

On 14-1-2011 10:15, Mathieu Boespflug wrote:
> Thank you for the solution, Wolfgang.  But it seems rather painful to
> have to replace every occurrence of _ in my definitions module with
> the very verbose \normalsubscript just because it's a module. The new
> default catcode for _ introduces extra difficulty when defining math
> macros. Would it be possible to at least have a macro to revert to the
> old behaviour? Also, I'm still stumped as to why modules make any
> difference here. I would have expected this problem to also show up if
> the definitions were made inline at the top of the source file for the
> document.

just add a space before the _ when it directly follows a \cs, so

... $\cs _2$ ...

but regular text like

... $x_2$ ...

can be left as it is

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: Bad interaction between new interpretation of underscore and modules
  2011-01-14 11:01     ` Hans Hagen
@ 2011-01-14 11:13       ` Wolfgang Schuster
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Schuster @ 2011-01-14 11:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 14.01.2011 um 12:01 schrieb Hans Hagen:

> just add a space before the _ when it directly follows a \cs, so
> 
> ... $\cs _2$ ...
> 
> but regular text like
> 
> ... $x_2$ ...
> 
> can be left as it is

He put the definitions in a external file which he loads with \usemodule and then this won’t work


\starttexcode
\def\lambdaone{\lambda_x}
\stoptexcode

\starttexcode
\def\lambdatwo{\lambda _x}
\stoptexcode

\starttexcode
\pushcatcodetable\donknuthmode
\def\lambdathree{\lambda_x}
\popcatcodes
\stoptexcode

\starttext
\doifmode{one}  {$\lambdaone  $}
\doifmode{two}  {$\lambdatwo  $}
\doifmode{three}{$\lambdathree$}
\stoptext


1. context --mode=one test.tex

! Undefined control sequence.
\lambdaone ->\lambda_x 
                       
<argument> $\lambdaone 
                       $
\firstofoneargument #1->#1
                          
l.16 \doifmode{one}  {$\lambdaone  $}
                                     
? 


2. context --mode=two test.tex

! Undefined control sequence.
\lambdatwo ->\lambda _
                      x
<argument> $\lambdatwo 
                       $
\firstofoneargument #1->#1
                          
l.17 \doifmode{two}  {$\lambdatwo  $}
                                     
? 


3. context --mode=three test.tex

-> test.pdf


Wolfgang

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2011-01-14 11:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-13 16:18 Bad interaction between new interpretation of underscore and modules Mathieu Boespflug
2011-01-13 21:50 ` Wolfgang Schuster
2011-01-13 22:43   ` Aditya Mahajan
2011-01-14  0:14     ` Wolfgang Schuster
2011-01-14  9:15   ` Mathieu Boespflug
2011-01-14  9:32     ` Wolfgang Schuster
2011-01-14 10:09       ` Mathieu Boespflug
2011-01-14 11:01     ` Hans Hagen
2011-01-14 11:13       ` Wolfgang Schuster

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