emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Ecay <aaronecay@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>, emacs-orgmode@gnu.org
Subject: Re: [RFC] [PATCH] ox-latex: support :float no with	caption	for minted listings
Date: Fri, 19 Sep 2014 15:04:14 -0400	[thread overview]
Message-ID: <87mw9vqvo1.fsf@gmail.com> (raw)
In-Reply-To: <87oav5eztu.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]

Hi Nicolas,

2014ko abuztuak 28an, Nicolas Goaziou-ek idatzi zuen:
> 
> Hello,
> 
> Aaron Ecay <aaronecay@gmail.com> 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
IMO.

Thanks,

-- 
Aaron Ecay

[-- Attachment #2: 0001-ox-latex-support-float-nil-with-caption-for-minted-l.patch --]
[-- Type: text/x-diff, Size: 5213 bytes --]

From 15ced3a12b8882292f43eb7351988be4ddf3d63f Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
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”
package.

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
 
 : #+HTML_INCLUDE_STYLE: t
 
-by 
+by
 
 : #+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
 installation.
 
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)
     "\\tolerance=1000")
   "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))
 	       (float-env
-		(cond ((and (not float) (plist-member attributes :float)) "%s")
+		(cond ((and (not float) (plist-member attributes :float) caption)
+		       (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*}"
 			       caption-str))
-- 
2.1.0


  reply	other threads:[~2014-09-19 19:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-23  7:36 [RFC] [PATCH] ox-latex: support :float no with caption for minted listings Aaron Ecay
2014-08-23 19:47 ` Nicolas Goaziou
2014-08-23 20:27   ` Aaron Ecay
2014-08-23 23:56     ` Nicolas Goaziou
2014-08-24  0:44       ` Aaron Ecay
2014-08-24  6:51         ` Nicolas Richard
2014-08-24 19:54         ` Nicolas Goaziou
2014-08-28  5:03           ` Aaron Ecay
2014-08-28  9:19             ` Nicolas Goaziou
2014-09-19 19:04               ` Aaron Ecay [this message]
2014-09-19 20:13                 ` Nicolas Goaziou
2014-09-23  3:09                   ` Aaron Ecay
2014-09-23 19:48                     ` Nicolas Goaziou
2014-09-28  4:07                       ` Aaron Ecay
2014-09-28  7:09                         ` Nicolas Goaziou
2014-09-28 12:00                         ` Rasmus

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=87mw9vqvo1.fsf@gmail.com \
    --to=aaronecay@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /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).