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
On 2013-10-08, at 7:22 AM, Procházka Lukáš Ing. - Pontex s. r. o.
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
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
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
On Tue, 08 Oct 2013 13:40:26 +0200, Marco Patzer
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
participants (3)
-
Aditya Mahajan
-
Marco Patzer
-
Procházka Lukáš Ing. - Pontex s. r. o.