When I read this from the manual a long time ago: The \directlua command is expandable: the results of the LUA code become effective immediately. I could not make sense of it, and actually cannot up to day. What are "the results of the LUA code"? What does "become effective" mean? Now I now the answers to those questions but not because of the explanation given there. The example provided does not help much either. Note that this comes very soon in the manual. I propose the following wording: The \directlua command is expandable. Since it passes Lua code to the Lua interpreter its expansion from the TeX viewpoint is usually empty. However, there are some Lua functions that produce material to be read by TeX, the so called print functions. The most simple use of these is tex.print(<string> s). The characters of the string s will be placed on TeX input buffer, that is, "before TeX's eyes" to be read by TeX immediately. For example: \count10=20 a\directlua{tex.print(tex.count[10]+5)}b expands to a25b Here is another example: $\pi = \directlua{tex.print(math.pi)}$ will result in p = 3.1415926535898 Note that the expansion of \directlua is a sequence of characters, not of tokens, contrary to all TeX commands. So formally speaking its expansion is null, but places material on a pseudo-file to be immediately read by TeX, as etex's \scantokens. For a description of print functions look at section 4.13.10. Regards, Javier A. Múgica
On 10/11/2011 01:53 PM, Javier Múgica de Rivera wrote:
When I read this from the manual a long time ago:
The \directlua command is expandable: the results of the LUA code become effective immediately.
I could not make sense of it, and actually cannot up to day. What are "the results of the LUA code"? What does "become effective" mean? Now I now the answers to those questions but not because of the explanation given there. The example provided does not help much either. Note that this comes very soon in the manual. I propose the following wording:
Thanks a lot! Applied to the repository version. Best wishes, Taco
Am 11.10.2011 um 13:53 schrieb Javier Múgica de Rivera:
Note that the expansion of \directlua is a sequence of characters, not of tokens, contrary to all TeX commands. So formally speaking its expansion is null, but places material on a pseudo-file to be immediately read by TeX, as etex's \scantokens.
For a description of print functions look at section 4.13.10.
Is that really true? When you assign catcodes (catcode tables) to the print functions, TeX's behavior is different from scantokens. I have never used scantokens, so I am not 100% sure. Take for example: tex.print(-2, "\\def\\foo{abc}") will not define \foo. While you have referenced the section with the print commands, I think that the description is misleading. Patrick
participants (3)
-
Javier Múgica de Rivera
-
Patrick Gundlach
-
Taco Hoekwater