Code highlighting in LaTeX for Swift

て烟熏妆下的殇ゞ 提交于 2019-12-02 07:22:02

问题


I found some solution with listings or minted to put source code into my LaTeX document but I would like to have Swift code highlighted. Any hints ?


回答1:


Swift works out of the box with minted:

\documentclass{article}
\usepackage{minted}

\begin{document}
\begin{minted}{swift}
    let x = 42
    println("Hello, \(x)!")
\end{minted}
\end{document}

with xelatex -shell-escape x produces

Note, however, that this requires Pygments 2 to be installed.




回答2:


Have a look at the listings package.

While I'm not sure if Swift is already part of the supported languages, adding your own language definition is not that difficult. See e.g. this example.



来源:https://stackoverflow.com/questions/32049024/code-highlighting-in-latex-for-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!