ox-latex: support :float nil with caption for minted listings

* lisp/ox-latex.el (org-latex-src-block): Support :float nil with
caption for minted.
(org-latex-listings): Edit docstring to describe this usecase.
* lisp/org.el (org-latex-default-packages-alist): Add “capt-of”
package.

This takes advantage of the capt-of package’s \captionof command,
which allows to insert a caption (with autogenerated number and
\ref-able label) without creating a floating environment.  One example
of where this is useful is in the case of a minted source code listing
that spans more than one page.  (Latex floats can’t be larger than a
page, generally speaking.)

The listings package already handles this case using its own mechanism.
This commit is contained in:
Aaron Ecay 2014-08-23 03:16:11 -04:00
parent a24ac01cd5
commit 200eeb5723
3 changed files with 14 additions and 5 deletions

View File

@ -87,6 +87,9 @@ parameters are now supported: ~:raw~, ~:backend~. Moreover, there are
new parameters specific to some pre-defined translators, e.g.,
~:environment~ and ~:booktabs~ for ~orgtbl-to-latex~. See translators
docstrings (including ~orgtbl-to-generic~) for details.
*** Non-floating minted listings in Latex export
It is not possible to specify =#+attr_latex: :float nil= in conjunction with
source blocks exported by the minted package.
** Miscellaneous
*** File names in links accept are now compatible with URI syntax
Absolute file names can now start with =///= in addition to =/=. E.g.,
@ -140,7 +143,7 @@ So you need to replace
: #+HTML_INCLUDE_STYLE: t
by
by
: #+OPTIONS: :html-include-style t
@ -194,13 +197,13 @@ of the list.
now use =amssymb= symbols by default instead.
*** New functions for paragraph motion
The commands =C-down= and =C-up= now invoke special commands
that use knowledge from the org-elements parser to move the cursor
in a paragraph-like way.
*** New entities in =org-entities.el=
Add support for ell, imath, jmath, varphi, varpi, aleph, gimel, beth,
dalet, cdots, S (§), dag, ddag, colon, therefore, because, triangleq,
leq, geq, lessgtr, lesseqgtr, ll, lll, gg, ggg, prec, preceq,
@ -308,7 +311,7 @@ instructions:
- when updating through ELPA (either from GNU ELPA or from Org ELPA),
you have to install Org's ELPA package in a session where no Org
function has been called already.
When in doubt, run =M-x org-version RET= and see if you have a mixed-up
installation.

View File

@ -4000,6 +4000,7 @@ header, or they will be appended."
("" "marvosym" t)
("" "wasysym" t)
("" "amssymb" t)
("" "capt-of" nil)
("" "hyperref" nil)
"\\tolerance=1000")
"Alist of default packages to be inserted in the header.
@ -4021,6 +4022,7 @@ Org mode to function properly:
- textcomp, marvosymb, wasysym, amssymb: for various symbols used
for interpreting the entities in `org-entities'. You can skip
some of these packages if you don't use any of their symbols.
- capt-of: for captions outside of floats
- hyperref: for cross references
Therefore you should not modify this variable unless you know

View File

@ -2301,7 +2301,11 @@ contextual information."
((eq listings 'minted)
(let* ((caption-str (org-latex--caption/label-string src-block info))
(float-env
(cond ((and (not float) (plist-member attributes :float)) "%s")
(cond ((and (not float) (plist-member attributes :float) caption)
(format "%%s\n%s" (replace-regexp-in-string
"\\\\caption" "\\captionof{listing}"
caption-str t t)))
((and (not float) (plist-member attributes :float)) "%s")
((string= "multicolumn" float)
(format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
caption-str))