From: Aaron Ecay <aaronecay@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [RFC] [PATCH] ox-latex: support :float no with caption for minted listings
Date: Sat, 23 Aug 2014 03:36:34 -0400 [thread overview]
Message-ID: <1408779394-11436-1-git-send-email-aaronecay@gmail.com> (raw)
* lisp/ox-latex.el (org-latex-src-block): Support :float no with
caption for minted.
(org-latex-listings): Edit docstring to describe this usecase.
This takes advantage of the caption 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.)
I haven’t done much testing, but the documentation of the listings
package seems to indicate that it already handles this case without
any special arrangement by org.
---
lisp/ox-latex.el | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c14d6dc..e29c6d2 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -727,6 +727,26 @@ using customize, or with
\(require 'ox-latex)
\(add-to-list 'org-latex-packages-alist '(\"\" \"minted\"))
+You can have listings with a caption which nonetheless do not
+float. This is useful in case the source code takes up more than
+a page, in which case trying to float it will also truncate it.
+To achieve this, you should specifying the following attributes
+on the source block:
+
+ #+caption: ...
+ #+attr_latex: :float no
+ #+begin_src
+ ...
+ #+end_src
+
+In this case, if you are using minted you must add the
+\"caption\" latex package to your document:
+
+ \(add-to-list 'org-latex-packages-alist '(\"\" \"caption\"))
+
+The listings package handles this case correctly with no
+additional packages.
+
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
@@ -2301,7 +2321,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 (string= "no" float) caption)
+ (format "%%s\n%s" (replace-regexp-in-string
+ "\\\\caption" "\\captionof{listing}"
+ caption-str t t)))
+ ((string= "no" float) "%s")
((string= "multicolumn" float)
(format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
caption-str))
--
2.0.4
next reply other threads:[~2014-08-23 7:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-23 7:36 Aaron Ecay [this message]
2014-08-23 19:47 ` [RFC] [PATCH] ox-latex: support :float no with caption for minted listings Nicolas Goaziou
2014-08-23 20:27 ` Aaron Ecay
2014-08-23 23:56 ` Nicolas Goaziou
2014-08-24 0:44 ` Aaron Ecay
2014-08-24 6:51 ` Nicolas Richard
2014-08-24 19:54 ` Nicolas Goaziou
2014-08-28 5:03 ` Aaron Ecay
2014-08-28 9:19 ` Nicolas Goaziou
2014-09-19 19:04 ` Aaron Ecay
2014-09-19 20:13 ` Nicolas Goaziou
2014-09-23 3:09 ` Aaron Ecay
2014-09-23 19:48 ` Nicolas Goaziou
2014-09-28 4:07 ` Aaron Ecay
2014-09-28 7:09 ` Nicolas Goaziou
2014-09-28 12:00 ` Rasmus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408779394-11436-1-git-send-email-aaronecay@gmail.com \
--to=aaronecay@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.