13.10.8 Source blocks in LaTeX export

The LaTeX export back-end can make source code blocks into floating objects through the attributes ‘:float’ and ‘:options’. For ‘:float’:

t

Makes a source block float; by default floats any source block with a caption.

multicolumn

Spans the source block across multiple columns of a page.

nil

Avoids a ‘:float’ even if using a caption; useful for source code blocks that may not fit on a page.

#+ATTR_LATEX: :float nil
#+BEGIN_SRC emacs-lisp
  Lisp code that may not fit in a single page.
#+END_SRC

The LaTeX export back-end passes string values in ‘:options’ to LaTeX packages for customization of that specific source block. In the example below, the ‘:options’ are set for Engraved or Minted. Minted is a source code highlighting LaTeX package with many configurable options134. Both Minted and Engraved are built on fvextra, and so support many of the same options.

#+ATTR_LATEX: :options mathescape
#+BEGIN_SRC emacs-lisp
  (defun Fib (n) ; $n_i = n_{i-2} + n_{i-1}$
    (if (< n 2) n (+ (Fib (- n 1)) (Fib (- n 2)))))
#+END_SRC

To apply similar configuration options for all source blocks in a file, use the org-latex-listings-options, org-latex-engraved-options, and org-latex-minted-options variables.


Footnotes

(134)

Minted uses an external Python package for code highlighting, which requires the flag ‘-shell-escape’ to be added to org-latex-pdf-process.