From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Rick Frankel <rick@rickster.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Bug formatting source code in new latex exporter
Date: Sat, 23 Mar 2013 22:51:23 +0100 [thread overview]
Message-ID: <87txo1zsx0.fsf@gmail.com> (raw)
In-Reply-To: <m2y5dgz28e.wl%rick@rickster.com> (Rick Frankel's message of "Thu, 21 Mar 2013 20:50:57 -0400")
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
Hello,
Rick Frankel <rick@rickster.com> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: implement long-listing attribute --]
[-- Type: text/x-patch, Size: 3702 bytes --]
From 561ac2144f6cfd21f6160a641d999e38f6f47381 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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
next prev parent reply other threads:[~2013-03-23 21:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-19 21:11 Bug formatting source code in new latex exporter Rick Frankel
2013-03-21 19:26 ` Nicolas Goaziou
2013-03-22 0:50 ` Rick Frankel
2013-03-23 21:51 ` Nicolas Goaziou [this message]
2013-03-24 23:29 ` Rick Frankel
2013-03-25 21:09 ` Nicolas Goaziou
2013-03-26 12:28 ` Rick Frankel
2013-03-27 14:17 ` Nicolas Goaziou
2013-03-27 22:10 ` Rick Frankel
2013-03-27 22:29 ` Nicolas Goaziou
-- strict thread matches above, loose matches on Subject: below --
2013-03-19 20:59 Rick Frankel
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87txo1zsx0.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=rick@rickster.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).