Changes

Jump to navigation Jump to search
m
→‎Interaction between TeX and Lua: A note about exansion of \startluacode
</texcode>
The contents of <code>\startluacode</code> ... <code>\stopluacode</code>, like the argument of <code>\ctxlua</code> are fully expanded. '''This mean that even the Lua comments should be valid TeX statements!''' For example,<texcode>\startluacode -- \undefined\stopluacode</texcode>will give an error because when TeX expands the contents, it encounters <code>\undefined</code> which is an undefined TeX macro. This error can be avoided by using <code>\type{\undefined}</code> or <code>\\undefined</code>. In general, the <code>\startluacode</code> ... <code>\stopluacode</code> environment is meant for moderately sized code snippets. For longer Lua code, it is more convenient to write the code in a separate Lua file and then load it using Lua's <code>dofile(...)</code> function.
ConTeXt also provides a Lua function to conveniently write to the TeX stream. The function is called <code>context(...)</code> and it is equivalent to <code>tex.print(string.format(...))</code>.

Navigation menu