ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Typing within doifmode leads to error
@ 2021-03-19  3:58 Christoph Reller
  2021-03-19  4:37 ` Aditya Mahajan
  2021-03-19  8:49 ` Hans Hagen
  0 siblings, 2 replies; 15+ messages in thread
From: Christoph Reller @ 2021-03-19  3:58 UTC (permalink / raw)
  To: ntg-context


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

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

Cheers,

Christoph Reller

[-- Attachment #1.2: Type: text/html, Size: 808 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] 15+ messages in thread

* Re: Typing within doifmode leads to error
  2021-03-19  3:58 Typing within doifmode leads to error Christoph Reller
@ 2021-03-19  4:37 ` Aditya Mahajan
  2021-03-19  6:59   ` Christoph Reller
  2021-03-19  8:49 ` Hans Hagen
  1 sibling, 1 reply; 15+ messages in thread
From: Aditya Mahajan @ 2021-03-19  4:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-19  4:37 ` Aditya Mahajan
@ 2021-03-19  6:59   ` Christoph Reller
  0 siblings, 0 replies; 15+ messages in thread
From: Christoph Reller @ 2021-03-19  6:59 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

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

[-- Attachment #1.2: Type: text/html, Size: 2621 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] 15+ messages in thread

* Re: Typing within doifmode leads to error
  2021-03-19  3:58 Typing within doifmode leads to error Christoph Reller
  2021-03-19  4:37 ` Aditya Mahajan
@ 2021-03-19  8:49 ` Hans Hagen
  2021-03-20  5:24   ` Christoph Reller
  1 sibling, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2021-03-19  8:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Christoph Reller

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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-19  8:49 ` Hans Hagen
@ 2021-03-20  5:24   ` Christoph Reller
  2021-03-20  7:24     ` Aditya Mahajan
  0 siblings, 1 reply; 15+ messages in thread
From: Christoph Reller @ 2021-03-20  5:24 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users


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

On Fri, Mar 19, 2021 at 9:49 AM Hans Hagen <j.hagen@xs4all.nl> 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

[-- Attachment #1.2: Type: text/html, Size: 2444 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] 15+ messages in thread

* Re: Typing within doifmode leads to error
  2021-03-20  5:24   ` Christoph Reller
@ 2021-03-20  7:24     ` Aditya Mahajan
  2021-03-20 11:11       ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Aditya Mahajan @ 2021-03-20  7:24 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
<?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 ?>
\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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-20  7:24     ` Aditya Mahajan
@ 2021-03-20 11:11       ` Hans Hagen
  2021-03-20 15:00         ` Christoph Reller
  0 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2021-03-20 11:11 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Aditya Mahajan

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
> <?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 ?>
> \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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-20 11:11       ` Hans Hagen
@ 2021-03-20 15:00         ` Christoph Reller
  2021-03-20 17:07           ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Christoph Reller @ 2021-03-20 15:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen <j.hagen@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
> > <?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 ?>
> > \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
<?lua if tex.modes['A'] then ?>
A
<?lua end ?>
\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

[-- Attachment #1.2: Type: text/html, Size: 1775 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] 15+ messages in thread

* Re: Typing within doifmode leads to error
  2021-03-20 15:00         ` Christoph Reller
@ 2021-03-20 17:07           ` Hans Hagen
  2021-03-20 20:23             ` Aditya Mahajan
  2021-03-21 14:44             ` Christoph Reller
  0 siblings, 2 replies; 15+ messages in thread
From: Hans Hagen @ 2021-03-20 17:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Christoph Reller

On 3/20/2021 4:00 PM, Christoph Reller wrote:
> On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen <j.hagen@xs4all.nl 
> <mailto:j.hagen@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
>      > <?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 ?>
>      > \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
> <?lua if tex.modes['A'] then ?>
> A
> <?lua end ?>
> \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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-20 17:07           ` Hans Hagen
@ 2021-03-20 20:23             ` Aditya Mahajan
  2021-03-20 20:49               ` Hans Hagen
  2021-03-21 14:44             ` Christoph Reller
  1 sibling, 1 reply; 15+ messages in thread
From: Aditya Mahajan @ 2021-03-20 20:23 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 1918 bytes --]

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 <j.hagen@xs4all.nl 
> > <mailto:j.hagen@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
> >      > <?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 ?>
> >      > \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
> > <?lua if tex.modes['A'] then ?>
> > A
> > <?lua end ?>
> > \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

[-- 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] 15+ messages in thread

* Re: Typing within doifmode leads to error
  2021-03-20 20:23             ` Aditya Mahajan
@ 2021-03-20 20:49               ` Hans Hagen
  2021-03-20 21:03                 ` Aditya Mahajan
  0 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2021-03-20 20:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Aditya Mahajan

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 <j.hagen@xs4all.nl
>>> <mailto:j.hagen@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
>>>       > <?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 ?>
>>>       > \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
>>> <?lua if tex.modes['A'] then ?>
>>> A
>>> <?lua end ?>
>>> \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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-20 20:49               ` Hans Hagen
@ 2021-03-20 21:03                 ` Aditya Mahajan
  2021-03-21  1:43                   ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Aditya Mahajan @ 2021-03-20 21:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
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] 15+ messages in thread

* Re: Typing within doifmode leads to error
  2021-03-20 21:03                 ` Aditya Mahajan
@ 2021-03-21  1:43                   ` Hans Hagen
  2021-03-21  2:40                     ` Aditya Mahajan
  0 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2021-03-21  1:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Aditya Mahajan

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
>    <?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.
this is just for the mode right? in that case we can also can provide

<?lua tex.enablemode("A") ?>

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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-21  1:43                   ` Hans Hagen
@ 2021-03-21  2:40                     ` Aditya Mahajan
  0 siblings, 0 replies; 15+ messages in thread
From: Aditya Mahajan @ 2021-03-21  2:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
> >    <?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.
> this is just for the mode right? in that case we can also can provide
> 
> <?lua tex.enablemode("A") ?>

:-)

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
___________________________________________________________________________________

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

* Re: Typing within doifmode leads to error
  2021-03-20 17:07           ` Hans Hagen
  2021-03-20 20:23             ` Aditya Mahajan
@ 2021-03-21 14:44             ` Christoph Reller
  1 sibling, 0 replies; 15+ messages in thread
From: Christoph Reller @ 2021-03-21 14:44 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users


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

On Sat, Mar 20, 2021 at 6:07 PM Hans Hagen <j.hagen@xs4all.nl> wrote:

> On 3/20/2021 4:00 PM, Christoph Reller wrote:
> > On Sat, Mar 20, 2021 at 12:12 PM Hans Hagen <j.hagen@xs4all.nl
> > <mailto:j.hagen@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
> >      > <?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 ?>
> >      > \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
> > <?lua if tex.modes['A'] then ?>
> > A
> > <?lua end ?>
> > \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

[-- Attachment #1.2: Type: text/html, Size: 2860 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] 15+ messages in thread

end of thread, other threads:[~2021-03-21 14:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19  3:58 Typing within doifmode leads to error Christoph Reller
2021-03-19  4:37 ` Aditya Mahajan
2021-03-19  6:59   ` Christoph Reller
2021-03-19  8:49 ` Hans Hagen
2021-03-20  5:24   ` Christoph Reller
2021-03-20  7:24     ` Aditya Mahajan
2021-03-20 11:11       ` Hans Hagen
2021-03-20 15:00         ` Christoph Reller
2021-03-20 17:07           ` Hans Hagen
2021-03-20 20:23             ` Aditya Mahajan
2021-03-20 20:49               ` Hans Hagen
2021-03-20 21:03                 ` Aditya Mahajan
2021-03-21  1:43                   ` Hans Hagen
2021-03-21  2:40                     ` Aditya Mahajan
2021-03-21 14:44             ` Christoph Reller

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