On Fri, Mar 19, 2021 at 5:38 AM Aditya Mahajan <adityam@umich.edu> 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