【问题标题】:Lua syntax highlighting latex for arXiv用于 arXiv 的 Lua 语法高亮乳胶
【发布时间】:2015-11-24 17:03:50
【问题描述】:

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

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

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

【问题讨论】:

标签: pdf lua latex syntax-highlighting


【解决方案1】:

您可以使用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}

【讨论】:

    【解决方案2】:

    好的,lhf 通过建议 GNU source-hightlight 包找到了一个很好的解决方案。我基本上从latex文件中取出lua代码的每个sn-p,将其放入一个适当命名的[snippet].lua文件中,然后在其上运行以下内容以生成[snippet]-lua.tex

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

    然后我使用以下方法将每个此类文件包含到主乳胶文件中:

    \input{[snippet]-lua}

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 2010-10-03
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      相关资源
      最近更新 更多