问题
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