I'm preparing some slides with Beamer and I've just discovered that the listings package, which otherwise does exactly what I want, is missing the syntax for the Lua language. How can I configure listings to highlight Lua?


2 Answers 2


The premise of your question is wrong. The listings package defines no fewer than three Lua "dialects" in the file lstdvrs.dtx: [5.0]Lua, [5.1]Lua, and [5.2]Lua. Pick whichever is appropriate. You may want to change the way things look, but you shouldn't have to redefine all the syntax from scratch.

enter image description here



  language         = {[5.0]Lua},
  basicstyle       = \ttfamily,
  showstringspaces = false,
  upquote          = true,


-- defines a factorial function
    function fact (n)
      if n == 0 then
        return 1
        return n * fact(n-1)

    print("enter a number:")
    a = io.read("*number")        -- read a number
  • Thanks for your answer, effectively I was wrong. So the problem is elsewhere, your sample doesn't work for me, I must miss the file lstdvrs.dtx, I'm under Debian Wheezy with package latex-beamer installed, does this extension packaged, and do you know it's name ?
    – Rodolphe
    Apr 3, 2014 at 11:30
  • As far as I know, as long as your TeX distro comes with the listings package, you shouldn't have to worry about lstdvrs.dtx. All the necessary files should come with the package. Unfortunately, I'm not familiar with Debian. Perhaps you should ask a separate question about that specific problem.
    – jub0bs
    Apr 3, 2014 at 11:33
  • I found where the languages are defined, there are files under /usr/share/texlive/texmf-dist/tex/latex/listings/lang*.sty there are a lot of language defined here but not Lua, I agree that the problem is more Debian related, so I'll look for a solution elsewhere, thanks again.
    – Rodolphe
    Apr 3, 2014 at 11:41
  • 1
    @Rodolphe: Looks like this should be of interest for you: How to install "vanilla" TeXLive on Debian or Ubuntu?
    – Speravir
    Apr 4, 2014 at 0:29

There is dialect 5.0 defined:



local words = io.open('hyphens-' .. tex.jobname .. '.txt', 'w');
local outchar = unicode.utf8.char
local function dumphyphens (head)
   local data = {}
   for v in node.traverse(head) do
       if v.id == node.id('glyph') then
         data[#data+1] = outchar(v.char);
       elseif v.id == node.id('disc') then
          data[#data+1] = '-'
       elseif v.id == node.id('glue') then
         data[#data+1] = outchar(32)
       elseif v.id == node.id('hlist') then
         data[#data+1] = dumphyphens(v.list)
   return table.concat(data)
callback.register ('hyphenate', function (head,tail)
   lang.hyphenate(head, tail) 
   words:write (dumphyphens(head) .. outchar(10))


enter image description here

  • Don't use \lst@definelanguage here. Use \lstdefinelanguage instead; see this. Also, if you want to use * as a keyword, you need to make it a letter first: alsoletter=*.
    – jub0bs
    Apr 3, 2014 at 10:01
  • It makes absolutely no difference!
    – user2478
    Apr 3, 2014 at 11:13
  • Using \lst@definelanguage outside driver files can be associated with nasty side effects. See the question I link to and cgnieder's comment.
    – jub0bs
    Apr 3, 2014 at 11:15
  • The only difference is that \lst@DefLang is set to \false.
    – user2478
    Apr 3, 2014 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .