What is the interweaving of context and Lua?

What is the interweaving of context and Lua?

The interweaving of ConTeXt and Lua consists of two elements: first you tell TeX that you’re starting some Lua code; then, once inside Lua, you need to use the appropriate functions to put things into the TeX stream.

How to write Lua code in a TeX document?

In general, you will define a function inside a \\startluacode block, and then define a TeX command that calls the function using \\ctxlua, especially because \\ctxlua has a few idiosyncracies. The main thing about Lua code in a TeX document is this: the code is expanded by TeX before Lua gets to it.

What are some examples of programming in LuaTeX?

For example, suppose we want to typeset a table showing the sum of the roll of two dice and want the output to look like this: This is easy in LuaTeX. Once a Lua instance starts, TeX does not see anything until the Lua instance exits.

Why are there so many loops in Tex?

Loops in TeX are tricky, because macro assignments and macro expansion interact in strange ways. For example, suppose we want to typeset a table showing the sum of the roll of two dice and want the output to look like this: This is easy in LuaTeX. Once a Lua instance starts, TeX does not see anything until the Lua instance exits.

Is the Lua code in a TeX document valid?

The main thing about Lua code in a TeX document is this: the code is expanded by TeX before Lua gets to it. This means that all the Lua code, even the comments, must be valid TeX! A string like “\ndefined” will cause an immediate failure. $2 + 5 eq \\ctxlua{ context ( 3+5)} $, but is equal to \\ctxlua{ context ( 2+5)} .

Which is the wrapper around the LuaTeX primitive \\ directlua?

Both are wrappers around the LuaTeX primitive \\directlua, which you should never need to use. In general, you will define a function inside a \\startluacode block, and then define a TeX command that calls the function using \\ctxlua, especially because \\ctxlua has a few idiosyncracies.