emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug formatting source code in new latex exporter


From: Nicolas Goaziou
Subject: Re: [O] Bug formatting source code in new latex exporter
Date: Sat, 23 Mar 2013 22:51:23 +0100

Hello,

Rick Frankel <address@hidden> 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
>From 561ac2144f6cfd21f6160a641d999e38f6f47381 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]