导出组织模式代码块和具有不同样式的结果

时间:2014-01-08 20:32:12

标签: emacs org-mode beamer org-babel

我正准备使用org-mode和babel进行演示,并希望导出为beamer pdf。

在输出中,源代码和结果具有相同的样式(逐字记录在latex中)。因此很难区分它们。

是否可以导出具有不同样式(最好是不同颜色)的源代码和结果?

非常感谢!

1 个答案:

答案 0 :(得分:17)

您可以使用minted LaTeX包语法突出显示源代码:

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

我在我的init文件中有这个:

(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"))

您可以使用不同颜色主题进行铸造,例如,您可以将此选项放入组织文件中以使用“monokai”:

#+LaTeX_HEADER: \usemintedstyle{monokai}

从pygmentize获取支持的样式列表:

pygmentize -L styles