Lua语法突出显示arXiv的乳胶

时间:2015-11-24 17:03:51

标签: pdf lua latex syntax-highlighting

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

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

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

2 个答案:

答案 0 :(得分:5)

您可以使用listings设置内嵌的任何样式。它的预定义Lua语言标识了所有关键字和相关样式,因此您只需更改它以满足您的需求:

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}

答案 1 :(得分:3)

好的,lhf通过建议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}

结果真的不如铸造包装好,但我厌倦了试图说服arXiv管理员支持铸造......