Lua arXiv 的语法高亮胶乳

Lua syntax highlighting latex for arXiv

我有一个乳胶文件,需要包含 Lua 代码片段(用于显示,而不是执行),所以我使用了 minted 包。它要求乳胶是 运行 和 latex -shell-escape 标志。

我正在尝试将 PDF 提交上传至 arXiv。该站点要求将这些提交为 .tex.sty.bbl,它们将自动从 Latex 编译为 PDF。当我尝试提交给 arXiv 时,我了解到他们无法激活 -shell-escape 标志。

所以我想知道你们中是否有人知道在没有 -shell-escape 标志的情况下在乳胶中突出显示 Lua 代码的方法。我尝试了 listings 包,但我无法在我的 Ubuntu 计算机上为 Lua 工作。

好的 lhf found a good solution by suggesting the GNU source-hightlight 包。我基本上从 latex 文件中取出了 lua 代码的每个片段,将其放入适当命名的 [snippet].lua 文件中,然后 运行 下面的内容生成 [snippet]-lua.tex :

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

然后我使用 :

将每个这样的文件包含到主乳胶文件中

\input{[snippet]-lua}

结果确实不如 minted 包好,但我已经厌倦了试图说服 arXiv 管理员支持 minted...

您可以使用 listings 设置您想要内嵌的任何样式。它是预定义的 Lua 语言已识别所有关键字和相关样式,因此您可以根据需要更改它:

\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}