TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Calling texlua file.lua on the command line runs the file through a Lua interpreter. Is it possible to give arguments to the script?

For instance, in

-- file.lua
io.write(3.4 + 5.6)

How do I make 5.6 into a parameter given on the command line?

share|improve this question
When egreg and I wrote checkcites, we opted for running it under texlua because the interpreter is available on every modern TeX distribution. :) – Paulo Cereda Jul 31 '12 at 18:31
@PauloCereda My goal is to provide a couple of LuaTeX-like functionalities in XeTeX by calling a texlua script within \immediate\write18. – Bruno Le Floch Jul 31 '12 at 19:09
cool, the idea sounds awesome! :) Well, you are a synonymous of awesomeness. :) – Paulo Cereda Aug 1 '12 at 13:37
up vote 7 down vote accepted
-- file.lua
io.write(arg[1] + arg[2])

$ texlua file.lua 103.4 5.6
share|improve this answer
Just to expand David's answer: Lua creates a table with all the command line arguments in a global variable named arg. The script name is in the index 0, the first argument is in 1, and so on. If you try negative indices, you go back in the line, so in David's example, arg[-1] == texlua. :) – Paulo Cereda Jul 31 '12 at 18:25
@PauloCereda But you can't go further back than texlua, i.e., in time texlua file.lua, arg[-2] is nil. – Bruno Le Floch Jul 31 '12 at 19:07
@BrunoLeFloch: you are right, the chain stops at the interpreter. :( – Paulo Cereda Aug 1 '12 at 8:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.