Lua latex highlight syntax for arXiv

I have a latex file that should contain Lua code fragments (for display, not for execution), so I used minted . This requires latex with the latex -shell-escape flag.

I am trying to upload a pdf document to arXiv . The site requires that they be represented as .tex , .sty and .bbl , which they will automatically compile into latex PDF. When I tried to obey arXiv, I found out that they were not able to activate the -shell-escape flag.

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

+5
source share
2 answers

You can set any style you want to embed using listings . The predefined Lua language contains all the keywords and related styles, so you can simply 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} 
+5
source

So lhf found a good solution by proposing GNU source-hightlight . I basically extracted each piece of lua code from the latex file, put it in a file with the corresponding name [snippet].lua and ran the following on it to generate [snippet]-lua.tex :

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

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

\input{[snippet]-lua}

The result is really not as pleasant as the result of the minted package, but I'm tired of trying to convince the arXiv administrator to support the minted ones ...

+3
source

Source: https://habr.com/ru/post/1236724/


All Articles