[Top][All Lists]

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

Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minte

From: Aaron Ecay
Subject: Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings
Date: Fri, 19 Sep 2014 15:04:14 -0400
User-agent: Notmuch/0.18.1+51~gbbbdf04 (http://notmuchmail.org) Emacs/ (x86_64-unknown-linux-gnu)

Hi Nicolas,

2014ko abuztuak 28an, Nicolas Goaziou-ek idatzi zuen:
> Hello,
> Aaron Ecay <address@hidden> writes:
>> The other application I can think of is to allow captioned images and
>> tables not to float.  The LaTeX world is full of tutorials on how to
>> un-float floating images and tables, but IME the org community doesn’t
>> ask for this.  (perhaps they implement their own solutions in latex.)
>> Given that the capt-of package is just two lines of code, defines just
>> one new command, and doesn’t modify any existing code, I’m inclined to
>> the belief that adding it to the default packages list is tolerable.
>> If capt-of is added to the default packages, then <caption, non-float,
>> org-latex-listing = nil> source blocks can also be handled.  
> I agree. Do you want to take care of this? This requires an entry in
> ORG-NEWS and some documentation changes too.

See the attached patch.  I updated ORG-NEWS, but the manual
(info "(org) LaTeX specific attributes") is already sufficiently general


Aaron Ecay
>From 15ced3a12b8882292f43eb7351988be4ddf3d63f Mon Sep 17 00:00:00 2001
From: Aaron Ecay <address@hidden>
Date: Sat, 23 Aug 2014 03:16:11 -0400
Subject: [PATCH] ox-latex: support :float nil with caption for minted listings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/ox-latex.el (org-latex-src-block): Support :float nil with
caption for minted.
(org-latex-listings): Edit docstring to describe this usecase.
* lisp/org.el (org-latex-default-packages-alist): Add “capt-of”

This takes advantage of the capt-of 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.)

The listings package handles this case using its own mechanism.
 etc/ORG-NEWS     | 11 +++++++----
 lisp/org.el      |  2 ++
 lisp/ox-latex.el | 18 +++++++++++++++++-
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 62181cb..08f813b 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -84,6 +84,9 @@ parameters are now supported: ~:raw~, ~:backend~.  Moreover, 
there are
 new parameters specific to some pre-defined translators, e.g.,
 ~:environment~ and ~:booktabs~ for ~orgtbl-to-latex~.  See translators
 docstrings (including ~orgtbl-to-generic~) for details.
+*** Non-floating minted listings in Latex export
+It is not possible to specify =#+attr_latex: :float nil= in conjunction with
+source blocks exported by the minted package.
 ** Miscellaneous
 *** File names in links accept are now compatible with URI syntax
 Absolute file names can now start with =///= in addition to =/=. E.g.,
@@ -137,7 +140,7 @@ So you need to replace
 : #+OPTIONS: :html-include-style t
@@ -191,13 +194,13 @@ of the list.
   now use =amssymb= symbols by default instead.
 *** New functions for paragraph motion
     The commands =C-down= and =C-up= now invoke special commands
     that use knowledge from the org-elements parser to move the cursor
     in a paragraph-like way.
 *** New entities in =org-entities.el=
 Add support for ell, imath, jmath, varphi, varpi, aleph, gimel, beth,
 dalet, cdots, S (§), dag, ddag, colon, therefore, because, triangleq,
 leq, geq, lessgtr, lesseqgtr, ll, lll, gg, ggg, prec, preceq,
@@ -305,7 +308,7 @@ instructions:
 - when updating through ELPA (either from GNU ELPA or from Org ELPA),
   you have to install Org's ELPA package in a session where no Org
   function has been called already.
 When in doubt, run =M-x org-version RET= and see if you have a mixed-up
diff --git a/lisp/org.el b/lisp/org.el
index cd57ec7..1f023be 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4000,6 +4000,7 @@ header, or they will be appended."
     (""     "marvosym"  t)
     (""     "wasysym"   t)
     (""     "amssymb"   t)
+    (""     "capt-of"   nil)
     (""     "hyperref"  nil)
   "Alist of default packages to be inserted in the header.
@@ -4021,6 +4022,7 @@ Org mode to function properly:
 - textcomp, marvosymb, wasysym, amssymb: for various symbols used
   for interpreting the entities in `org-entities'.  You can skip
   some of these packages if you don't use any of their symbols.
+- capt-of: for captions on `:float nil' source blocks
 - hyperref: for cross references
 Therefore you should not modify this variable unless you know
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f59d6b2..5d0a31c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -725,6 +725,18 @@ 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 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
@@ -2300,7 +2312,11 @@ contextual information."
        ((eq listings 'minted)
        (let* ((caption-str (org-latex--caption/label-string src-block info))
-               (cond ((and (not float) (plist-member attributes :float)) "%s")
+               (cond ((and (not float) (plist-member attributes :float) 
+                      (format "%%s\n%s" (replace-regexp-in-string
+                                         "\\\\caption" "\\captionof{listing}"
+                                         caption-str t t)))
+                     ((and (not float) (plist-member attributes :float)) "%s")
                      ((string= "multicolumn" float)
                       (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"

reply via email to

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