Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua syntax highlighting latex for arXiv

I have a latex file which needed to include snippets of Lua code (for display, not execution), so I used the minted package. It requires latex to be run with the latex -shell-escape flag.

I am trying to upload a PDF submission to arXiv. The site requires these to be submitted as .tex, .sty and .bbl, which they will automatically compile to PDF from latex. When I tried to submit to arXiv, I learned that there was no way for them to activate the -shell-escape flag.

So I was wondering if any of you knew a way to highlight Lua code in latex without the -shell-escape flag. I tried the listings package, but I can't get it to work for Lua on my Ubuntu computer.

like image 320
Nicholas Leonard Avatar asked Nov 24 '15 17:11

Nicholas Leonard


2 Answers

You can set whichever style you want inline using listings. It's predefined Lua language has all the keywords and associated styles identified, so you can just change it to suit your needs:

enter image description here

\documentclass{article}

\usepackage{listings,xcolor}

\lstdefinestyle{lua}{
  language=[5.1]Lua,
  basicstyle=\ttfamily,
  keywordstyle=\color{magenta},
  stringstyle=\color{blue},
  commentstyle=\color{black!50}
}

\begin{document}

\begin{lstlisting}[style=lua]
-- defines a factorial function
    function fact (n)
      if n == 0 then
        return 1
      else
        return n * fact(n-1)
      end
    end

    print("enter a number:")
    a = io.read("*number")        -- read a number
    print(fact(a))
\end{lstlisting}

\end{document}
like image 176
Werner Avatar answered Oct 15 '22 10:10

Werner


Okay so lhf found a good solution by suggesting the GNU source-hightlight package. I basically took out each snippet of lua code from the latex file, put it into an appropriately named [snippet].lua file and ran the following on it to generate a [snippet]-lua.tex :

source-highlight -s lua -f latex -i [snippet].lua -o [snippet]-lua.tex

And then I included each such file into the main latex file using :

\input{[snippet]-lua}

The result really isn't as nice as that of the minted package, but I am tired of trying to convince the arXiv admin to support minted...

like image 35
Nicholas Leonard Avatar answered Oct 15 '22 09:10

Nicholas Leonard