From: Nicolas Goaziou <n.goaziou@gmail.com>
To: jamshark70@dewdrop-world.net
Cc: "Emacs-orgmode@gnu.org" <Emacs-orgmode@gnu.org>,
"Thomas S. Dye" <tsd@tsdye.com>
Subject: Re: Exporting source code blocks as LaTeX figures
Date: Mon, 20 May 2013 10:54:33 +0200 [thread overview]
Message-ID: <8738tic9py.fsf@gmail.com> (raw)
In-Reply-To: <CAFniQ7W96oN6HF3dVo2hMJgmaMbc+1d+MofjWfGYs78r-w5Nnw@mail.gmail.com> (James Harkins's message of "Mon, 20 May 2013 15:00:53 +0800")
[-- Attachment #1: Type: text/plain, Size: 959 bytes --]
Hello,
James Harkins <jamshark70@gmail.com> writes:
> The other reference to multicolumn is for table export, and this isn't
> a table either. So I think, as currently designed, :multicolumn simply
> doesn't apply.
Correct. The first attached patch implements :float multicolumn
and :float figure handling for source blocks. Would you mind to test it?
> I'm aware that BEGIN_figure delimits a "special block" which
> translates into LaTeX as an arbitrary environment, and not all
> environments can be floated safely... but perhaps one approach for the
> future would be to consider BEGIN_figure to be an extra-special
> "special block" where we know that the properties of LaTeX floating
> bodies are valid.
The second patch introduces :starred attribute for special blocks in
latex back-end, e.g.,
#+attr_latex: :starred t :options [b]
#+begin_figure
something
#+end_figure
I think it could be useful. Do you?
Regards,
--
Nicolas Goaziou
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Implement-float-attribute-for-source-blocks.patch --]
[-- Type: text/x-patch, Size: 6721 bytes --]
From cbc4a3a0b98cab9455bd7d3bd8b0ea8bfe8ea34e Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Mon, 20 May 2013 10:43:18 +0200
Subject: [PATCH 1/2] ox-latex: Implement :float attribute for source blocks
* lisp/ox-latex.el (org-latex-src-block): Handle :float attribute. Its
value can be set to "figure", "multicolumn" or "nil".
This needs to be documented in Org manual.
---
lisp/ox-latex.el | 142 +++++++++++++++++++++++++++++++------------------------
1 file changed, 80 insertions(+), 62 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 41cf1d0..669c84b 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2073,21 +2073,27 @@ contextual information."
(continued (org-export-get-loc src-block info))
(new 0)))
(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))))
+ (attributes (org-export-read-attribute :attr_latex src-block))
+ (long-listing (if (plist-member attributes :long-listing)
+ (plist-get attributes :long-listing)
+ org-latex-long-listings))
+ (float (plist-get attributes :float)))
(cond
;; Case 1. No source fontification.
((not org-latex-listings)
(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))))
+ (float-env
+ (cond (long-listing "%s")
+ ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%%s\n\\end{figure*}"
+ org-latex-default-figure-position
+ caption-str))
+ ((or label caption (string= "figure" float))
+ (format "\\begin{figure}[H]\n%s%%s\n\\end{figure}"
+ caption-str))
+ (t "%s"))))
(format
- (or float-env "%s")
+ float-env
(concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
(org-export-format-code-default src-block info))))))
;; Case 2. Custom environment.
@@ -2097,46 +2103,52 @@ contextual information."
custom-env))
;; Case 3. Use minted package.
((eq org-latex-listings 'minted)
- (let ((float-env
- (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}"
- ;; Options.
- (org-latex--make-option-string
- (if (or (not num-start)
- (assoc "linenos" org-latex-minted-options))
- org-latex-minted-options
- (append `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- org-latex-minted-options)))
- ;; Language.
- (or (cadr (assq (intern lang) org-latex-minted-langs)) lang)
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (float-env
+ (cond (long-listing "%s")
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
+ caption-str))
+ ((or label caption (string= "figure" float))
+ (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
+ caption-str))
+ (t "%s")))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (org-latex--make-option-string
+ (if (or (not num-start)
+ (assoc "linenos" org-latex-minted-options))
+ org-latex-minted-options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ org-latex-minted-options)))
+ ;; Language.
+ (or (cadr (assq (intern lang) org-latex-minted-langs)) lang)
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
;; Return value.
- (if float-env (format float-env body) body)))
+ (format float-env body)))
;; Case 4. Use listings package.
(t
(let ((lst-lang
@@ -2152,19 +2164,25 @@ contextual information."
(org-export-data main info)))))))
(concat
;; Options.
- (format "\\lstset{%s}\n"
- (org-latex--make-option-string
- (append
- org-latex-listings-options
- `(("language" ,lst-lang))
- (when label `(("label" ,label)))
- (when caption-str `(("caption" ,caption-str)))
- (cond ((assoc "numbers" org-latex-listings-options) nil)
- ((not num-start) '(("numbers" "none")))
- ((zerop num-start) '(("numbers" "left")))
- (t `(("numbers" "left")
- ("firstnumber"
- ,(number-to-string (1+ num-start)))))))))
+ (format
+ "\\lstset{%s}\n"
+ (org-latex--make-option-string
+ (append
+ org-latex-listings-options
+ (cond
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and (string= "figure" float)
+ (not (assoc "float" org-latex-listings-options)))
+ `(("float" ,org-latex-default-figure-position))))
+ `(("language" ,lst-lang))
+ (when label `(("label" ,label)))
+ (when caption-str `(("caption" ,caption-str)))
+ (cond ((assoc "numbers" org-latex-listings-options) nil)
+ ((not num-start) '(("numbers" "none")))
+ ((zerop num-start) '(("numbers" "left")))
+ (t `(("numbers" "left")
+ ("firstnumber"
+ ,(number-to-string (1+ num-start)))))))))
;; Source code.
(format
"\\begin{lstlisting}\n%s\\end{lstlisting}"
--
1.8.2.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Implement-starred-attribute-for-special-blo.patch --]
[-- Type: text/x-patch, Size: 1613 bytes --]
From 814edb94ffc45c0d1734e42805d8ede33ad81f67 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Mon, 20 May 2013 10:44:44 +0200
Subject: [PATCH 2/2] ox-latex: Implement :starred attribute for special blocks
* lisp/ox-latex.el (org-latex-special-block): Implement :starred
attribute for special blocks.
---
lisp/ox-latex.el | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 669c84b..ab5c062 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2045,15 +2045,17 @@ holding contextual information."
"Transcode a SPECIAL-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
- (let ((type (downcase (org-element-property :type special-block)))
- (opt (org-export-read-attribute :attr_latex special-block :options)))
- (concat (format "\\begin{%s}%s\n" type (or opt ""))
+ (let* ((type (downcase (org-element-property :type special-block)))
+ (attributes (org-export-read-attribute :attr_latex special-block))
+ (opt (plist-get attributes :options))
+ (starredp (plist-get attributes :starred)))
+ (concat (format "\\begin{%s%s}%s\n" type (if starredp "*" "") (or opt ""))
;; Insert any label or caption within the block
;; (otherwise, a reference pointing to that element will
;; count the section instead).
(org-latex--caption/label-string special-block info)
contents
- (format "\\end{%s}" type))))
+ (format "\\end{%s%s}" type (if starredp "*" "")))))
;;;; Src Block
--
1.8.2.3
next prev parent reply other threads:[~2013-05-20 8:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-17 7:14 Exporting source code blocks as LaTeX figures James Harkins
2013-05-18 7:39 ` Nicolas Goaziou
2013-05-20 4:06 ` James Harkins
2013-05-20 6:30 ` Thomas S. Dye
2013-05-20 7:00 ` James Harkins
2013-05-20 8:54 ` Nicolas Goaziou [this message]
2013-05-21 0:13 ` James Harkins
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=8738tic9py.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=Emacs-orgmode@gnu.org \
--cc=jamshark70@dewdrop-world.net \
--cc=tsd@tsdye.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).