From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: [RFC] [PATCH] ox-latex: support :float no with caption for minted listings Date: Sat, 23 Aug 2014 03:36:34 -0400 Message-ID: <1408779394-11436-1-git-send-email-aaronecay@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XL5sZ-0006rM-2I for emacs-orgmode@gnu.org; Sat, 23 Aug 2014 03:36:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XL5sT-00060N-25 for emacs-orgmode@gnu.org; Sat, 23 Aug 2014 03:36:50 -0400 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:34539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XL5sS-00060J-Tu for emacs-orgmode@gnu.org; Sat, 23 Aug 2014 03:36:44 -0400 Received: by mail-qg0-f54.google.com with SMTP id j5so8561987qga.27 for ; Sat, 23 Aug 2014 00:36:44 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * 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