我正在使用org-mode和Babel准备一份演示文稿,并希望将其导出为beamer pdf。
在输出中,源代码和结果具有相同的样式(LaTeX中的verbatim)。因此,很难区分它们。
是否可以使用不同的样式(最好是不同的颜色)导出源代码和结果?
非常感谢!
你可以使用LaTeX的minted
包来对源代码进行语法高亮:
C-h v org-latex-listings
...
(setq org-latex-listings 'minted)
causes source code to be exported using the minted package as
opposed to listings. If you want to use minted, you need to add
the minted package to `org-latex-packages-alist', for example
using customize, or with
(require 'ox-latex)
(add-to-list 'org-latex-packages-alist '("" "minted"))
In addition, it is necessary to install pygments
(http://pygments.org), and to configure the variable
`org-latex-pdf-process' so that the -shell-escape option is
passed to pdflatex.
The minted choice has possible repercussions on the preview of
latex fragments (see `org-preview-latex-fragment'). If you run
into previewing problems, please consult
http://orgmode.org/worg/org-tutorials/org-latex-preview.html
我在我的初始化文件中有以下代码:
(require 'ox-latex)
(add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-listings 'minted)
(setq org-latex-pdf-process
'("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
在minted中有不同的颜色主题可以使用,例如您可以将此选项放入组织文件中以使用"monokai":
#+LaTeX_HEADER: \usemintedstyle{monokai}
获取 pygmentize 支持的样式列表:
pygmentize -L styles