# [luatex] Building a PDF with Lua code, without a TeX stub

David Carlisle d.p.carlisle at gmail.com
Thu Oct 20 10:47:04 CEST 2016

On 20 October 2016 at 07:25, Deepak Jois <deepak.jois at gmail.com> wrote:
> Hi
> I would like to invoke the LuaTeX interpreter with a Lua file which
> does the node building etc, and then calls something like
> tex.shipout(), which can generate a PDF. I am aware of the --lua flag,
> but the file passed to that flag executes before the TeX engine is
> fully initialised. So that’s not what I am looking for
>
> For example, lets say I have a Lua file with code:
>
> <code>
> -- Page settings
> tex.pagewidth = "210mm"
> tex.pageheight = "297mm"
> tex.hsize = "210mm"
>
> -- Set the paragraph indentation
> tex.parindent = "20pt"
>
> tex.sprint("hello world")
> </code>
>
> and I want to generate a PDF from it directly using the luatex
> command. I cannot seem to do that right now, and I require a stub TeX
> file like this.
>
> <code>
> \outputmode=1 % this could be avoided if I pass --output-format=pdf
> \directlua{dofile('code.lua')}
> \bye
> </code>
>
> Questions:
>
> - Is there a way to avoid creating the stub TeX file?
>
> - If not, is it something worth adding (or possible to add) as a
> feature to the LuaTeX program?
>
> Deepak
>

You don't need a file, although you do need some tex code,
this produces a pdf with hello world if I save your lua as zz.lua

luatex '\directlua{require("zz")}\end'

of course you could have written the \end from lua as well so you
really just need
a calling line as

luatex '\directlua{require("zz")}'

David