ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Hooking \stoptext
@ 2012-03-07 14:28 Procházka Lukáš Ing. - Pontex s. r. o.
  2012-03-07 14:39 ` luigi scarso
  2012-03-07 15:50 ` Philipp Gesang
  0 siblings, 2 replies; 13+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2012-03-07 14:28 UTC (permalink / raw)
  To: ConTeXt

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

Hello,

I'd need to to hook \stoptext by Lua - I'd need to write something right before the end of the text.

See the simple example:

---- t-Hook.mkiv
\startluacode
   local stoptext_p = context.stoptext

   context.stoptext = function(...)
     context("END")
     stoptext_p(...)
   end
\stopluacode

\starttext
   \input knuth
\stoptext % To be hooked by Lua
----

This code should write "END" right before the end of the document, but it doesn't.

How to achieve that?

- I'd rather Lua to TeX do the job as I need Lua to do more complicated things (the example above is very simplified).

TIA.

Best regards,

Lukas


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

[-- Attachment #2: t-Hook.mkiv --]
[-- Type: application/octet-stream, Size: 195 bytes --]

\startluacode
  local stoptext_p = context.stoptext

  context.stoptext = function(...)
    context("END")
    stoptext_p(...)
  end
\stopluacode

\starttext
  \input knuth
\stoptext

[-- Attachment #3: t-Hook.pdf --]
[-- Type: application/pdf, Size: 9427 bytes --]

[-- Attachment #4: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking \stoptext
  2012-03-07 14:28 Hooking \stoptext Procházka Lukáš Ing. - Pontex s. r. o.
@ 2012-03-07 14:39 ` luigi scarso
  2012-03-07 15:14   ` luigi scarso
  2012-03-07 15:26   ` Procházka Lukáš Ing. - Pontex s. r. o.
  2012-03-07 15:50 ` Philipp Gesang
  1 sibling, 2 replies; 13+ messages in thread
From: luigi scarso @ 2012-03-07 14:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

2012/3/7 Procházka Lukáš Ing. - Pontex s. r. o. <LPr@pontex.cz>

> Hello,
>
> I'd need to to hook \stoptext by Lua - I'd need to write something right
> before the end of the text.
>

At least
\let\Oldstoptext\stoptext
\def\stoptext{%
\startluacode
context("END")
\stopluacode
\Oldstoptext}


\starttext
 \input knuth
\stoptext % To be hooked by Lua


But there are several \every* tokens list for this.
-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 736 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking \stoptext
  2012-03-07 14:39 ` luigi scarso
@ 2012-03-07 15:14   ` luigi scarso
  2012-03-07 15:26   ` Procházka Lukáš Ing. - Pontex s. r. o.
  1 sibling, 0 replies; 13+ messages in thread
From: luigi scarso @ 2012-03-07 15:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On Wed, Mar 7, 2012 at 3:39 PM, luigi scarso <luigi.scarso@gmail.com> wrote:

>
>
> 2012/3/7 Procházka Lukáš Ing. - Pontex s. r. o. <LPr@pontex.cz>
>
> Hello,
>>
>> I'd need to to hook \stoptext by Lua - I'd need to write something right
>> before the end of the text.
>>
>
> At least
> \let\Oldstoptext\stoptext
> \def\stoptext{%
> \startluacode
> context("END")
> \stopluacode
> \Oldstoptext}
>
>
>
> \starttext
>  \input knuth
> \stoptext % To be hooked by Lua
>
>
> But there are several \every* tokens list for this.
> --
> luigi
>
>
\appendtoks%
\startluacode
context("END")
\stopluacode
\to\everylastshipout
\starttext
\showframe
 \input knuth
 \page
 \input tufte
\stoptext % To be hooked by Lua

It's hooked by Lua too, but is it what you want ?

-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 1486 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking \stoptext
  2012-03-07 14:39 ` luigi scarso
  2012-03-07 15:14   ` luigi scarso
@ 2012-03-07 15:26   ` Procházka Lukáš Ing. - Pontex s. r. o.
  1 sibling, 0 replies; 13+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2012-03-07 15:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

... OK, your solution works -

- But I'd need one which doesn't force user to hook manually; i.e. without:

----
\let\Oldstoptext\stoptext
\def\stoptext{%
   \startluacode
   context("END")
   \stopluacode
   \Oldstoptext
}
----

Hooking should be performed in a Lua function and should be "invisible" to the user.

More complicated example:

---- t-Hook4.mkiv
\startluacode
   function foo()
     local stoptext_p = context.stoptext

     context.stoptext = function(...)
       context("END")
       stoptext_p(...)
     end
   end
\stopluacode

\starttext
   \input knuth

   \ctxlua{foo()} % This should cause "END" to appear at the end of the document
\stoptext
----

In this case, "foo()" is a function which does the hooking; and "foo()" may be placed in another file or Lua toolbox, so user is to call Lua's "require 'my-Lua-toolbox-with-foo' foo()".

So user is not forced to know how the function works; once he uses it, the text "END" will appear at the end of the document.

- And this doesn't happen to me; and my goal is to make it work.

Lukas


On Wed, 07 Mar 2012 15:39:23 +0100, luigi scarso <luigi.scarso@gmail.com> wrote:

> 2012/3/7 Procházka Lukáš Ing. - Pontex s. r. o. <LPr@pontex.cz>
>
>> Hello,
>>
>> I'd need to to hook \stoptext by Lua - I'd need to write something right
>> before the end of the text.
>>
>
> At least
> \let\Oldstoptext\stoptext
> \def\stoptext{%
> \startluacode
> context("END")
> \stopluacode
> \Oldstoptext}
>
>
> \starttext
>  \input knuth
> \stoptext % To be hooked by Lua
>
>
> But there are several \every* tokens list for this.


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

[-- Attachment #2: t-Hook4.mkiv --]
[-- Type: application/octet-stream, Size: 313 bytes --]

\startluacode
  function foo()
    local stoptext_p = context.stoptext

    context.stoptext = function(...)
      context("END")
      stoptext_p(...)
    end
  end
\stopluacode

\starttext
  \input knuth

  \ctxlua{foo()} % This should cause "END" to appear at the end of the document
\stoptext

[-- Attachment #3: t-Hook4.pdf --]
[-- Type: application/pdf, Size: 9432 bytes --]

[-- Attachment #4: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking \stoptext
  2012-03-07 14:28 Hooking \stoptext Procházka Lukáš Ing. - Pontex s. r. o.
  2012-03-07 14:39 ` luigi scarso
@ 2012-03-07 15:50 ` Philipp Gesang
  2012-03-07 15:57   ` Procházka Lukáš Ing. - Pontex s. r. o.
  1 sibling, 1 reply; 13+ messages in thread
From: Philipp Gesang @ 2012-03-07 15:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

On 2012-03-07 15:28, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
> Hello,
> 
> I'd need to to hook \stoptext by Lua - I'd need to write something right before the end of the text.
> 
> See the simple example:
> 
> ---- t-Hook.mkiv
> \startluacode
>   local stoptext_p = context.stoptext
> 
>   context.stoptext = function(...)
>     context("END")
>     stoptext_p(...)
>   end
> \stopluacode
> 
> \starttext
>   \input knuth
> \stoptext % To be hooked by Lua
> ----
> 
> This code should write "END" right before the end of the document, but it doesn't.

context.stoptext() just calls “\stoptext”, not the other way
round. Btw CLD are implemented as metatable so afaik you would
have to redefine the “__index” attribute.

> How to achieve that?

········································································
\startluacode
  local old_stoptext = commands.stoptext

  commands.stoptext = function(...)
    context"END"
    old_stoptext(...)
  end
\stopluacode

\starttext
  \input knuth
\stoptext % To be hooked by Lua
········································································

Cf. file.job.mkvi at line 107.

Hth
Philipp


> 
> - I'd rather Lua to TeX do the job as I need Lua to do more complicated things (the example above is very simplified).
> 
> TIA.
> 
> Best regards,
> 
> Lukas
> 
> 
> -- 
> Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
> Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
> Bezová 1658
> 147 14 Praha 4
> 
> Tel: +420 244 062 238
> Fax: +420 244 461 038



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


-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking \stoptext
  2012-03-07 15:50 ` Philipp Gesang
@ 2012-03-07 15:57   ` Procházka Lukáš Ing. - Pontex s. r. o.
  2012-03-07 17:37     ` Wolfgang Schuster
  0 siblings, 1 reply; 13+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2012-03-07 15:57 UTC (permalink / raw)
  To: mailing list for ConTeXt users

... Yes, that's it! Thanks a lot!

Best regards,

Lukas


On Wed, 07 Mar 2012 16:50:01 +0100, Philipp Gesang <gesang@stud.uni-heidelberg.de> wrote:

> On 2012-03-07 15:28, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
>> Hello,
>>
>> I'd need to to hook \stoptext by Lua - I'd need to write something right before the end of the text.
>>
>> See the simple example:
>>
>> ---- t-Hook.mkiv
>> \startluacode
>>   local stoptext_p = context.stoptext
>>
>>   context.stoptext = function(...)
>>     context("END")
>>     stoptext_p(...)
>>   end
>> \stopluacode
>>
>> \starttext
>>   \input knuth
>> \stoptext % To be hooked by Lua
>> ----
>>
>> This code should write "END" right before the end of the document, but it doesn't.
>
> context.stoptext() just calls “\stoptext”, not the other way
> round. Btw CLD are implemented as metatable so afaik you would
> have to redefine the “__index” attribute.
>
>> How to achieve that?
>
> ········································································
> \startluacode
>   local old_stoptext = commands.stoptext
>
>   commands.stoptext = function(...)
>     context"END"
>     old_stoptext(...)
>   end
> \stopluacode
>
> \starttext
>   \input knuth
> \stoptext % To be hooked by Lua
> ········································································
>
> Cf. file.job.mkvi at line 107.
>
> Hth
> Philipp
>
>
>>
>> - I'd rather Lua to TeX do the job as I need Lua to do more complicated things (the example above is very simplified).
>>
>> TIA.
>>
>> Best regards,
>>
>> Lukas
>>
>>
>> --
>> Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
>> Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
>> Bezová 1658
>> 147 14 Praha 4
>>
>> Tel: +420 244 062 238
>> Fax: +420 244 461 038
>
>
>
>> ___________________________________________________________________________________
>> 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
>> ___________________________________________________________________________________
>
>


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

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

* Re: Hooking \stoptext
  2012-03-07 15:57   ` Procházka Lukáš Ing. - Pontex s. r. o.
@ 2012-03-07 17:37     ` Wolfgang Schuster
  2012-03-07 23:07       ` Wolfgang Schuster
  0 siblings, 1 reply; 13+ messages in thread
From: Wolfgang Schuster @ 2012-03-07 17:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 07.03.2012 um 16:57 schrieb Procházka Lukáš Ing. - Pontex s. r. o.:

> ... Yes, that's it! Thanks a lot!

You can also write your own stop/stop-commands for the document like

\def\startmydocument
  {\starttext}

\def\stopmydocument
  {\ctxlua{…}%
   \stoptext}

and use them instead of \starttext and \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] 13+ messages in thread

* Re: Hooking \stoptext
  2012-03-07 17:37     ` Wolfgang Schuster
@ 2012-03-07 23:07       ` Wolfgang Schuster
  0 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Schuster @ 2012-03-07 23:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 07.03.2012 um 18:37 schrieb Wolfgang Schuster:

> 
> Am 07.03.2012 um 16:57 schrieb Procházka Lukáš Ing. - Pontex s. r. o.:
> 
>> ... Yes, that's it! Thanks a lot!
> 
> You can also write your own stop/stop-commands for the document like
> 
> \def\startmydocument
>  {\starttext}
> 
> \def\stopmydocument
>  {\ctxlua{…}%
>   \stoptext}
> 
> and use them instead of \starttext and \stoptext.

Or you use the predefined document environment which has before and after keys.

\setupdocument[after={\blank\midaligned{\bf THE END}}]

\startdocument
\input knuth
\stopdocument

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

* Re: Hooking stoptext
  2013-10-08 11:40 ` Marco Patzer
  2013-10-08 11:43   ` Marco Patzer
@ 2013-10-08 11:52   ` Procházka Lukáš Ing. - Pontex s. r. o.
  1 sibling, 0 replies; 13+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2013-10-08 11:52 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, 08 Oct 2013 13:40:26 +0200, Marco Patzer <lists@homerow.info> wrote:

> On 2013–10–08 Procházka Lukáš Ing. - Pontex s. r. o. wrote:
>
>> I'm trying to hook commands.stoptext()...
>
> There is already a hook for that. No need to tinker with Lua.
>
> \setupexternalfigures
>   [location=default]
>
> \setupdocument
>   [after=\setups{document:after}]
>
> \startsetups [document:after]
>   \startTEXpage
>     \externalfigure [cow]
>   \stopTEXpage
> \stopsetups
>
> \startdocument
>   \input knuth
> \stopdocument
>
> Marco
>

OK... But - is there a solution "more close" and "more Lua" to that mine?

The example is much simpler than I need to use in reality;
and I'd like to hide the document-after-operation to the user.

The hook should be automatically generated once the user uses Lua's "f()";
but not earlier (in the document setup).

In your example, user needs to "\setupdocument[after=...]" which I'd like to avoid.

And - any idea why my minimal example works when the image is NOT surrounded with \s/s-TEXpage, while when it is enclosed, only first figure appears?

Lukas


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

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

* Re: Hooking stoptext
  2013-10-08 11:40 ` Marco Patzer
@ 2013-10-08 11:43   ` Marco Patzer
  2013-10-08 11:52   ` Procházka Lukáš Ing. - Pontex s. r. o.
  1 sibling, 0 replies; 13+ messages in thread
From: Marco Patzer @ 2013-10-08 11:43 UTC (permalink / raw)
  To: ntg-context


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

On 2013–10–08 Marco Patzer wrote:

> On 2013–10–08 Procházka Lukáš Ing. - Pontex s. r. o. wrote:
> 
> > I'm trying to hook commands.stoptext()...
> 
> There is already a hook for that. No need to tinker with Lua.
> 
> \setupexternalfigures
>   [location=default]
> 
> \setupdocument
>   [after=\setups{document:after}]
> 
> \startsetups [document:after]
>   \startTEXpage
>     \externalfigure [cow]
>   \stopTEXpage
> \stopsetups
> 
> \startdocument
>   \input knuth
> \stopdocument

Even shorter:

\setupexternalfigures
  [location=default]

\setupdocument
  [after={\pagefigure[cow]}]

\startdocument
  \input knuth
\stopdocument

Marco

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking stoptext
  2013-10-08 11:22 Hooking stoptext Procházka Lukáš Ing. - Pontex s. r. o.
  2013-10-08 11:34 ` Aditya Mahajan
@ 2013-10-08 11:40 ` Marco Patzer
  2013-10-08 11:43   ` Marco Patzer
  2013-10-08 11:52   ` Procházka Lukáš Ing. - Pontex s. r. o.
  1 sibling, 2 replies; 13+ messages in thread
From: Marco Patzer @ 2013-10-08 11:40 UTC (permalink / raw)
  To: ntg-context


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

On 2013–10–08 Procházka Lukáš Ing. - Pontex s. r. o. wrote:

> I'm trying to hook commands.stoptext()...

There is already a hook for that. No need to tinker with Lua.

\setupexternalfigures
  [location=default]

\setupdocument
  [after=\setups{document:after}]

\startsetups [document:after]
  \startTEXpage
    \externalfigure [cow]
  \stopTEXpage
\stopsetups

\startdocument
  \input knuth
\stopdocument

Marco

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 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] 13+ messages in thread

* Re: Hooking stoptext
  2013-10-08 11:22 Hooking stoptext Procházka Lukáš Ing. - Pontex s. r. o.
@ 2013-10-08 11:34 ` Aditya Mahajan
  2013-10-08 11:40 ` Marco Patzer
  1 sibling, 0 replies; 13+ messages in thread
From: Aditya Mahajan @ 2013-10-08 11:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 2013-10-08, at 7:22 AM, Procházka Lukáš Ing. - Pontex s. r. o. <LPr@pontex.cz> wrote:

> Hello,
> 
> I'm trying to hook commands.stoptext()...
> 
> Here's a minimal example: why only the first image appears?
> 
> ----
> \startluacode
>  local cmd_p
>  local tab = {}
> 
>  f = function(a)
>    if not cmd_p then
>      cmd_p = commands.stoptext
> 
>      commands.stoptext = function(...)
>        context("Hook")
> 
>        for _, v in ipairs(tab) do
>          context.startTEXpage()
>            context.externalfigure{v}
>          context.stopTEXpage()
>        end
> 
>        cmd_p(...)
>      end
>    end
> 
>    table.insert(tab, a)
>  end
> \stopluacode
> 
> \starttext
>  A
>  \ctxlua{f("cow")}
>  \ctxlua{f("hacker")}
> \stoptext
> ----
> 
> When I modify the code:
> 
> ----
> ...
>        for _, v in ipairs(tab) do
>          --context.startTEXpage()
>            context.externalfigure{v}
>          --context.stopTEXpage()
>        end
> ...
> ----
> 
> all figures are shown OK.
> 
> Where's the problem?

An alternative is to use (untested)

\appendtoks ... \to \everystoptext 

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

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

* Hooking stoptext
@ 2013-10-08 11:22 Procházka Lukáš Ing. - Pontex s. r. o.
  2013-10-08 11:34 ` Aditya Mahajan
  2013-10-08 11:40 ` Marco Patzer
  0 siblings, 2 replies; 13+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2013-10-08 11:22 UTC (permalink / raw)
  To: ConTeXt

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

Hello,

I'm trying to hook commands.stoptext()...

Here's a minimal example: why only the first image appears?

----
\startluacode
   local cmd_p
   local tab = {}

   f = function(a)
     if not cmd_p then
       cmd_p = commands.stoptext

       commands.stoptext = function(...)
         context("Hook")

         for _, v in ipairs(tab) do
           context.startTEXpage()
             context.externalfigure{v}
           context.stopTEXpage()
         end

         cmd_p(...)
       end
     end

     table.insert(tab, a)
   end
\stopluacode

\starttext
   A
   \ctxlua{f("cow")}
   \ctxlua{f("hacker")}
\stoptext
----

When I modify the code:

----
...
         for _, v in ipairs(tab) do
           --context.startTEXpage()
             context.externalfigure{v}
           --context.stopTEXpage()
         end
...
----

all figures are shown OK.

Where's the problem?

TIA.

Best regards,

Lukas


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

[-- Attachment #2: t.pdf --]
[-- Type: application/pdf, Size: 10212 bytes --]

[-- Attachment #3: t.mkiv --]
[-- Type: application/octet-stream, Size: 516 bytes --]

\startluacode
  local cmd_p
  local tab = {}

  f = function(a)
    if not cmd_p then
      cmd_p = commands.stoptext

      commands.stoptext = function(...)
        context("Hook")

        for _, v in ipairs(tab) do
          context.startTEXpage()
            context.externalfigure{v}
          context.stopTEXpage()
        end

        cmd_p(...)
      end
    end

    table.insert(tab, a)
  end
\stopluacode

\starttext
  A
  \ctxlua{f("cow")}
  \ctxlua{f("hacker")}
\stoptext

[-- Attachment #4: Type: text/plain, Size: 485 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] 13+ messages in thread

end of thread, other threads:[~2013-10-08 11:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-07 14:28 Hooking \stoptext Procházka Lukáš Ing. - Pontex s. r. o.
2012-03-07 14:39 ` luigi scarso
2012-03-07 15:14   ` luigi scarso
2012-03-07 15:26   ` Procházka Lukáš Ing. - Pontex s. r. o.
2012-03-07 15:50 ` Philipp Gesang
2012-03-07 15:57   ` Procházka Lukáš Ing. - Pontex s. r. o.
2012-03-07 17:37     ` Wolfgang Schuster
2012-03-07 23:07       ` Wolfgang Schuster
2013-10-08 11:22 Hooking stoptext Procházka Lukáš Ing. - Pontex s. r. o.
2013-10-08 11:34 ` Aditya Mahajan
2013-10-08 11:40 ` Marco Patzer
2013-10-08 11:43   ` Marco Patzer
2013-10-08 11:52   ` Procházka Lukáš Ing. - Pontex s. r. o.

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