[NTG-context] Typing within doifmode leads to error

Aditya Mahajan adityam at umich.edu
Sat Mar 20 22:03:31 CET 2021


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
  <?lua if tex.modes["A"] and not tex.modes["B"] then ?>
  \starttyping
  A and not B
  \stoptyping
  <?lua else ?>
  \starttyping
  not (A and not B)
  \stoptyping
  <?lua end ?>
\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]
  <?lua if tex.modes["A"] and not tex.modes["B"] then ?>
  \starttyping
  A and not B
  \stoptyping
  <?lua else ?>
  \starttyping
  not (A and not B)
  \stoptyping
  <?lua end ?>
\stopbuffer
\savebuffer[file={\jobname-luatemplate.mkix}, list={luatemplate}]
\input \jobname-luatemplate.mkix
\stoptext

but without the need to save to an external file. 

Aditya


More information about the ntg-context mailing list