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

Yi *_*ang 11 emacs beamer org-mode org-babel

我正在准备使用org-mode和babel的演示文稿,并希望导出到beamer pdf.

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

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

非常感谢!

ste*_*ter 17

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

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
Run Code Online (Sandbox Code Playgroud)

我在我的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"))
Run Code Online (Sandbox Code Playgroud)

您可以使用不同的颜色主题与铸造,例如,您可以将此选项放入您的组织文件以使用"monokai":

#+LaTeX_HEADER: \usemintedstyle{monokai}
Run Code Online (Sandbox Code Playgroud)

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

pygmentize -L样式

  • 非常感谢!我目前需要的语言(Mathematica)由列表包而不是铸造支持.不过,你的答案完全回答了我的上述问题.在Mathematica的情况下,我写了一篇关于如何做到这一点的博客http://cosmosimple.blogspot.co.uk/2014/01/colored-code-in-org-mode-export.html (3认同)