Re: [NTG-context] Typing within doifmode leads to error

2021-03-21 Thread Christoph Reller
On Sat, Mar 20, 2021 at 6:07 PM Hans Hagen  wrote:

> On 3/20/2021 4:00 PM, Christoph Reller wrote:
> > On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen  > > wrote:
> >
> > On 3/20/2021 8:24 AM, Aditya Mahajan wrote:
> >  > On Sat, 20 Mar 2021, Christoph Reller wrote:
> >  >> Of course we can do this in lua:
> >  >>
> >  >> if tex.modes["A"] and not tex.modes{"B"] then
> >  >> ...
> >  >> end
> >  >
> >  > ... which means that you can use that at the context end as well
> > (old feature).
> >  > Save the following as test.mkix (or add "% macros=mkix" as the
> > first line):
> >  >
> >  > ```
> >  > \starttext
> >  > 
> >  > \starttyping
> >  > A and not B
> >  > \stoptyping
> >  > 
> >  > \starttyping
> >  > not (A and not B)
> >  > \stoptyping
> >  > 
> >  > \stoptext
> > a neat application!
> >
> >
> > Thank you for this hint, Aditya. This would be a very nice solution
> > indeed. But it does not seem to work:
> >
> > % macros=mkix
> > \definemode[A][yes]
> > \starttext
> > \startluacode
> >if tex.modes['A'] then
> >  context("A")
> >end
> > \stopluacode
> > 
> > A
> > 
> > \stoptext
> >
> > With ConTeXt LMTX 2021.03.17 the output of the above is a single "A". I
> > would expect two. What am I doing wrong?
>
> When the file gets preprocessed the mode is not known
>
> context --mode=A foo.tex
>
> it does of course also work when you set the mode in a parent file and
> then include foo.tex


For me this is good enough, because I define modes always in top-level
files or in modules. Thank you!

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Aditya Mahajan
On Sun, 21 Mar 2021, Hans Hagen wrote:

> On 3/20/2021 10:03 PM, Aditya Mahajan wrote:
> > On Sat, 20 Mar 2021, Hans Hagen wrote:
> > 
> > > > 
> > > > I wonder if we could have an environment, say \startluatemplate ...
> > > > \stopluatemplate, which is evaluated on the fly rather than when loading
> > > > a
> > > > file.
> > > 
> > > define 'evaluated on the fly'
> > 
> > Consider the following example:
> > 
> > \enablemode[A]
> > \starttext
> > \startluatemplate
> >
> >\starttyping
> >A and not B
> >\stoptyping
> >
> >\starttyping
> >not (A and not B)
> >\stoptyping
> >
> > \stopluatemplate
> > \stoptext
> > 
> > What I am thinking is that \startluatemplate ... \stopluatemplate grabs the
> > content (like a buffer) and then processes it using the mkix conversion
> > mechanism. Thus, in terms of output, it should be equivalent to:
> > 
> > \enablemode[A]
> > \starttext
> > \startbuffer[luatemplate]
> >
> >\starttyping
> >A and not B
> >\stoptyping
> >
> >\starttyping
> >not (A and not B)
> >\stoptyping
> >
> > \stopbuffer
> > \savebuffer[file={\jobname-luatemplate.mkix}, list={luatemplate}]
> > \input \jobname-luatemplate.mkix
> > \stoptext
> > 
> > but without the need to save to an external file.
> this is just for the mode right? in that case we can also can provide
> 
> 

:-)

I don't use templates too often, so I don't have other examples in mind where 
the \startluatemplate ... \stopluatemplate might be needed. So, just adding 
tex.enablemode at the lua will also work. We can see if another use case comes 
up in the future!

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Hans Hagen

On 3/20/2021 10:03 PM, Aditya Mahajan wrote:

On Sat, 20 Mar 2021, Hans Hagen wrote:



I wonder if we could have an environment, say \startluatemplate ...
\stopluatemplate, which is evaluated on the fly rather than when loading a
file.


define 'evaluated on the fly'


Consider the following example:

\enablemode[A]
\starttext
\startluatemplate
   
   \starttyping
   A and not B
   \stoptyping
   
   \starttyping
   not (A and not B)
   \stoptyping
   
\stopluatemplate
\stoptext

What I am thinking is that \startluatemplate ... \stopluatemplate grabs the 
content (like a buffer) and then processes it using the mkix conversion 
mechanism. Thus, in terms of output, it should be equivalent to:

\enablemode[A]
\starttext
\startbuffer[luatemplate]
   
   \starttyping
   A and not B
   \stoptyping
   
   \starttyping
   not (A and not B)
   \stoptyping
   
\stopbuffer
\savebuffer[file={\jobname-luatemplate.mkix}, list={luatemplate}]
\input \jobname-luatemplate.mkix
\stoptext

but without the need to save to an external file.

this is just for the mode right? in that case we can also can provide



Hans


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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Aditya Mahajan
On Sat, 20 Mar 2021, Hans Hagen wrote:

> > 
> > I wonder if we could have an environment, say \startluatemplate ...
> > \stopluatemplate, which is evaluated on the fly rather than when loading a
> > file.
> 
> define 'evaluated on the fly'

Consider the following example:

\enablemode[A]
\starttext
\startluatemplate
  
  \starttyping
  A and not B
  \stoptyping
  
  \starttyping
  not (A and not B)
  \stoptyping
  
\stopluatemplate
\stoptext

What I am thinking is that \startluatemplate ... \stopluatemplate grabs the 
content (like a buffer) and then processes it using the mkix conversion 
mechanism. Thus, in terms of output, it should be equivalent to:

\enablemode[A]
\starttext
\startbuffer[luatemplate]
  
  \starttyping
  A and not B
  \stoptyping
  
  \starttyping
  not (A and not B)
  \stoptyping
  
\stopbuffer
\savebuffer[file={\jobname-luatemplate.mkix}, list={luatemplate}]
\input \jobname-luatemplate.mkix
\stoptext

but without the need to save to an external file. 

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Hans Hagen

On 3/20/2021 9:23 PM, Aditya Mahajan wrote:

On Sat, 20 Mar 2021, Hans Hagen wrote:


On 3/20/2021 4:00 PM, Christoph Reller wrote:

On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen mailto:j.ha...@xs4all.nl>> wrote:

 On 3/20/2021 8:24 AM, Aditya Mahajan wrote:
  > On Sat, 20 Mar 2021, Christoph Reller wrote:
  >> Of course we can do this in lua:
  >>
  >> if tex.modes["A"] and not tex.modes{"B"] then
  >> ...
  >> end
  >
  > ... which means that you can use that at the context end as well
 (old feature).
  > Save the following as test.mkix (or add "% macros=mkix" as the
 first line):
  >
  > ```
  > \starttext
  > 
  > \starttyping
  > A and not B
  > \stoptyping
  > 
  > \starttyping
  > not (A and not B)
  > \stoptyping
  > 
  > \stoptext
 a neat application!


Thank you for this hint, Aditya. This would be a very nice solution
indeed. But it does not seem to work:

% macros=mkix
\definemode[A][yes]
\starttext
\startluacode
    if tex.modes['A'] then
      context("A")
    end
\stopluacode

A

\stoptext

With ConTeXt LMTX 2021.03.17 the output of the above is a single "A". I
would expect two. What am I doing wrong?


When the file gets preprocessed the mode is not known

context --mode=A foo.tex

it does of course also work when you set the mode in a parent file and
then include foo.tex


I wonder if we could have an environment, say \startluatemplate ... 
\stopluatemplate, which is evaluated on the fly rather than when loading a file.


define 'evaluated on the fly'


Aditya


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




--

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Aditya Mahajan
On Sat, 20 Mar 2021, Hans Hagen wrote:

> On 3/20/2021 4:00 PM, Christoph Reller wrote:
> > On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen  > > wrote:
> > 
> > On 3/20/2021 8:24 AM, Aditya Mahajan wrote:
> >  > On Sat, 20 Mar 2021, Christoph Reller wrote:
> >  >> Of course we can do this in lua:
> >  >>
> >  >> if tex.modes["A"] and not tex.modes{"B"] then
> >  >> ...
> >  >> end
> >  >
> >  > ... which means that you can use that at the context end as well
> > (old feature).
> >  > Save the following as test.mkix (or add "% macros=mkix" as the
> > first line):
> >  >
> >  > ```
> >  > \starttext
> >  > 
> >  > \starttyping
> >  > A and not B
> >  > \stoptyping
> >  > 
> >  > \starttyping
> >  > not (A and not B)
> >  > \stoptyping
> >  > 
> >  > \stoptext
> > a neat application!
> > 
> > 
> > Thank you for this hint, Aditya. This would be a very nice solution 
> > indeed. But it does not seem to work:
> > 
> > % macros=mkix
> > \definemode[A][yes]
> > \starttext
> > \startluacode
> >    if tex.modes['A'] then
> >      context("A")
> >    end
> > \stopluacode
> > 
> > A
> > 
> > \stoptext
> > 
> > With ConTeXt LMTX 2021.03.17 the output of the above is a single "A". I 
> > would expect two. What am I doing wrong?
> 
> When the file gets preprocessed the mode is not known
> 
> context --mode=A foo.tex
> 
> it does of course also work when you set the mode in a parent file and 
> then include foo.tex

I wonder if we could have an environment, say \startluatemplate ... 
\stopluatemplate, which is evaluated on the fly rather than when loading a 
file. 

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Hans Hagen

On 3/20/2021 4:00 PM, Christoph Reller wrote:
On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen > wrote:


On 3/20/2021 8:24 AM, Aditya Mahajan wrote:
 > On Sat, 20 Mar 2021, Christoph Reller wrote:
 >> Of course we can do this in lua:
 >>
 >> if tex.modes["A"] and not tex.modes{"B"] then
 >> ...
 >> end
 >
 > ... which means that you can use that at the context end as well
(old feature).
 > Save the following as test.mkix (or add "% macros=mkix" as the
first line):
 >
 > ```
 > \starttext
 > 
 > \starttyping
 > A and not B
 > \stoptyping
 > 
 > \starttyping
 > not (A and not B)
 > \stoptyping
 > 
 > \stoptext
a neat application!


Thank you for this hint, Aditya. This would be a very nice solution 
indeed. But it does not seem to work:


% macros=mkix
\definemode[A][yes]
\starttext
\startluacode
   if tex.modes['A'] then
     context("A")
   end
\stopluacode

A

\stoptext

With ConTeXt LMTX 2021.03.17 the output of the above is a single "A". I 
would expect two. What am I doing wrong?


When the file gets preprocessed the mode is not known

context --mode=A foo.tex

it does of course also work when you set the mode in a parent file and 
then include foo.tex


Hans




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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Christoph Reller
On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen  wrote:

> On 3/20/2021 8:24 AM, Aditya Mahajan wrote:
> > On Sat, 20 Mar 2021, Christoph Reller wrote:
> >> Of course we can do this in lua:
> >>
> >> if tex.modes["A"] and not tex.modes{"B"] then
> >> ...
> >> end
> >
> > ... which means that you can use that at the context end as well (old
> feature).
> > Save the following as test.mkix (or add "% macros=mkix" as the first
> line):
> >
> > ```
> > \starttext
> > 
> > \starttyping
> > A and not B
> > \stoptyping
> > 
> > \starttyping
> > not (A and not B)
> > \stoptyping
> > 
> > \stoptext
> a neat application!
>
>
Thank you for this hint, Aditya. This would be a very nice solution indeed.
But it does not seem to work:

% macros=mkix
\definemode[A][yes]
\starttext
\startluacode
  if tex.modes['A'] then
context("A")
  end
\stopluacode

A

\stoptext

With ConTeXt LMTX 2021.03.17 the output of the above is a single "A". I
would expect two. What am I doing wrong?

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Hans Hagen

On 3/20/2021 8:24 AM, Aditya Mahajan wrote:

On Sat, 20 Mar 2021, Christoph Reller wrote:

Of course we can do this in lua:

if tex.modes["A"] and not tex.modes{"B"] then
...
end


... which means that you can use that at the context end as well (old feature).
Save the following as test.mkix (or add "% macros=mkix" as the first line):

```
\starttext

\starttyping
A and not B
\stoptyping

\starttyping
not (A and not B)
\stoptyping

\stoptext

a neat application!

Hans

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-20 Thread Aditya Mahajan
On Sat, 20 Mar 2021, Christoph Reller wrote:
> Of course we can do this in lua:
> 
> if tex.modes["A"] and not tex.modes{"B"] then
> ...
> end

... which means that you can use that at the context end as well (old feature).
Save the following as test.mkix (or add "% macros=mkix" as the first line):

```
\starttext

\starttyping
A and not B
\stoptyping

\starttyping
not (A and not B)
\stoptyping

\stoptext
```

See the templates manual for more details: 
https://www.pragma-ade.com/general/manuals/templates-mkiv.pdf

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-19 Thread Christoph Reller
On Fri, Mar 19, 2021 at 9:49 AM Hans Hagen  wrote:

> On 3/19/2021 4:58 AM, Christoph Reller wrote:
> > Hi,
> >
> > Consider the following MWE:
> >
> > \definetyping[T]
> > \definemode[mode][yes]
> > \starttext
> > \doifmode{mode}{%
> >\startT
> >  Bla
> >\stopT}
> > \stoptext
> >
> > Compilation with the currently latest ConTeXt LMTX (ver: 2021.03.17
> > 17:46 LMTX  fmt: 2021.3.18) fails with:
> >
> > tex error   > runaway error: end of file encountered
> > mtx-context | fatal error: return code: 1
> >
> > Compilation is successful if I replace doifmode{mode}{...} by
> > \startmode[mode]...\stopmode.
> >
> > Is there anything I'm missing? (This could be a bug.)
> not a bug, just the way tex works .. modes cannot know that what goes
> into an argument is something verbose
>
> but you can use this (also more efficient here):
>
> \definetyping[T]
> \definemode[mode][yes]
> \starttext
> \startmode[mode]
> \startT
>  Bla
> \stopT
> \stopmode
> \stoptext
>
> % there's also \startnotmode
>
>
Thank you for hinting at the environment form. The problem with this is,
that it cannot be nested, and that there is no "else" form.
E.g:

\startmode[A]
... mode A
\startmode[B]
... mode A and mode B
\elsemode
... mode A and not mode B
\stopmode
\stopmode

I know that there is \start(not)mode and \start(not)allmodes, but there
seems to be no way to use a general boolean expression such as:

\startmodes[A and not B]
...
\stopmodes

Of course we can do this in lua:

if tex.modes["A"] and not tex.modes{"B"] then
...
end

Keep up your excellent work! Cheers,

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-19 Thread Hans Hagen

On 3/19/2021 4:58 AM, Christoph Reller wrote:

Hi,

Consider the following MWE:

\definetyping[T]
\definemode[mode][yes]
\starttext
\doifmode{mode}{%
   \startT
     Bla
   \stopT}
\stoptext

Compilation with the currently latest ConTeXt LMTX (ver: 2021.03.17 
17:46 LMTX  fmt: 2021.3.18) fails with:


tex error       > runaway error: end of file encountered
mtx-context     | fatal error: return code: 1

Compilation is successful if I replace doifmode{mode}{...} by 
\startmode[mode]...\stopmode.


Is there anything I'm missing? (This could be a bug.)
not a bug, just the way tex works .. modes cannot know that what goes 
into an argument is something verbose


but you can use this (also more efficient here):

\definetyping[T]
\definemode[mode][yes]
\starttext
\startmode[mode]
\startT
Bla
\stopT
\stopmode
\stoptext

% there's also \startnotmode



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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-19 Thread Christoph Reller
On Fri, Mar 19, 2021 at 5:38 AM Aditya Mahajan  wrote:

> On Fri, 19 Mar 2021, Christoph Reller wrote:
>
> > Consider the following MWE:
> >
> > \definetyping[T]
> > \definemode[mode][yes]
> > \starttext
> > \doifmode{mode}{%
> >   \startT
> > Bla
> >   \stopT}
> > \stoptext
> >
> > Compilation with the currently latest ConTeXt LMTX (ver: 2021.03.17 17:46
> > LMTX  fmt: 2021.3.18) fails with:
> >
> > tex error   > runaway error: end of file encountered
> > mtx-context | fatal error: return code: 1
> >
> > Compilation is successful if I replace doifmode{mode}{...} by
> > \startmode[mode]...\stopmode.
>
> Has to be with how tex works. The argument of any macro
> (\doifmode{mode}{...} in this case) is scanned under the current catcode
> regime. So, any environment (like typing) which changes catcodes does work
> inside the argument to another macro.
>

I see. Strangely, the MWE did work in older versions of ConTeXt ;-)


> So, either use the environment version of \doifmode (which doesn't
> _capture_ it content):
>
> \definetyping[T]
> \definemode[mode][yes]
> \starttext
> \startmode[mode]
>   \startT
> Bla
>   \stopT
> \stopmode
> \stoptext
>
> Or use buffers (to avoid catcode all together):
>
> \definetyping[T]
> \definemode[mode][yes]
> \starttext
> \startbuffer[code]
> \startT
> Bla
> \stopT
> \stopbuffer
>
> \doifmode{mode}{\getbuffer[code]}
> \stoptext
>
> or (note type**T**buffer so that the output is formatting according to the
> options of \definetyping[T])
>
> \definetyping[T]
> \definemode[mode][yes]
> \starttext
> \startbuffer[code]
> Bla
> \stopbuffer
>
> \doifmode{mode}{\typeTbuffer[code]}
> \stoptext
>
> Perhaps this should be added to the FAQ on the wiki.
>
> Aditya
>

 Thank you for your ultra-speedy and very helpful response!

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


Re: [NTG-context] Typing within doifmode leads to error

2021-03-18 Thread Aditya Mahajan
On Fri, 19 Mar 2021, Christoph Reller wrote:

> Hi,
> 
> Consider the following MWE:
> 
> \definetyping[T]
> \definemode[mode][yes]
> \starttext
> \doifmode{mode}{%
>   \startT
> Bla
>   \stopT}
> \stoptext
> 
> Compilation with the currently latest ConTeXt LMTX (ver: 2021.03.17 17:46
> LMTX  fmt: 2021.3.18) fails with:
> 
> tex error   > runaway error: end of file encountered
> mtx-context | fatal error: return code: 1
> 
> Compilation is successful if I replace doifmode{mode}{...} by
> \startmode[mode]...\stopmode.
> 
> Is there anything I'm missing? (This could be a bug.)

Has to be with how tex works. The argument of any macro (\doifmode{mode}{...} 
in this case) is scanned under the current catcode regime. So, any environment 
(like typing) which changes catcodes does work inside the argument to another 
macro. 

So, either use the environment version of \doifmode (which doesn't _capture_ it 
content):

\definetyping[T]
\definemode[mode][yes]
\starttext
\startmode[mode]
  \startT
Bla
  \stopT
\stopmode
\stoptext

Or use buffers (to avoid catcode all together):

\definetyping[T]
\definemode[mode][yes]
\starttext
\startbuffer[code]
\startT
Bla
\stopT
\stopbuffer

\doifmode{mode}{\getbuffer[code]}
\stoptext

or (note type**T**buffer so that the output is formatting according to the 
options of \definetyping[T])

\definetyping[T]
\definemode[mode][yes]
\starttext
\startbuffer[code]
Bla
\stopbuffer

\doifmode{mode}{\typeTbuffer[code]}
\stoptext

Perhaps this should be added to the FAQ on the wiki.

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