Nice! Thanks a lot, Max!
--Mohammad
On Sat, Mar 29, 2025 at 6:43 PM Max Chernoff via ntg-context <
[email protected]> wrote:
> Hi Mohammad,
>
> On Sat, 2025-03-29 at 11:06 -0400, Mohammad Hossein Bateni wrote:
> > Is there a more elegant solution?
> > Ideally I want a way to start a TeX process under Lua, and
> > process the macros there before I get to the next line of Lua code.
>
> One option is to use "publications.prerollcmdstring", which fully and
> completely expands its arguments (it typesets the arguments in a box and
> then parses the box's glyphs). Another option is to use
> "context.stepwise", which lets you interleave TeX and Lua execution.
>
> Demonstration:
>
> \define[1]\MakeSomething{%
> \setbox0=\hbox{#1}%
> \ifdim\wd0>12pt\relax%
> 12%
> \else%
> X%
> \fi%
> }
>
> \newcount\mycounter
> \define\incrementmycounter{%
> \advance\mycounter by 1\relax%
> }
>
> \startluacode
> local function WorkWithSomething(data)
> local value =
> publications.prerollcmdstring(([[\MakeSomething{%s}]]):format(data))
> return ("<%s>"):format(value)
> end
>
> interfaces.implement {
> name = "WorkWithSomething",
> arguments = { "string" },
> actions = { WorkWithSomething, context },
> public = true,
> }
>
> for i=1, 10 do
> context.incrementmycounter()
> print(tex.count.mycounter)
> end
>
> context.stepwise(function()
> for i=1, 10 do
> context.incrementmycounter()
> context.step()
> print(tex.count.mycounter)
> end
> end)
> \stopluacode
>
> \startTEXpage
> \WorkWithSomething{.}
> \WorkWithSomething{XXX}
> \stopTEXpage
>
> Thanks,
> -- Max
>
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : [email protected] /
> https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive : https://github.com/contextgarden/context
> wiki : https://wiki.contextgarden.net
>
> ___________________________________________________________________________________
>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________