From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Bug formatting source code in new latex exporter Date: Sat, 23 Mar 2013 22:51:23 +0100 Message-ID: <87txo1zsx0.fsf@gmail.com> References: <20130319211125.GA54083@BigDog.local> <87wqt0sget.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:43605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJWLd-0002s4-EK for emacs-orgmode@gnu.org; Sat, 23 Mar 2013 17:51:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UJWLb-0006hK-Tc for emacs-orgmode@gnu.org; Sat, 23 Mar 2013 17:51:33 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:58868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJWLb-0006gx-K7 for emacs-orgmode@gnu.org; Sat, 23 Mar 2013 17:51:31 -0400 Received: by mail-wg0-f44.google.com with SMTP id dr12so1344976wgb.23 for ; Sat, 23 Mar 2013 14:51:30 -0700 (PDT) In-Reply-To: (Rick Frankel's message of "Thu, 21 Mar 2013 20:50:57 -0400") 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: Rick Frankel Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Rick Frankel writes: > The cross reference approach seems clever, but maybe a simpler > approach would simply be to add an ATTR_LaTeX(:longlisting) and leave > it up to the user. That's the most reasonable option, indeed. The following patch implements :long-listing attribute for src-blocks. What do you think? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ox-latex-long-listing-avoids-wrapping-src-blocks-wit.patch Content-Description: implement long-listing attribute >From 561ac2144f6cfd21f6160a641d999e38f6f47381 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 23 Mar 2013 22:10:35 +0100 Subject: [PATCH] ox-latex: :long-listing avoids wrapping src-blocks within floats * lisp/ox-latex.el (org-latex-long-listings): New variable. (org-latex-src-block): Use new variable. --- lisp/ox-latex.el | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 715212b..c743c89 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -95,6 +95,9 @@ ;; Special blocks accept `:options' as attribute. Its value will be ;; appended as-is to the opening string of the environment created. ;; +;; Source blocks accept `:long-listing' attribute, which prevents the +;; block to be wrapped within a float when non-nil. +;; ;; This back-end also offers enhanced support for footnotes. Thus, it ;; handles nested footnotes, footnotes in tables and footnotes in item ;; descriptions. @@ -831,6 +834,20 @@ options will be applied to blocks of all languages." (string :tag "Minted option name ") (string :tag "Minted option value")))) +(defcustom org-latex-long-listings nil + "When non-nil no listing will be wrapped within a float. + +Removing floats may break some functionalities. For example, it +will be impossible to use cross-references to listings when using +`minted' set-up when this variable is non-nil. + +This value can be locally ignored with \":long-listing t\" and +\":long-listing nil\" LaTeX attributes." + :group 'org-export-latex + :version "24.4" + :package-version '(Org . "8.0") + :type 'boolean) + (defvar org-latex-custom-lang-environments nil "Alist mapping languages to language-specific LaTeX environments. @@ -2156,16 +2173,23 @@ contextual information." (num-start (case (org-element-property :number-lines src-block) (continued (org-export-get-loc src-block info)) (new 0))) - (retain-labels (org-element-property :retain-labels src-block))) + (retain-labels (org-element-property :retain-labels src-block)) + (long-listing + (let ((attr (org-export-read-attribute :attr_latex src-block))) + (if (plist-member attr :long-listing) + (plist-get attr :long-listing) + org-latex-long-listings)))) (cond ;; Case 1. No source fontification. ((not org-latex-listings) - (let ((caption-str (org-latex--caption/label-string src-block info)) - (float-env (and caption "\\begin{figure}[H]\n%s\n\\end{figure}"))) + (let* ((caption-str (org-latex--caption/label-string src-block info)) + (float-env (and (not long-listing) + (or label caption) + (format "\\begin{figure}[H]\n%s%%s\n\\end{figure}" + caption-str)))) (format (or float-env "%s") - (concat caption-str - (format "\\begin{verbatim}\n%s\\end{verbatim}" + (concat (format "\\begin{verbatim}\n%s\\end{verbatim}" (org-export-format-code-default src-block info)))))) ;; Case 2. Custom environment. (custom-env (format "\\begin{%s}\n%s\\end{%s}\n" @@ -2175,9 +2199,10 @@ contextual information." ;; Case 3. Use minted package. ((eq org-latex-listings 'minted) (let ((float-env - (when (or label caption) - (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}" - (org-latex--caption/label-string src-block info)))) + (and (not long-listing) + (or label caption) + (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}" + (org-latex--caption/label-string src-block info)))) (body (format "\\begin{minted}[%s]{%s}\n%s\\end{minted}" -- 1.8.2 --=-=-=--