Question

I am preparing a presentation using org-mode and babel, and want to export to beamer pdf.

In the output, the source code and the results are with the same style (verbatim in latex). Thus it is difficult to distinguish them.

Would it be possible to export source code and results with different styles (preferably different color)?

Thanks a lot!

Was it helpful?

Solution

You could use the minted LaTeX package to syntax highlight the source code:

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

I have this in my init file:

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

There are different color-themes you can use with minted, for example you could put this option into your org file to use "monokai":

#+LaTeX_HEADER: \usemintedstyle{monokai}

to get a list of the supported styles from pygmentize:

pygmentize -L styles

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top