A Quick How-to on using LuaTeX with ConTeXt

#context, tex, typesetting

Published: Sep 15, 2010

LuaTeX is an extended version of pdfTeX using Lua as an embedded scripting language.

ConTeXt is a document processing system based on TeX.

This is a short how-to on how to embed Lua code into TeX.

\starttext
Hello World

\startluacode
  -- A lua comment
   tex.print("This is printed.")
  local t = {1,2,3,4}
   tex.print("length " .. #t)
\stopluacode

\ctxlua
  {local t = {1,2,3,4}
   tex.print("length " .. \string#t)}

\stoptext

Compile(!) the .tex file:

    $ texexec --luatex hello

You can open hello.pdf to see the results, which should be:

Hello World
length 4