【问题标题】:Export org-mode code block and result with different styles以不同样式导出 org-mode 代码块和结果
【发布时间】:2014-01-08 20:32:11
【问题描述】:

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

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

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

非常感谢!

【问题讨论】:

  • 我发现使用listings可以解决问题。我会稍微调整一下样式并回答自己。当然欢迎更多答案,特别是如果有其他方法。

标签: emacs org-mode beamer org-babel


【解决方案1】:

您可以使用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

我的初始化文件中有这个:

(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 中使用不同的颜色主题,例如,您可以将此选项放入您的 org 文件中以使用“monokai”:

#+LaTeX_HEADER: \usemintedstyle{monokai}

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

pygmentize -L styles

【讨论】:

  • 非常感谢!我目前需要的语言(Mathematica)由 Listings 包而不是 minted 支持。不过,您的回答完美地回答了我的上述问题。在 Mathematica 的情况下,我写了一篇关于如何做的博客cosmosimple.blogspot.co.uk/2014/01/…
猜你喜欢
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多