From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: Re: [patch, ox-latex] caption and :float nil Date: Wed, 01 Jul 2015 15:21:39 +0100 Message-ID: <87wpykj6vg.fsf@gmail.com> References: <87twtovkjh.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAItk-0006Fc-F1 for emacs-orgmode@gnu.org; Wed, 01 Jul 2015 10:22:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAItc-0000Cs-6D for emacs-orgmode@gnu.org; Wed, 01 Jul 2015 10:22:00 -0400 Received: from mail-wg0-x22a.google.com ([2a00:1450:400c:c00::22a]:35929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAItb-0000CH-Rz for emacs-orgmode@gnu.org; Wed, 01 Jul 2015 10:21:52 -0400 Received: by wguu7 with SMTP id u7so38287258wgu.3 for ; Wed, 01 Jul 2015 07:21:51 -0700 (PDT) In-Reply-To: <87twtovkjh.fsf@gmx.us> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rasmus Cc: orgmode Hi Rasmus, AFAICS you sent the original message only to me. I=E2=80=99m replying also= to the org mode list. You may want to resend the patch attachment though, since the quoting in this reply will probably mangle it. I have almost no time to follow org development these days (sadly). However these are my brief thoughts. 2015ko uztailak 1an, Rasmus-ek idatzi zuen: >=20 > Hi, >=20 > Attached is a patch that works reasonably well to allow :float nil > "floats" to have captions in ox-latex. >=20 > The hard part is src-blocks. >=20 > At the moment we sometimes allow captions to register as figures (at least > when when using verbatim). Instead we could go with "listing". Of course > listing is not a known environment to LaTeX. We can add register it with > newfloat in default-packages, or we can mention in the manual the lines > that needs to be added to org-latex-packages if desired: >=20 > \usepackage{newfloat} > \DeclareFloatingEnvironment{listing} > I think this should depend on the value of org-latex-listings: nil -> use \captionof{float} t -> use \captionof{listing} minted -> use \captionof{listing} (see below for why) > We could also unconditionally use captionof in case of verbatim output for > src blocks, even if float is required, which would allow us to kill > float.sty from default package alist. >=20 > BTW: In the current code we uses \captionof{listing}{caption} with minted. > This seems incompatible.=20=20 Minted uses listing as its floating environment; see sec. 5 of the minted manual. So this seems correct in fact. > But I have not really used minted so I don't know if I did the > test correctly. minted has a [H] placement through it's listings > environment, it seems, so I don't think we need captionof there. I=E2=80=99m not sure that minted provides this separately from the float package. So it=E2=80=99s probably better to use \captionof in the minted c= ase as well. Certainly it will make things more consistent from org=E2=80=99s = POV. Thanks, Aaron >=20 > Aaron: I think you had something to do with this at some point, hence the= Cc. >=20 > WDYT?=20 >=20 > Rasmus >=20 > Examples: >=20 > #+caption: cap > #+attr_latex: :float nil > |a| >=20 > =E2=87=92 >=20 > \begin{center} > \captionof{table}{cap} > \begin{tabular}{l} > \toprule > a\\ > \bottomrule > \end{tabular} > \end{center} >=20 > (Of course, this is from my normal Emacs session) >=20 >=20 > #+caption: cap > #+attr_latex: :float nil > [[file:org.png]] >=20 > =E2=87=92 >=20 > \begin{center} > \includegraphics{org.png} > \captionof{figure}{cap} > \end{center} >=20 >=20 > #+caption: test > #+attr_latex: :float nil > #+BEGIN_SRC emacs-lisp > (setq org-latex-listings 'minted) > #+END_SRC >=20 > =E2=87=92 [Note, latex is happy with this...] >=20 > % \usepackage{minted} > \begin{minted}[]{common-lisp} > (setq org-latex-listings 'minted) > \end{minted} > \captionof{listing}{test} >=20 >=20 > #+caption: test > #+attr_latex: :float nil > #+BEGIN_SRC emacs-lisp > (setq org-latex-listings nil) > #+END_SRC >=20 > =E2=87=92 [Note, here I think we should use listing instead of figure] >=20 > \begin{verbatim} > (setq org-latex-listings nil) > \end{verbatim} > \captionof{figure}{test} >=20 >=20 > --=20 > Don't panic!!! > From 590390f2e5cf34edcfbb13b18e5c9abc67b98d93 Mon Sep 17 00:00:00 2001 > From: Rasmus > Date: Wed, 1 Jul 2015 01:12:42 +0200 > Subject: [PATCH] ox-latex: Support captions for None-floats >=20 > * ox-latex.el (org-latex--caption/label-string): Format > nonfloating captions using the capt-of package. > (org-latex--inline-image, org-latex-src-block) > (org-latex--org-table): Allow none-float and caption. > --- > etc/ORG-NEWS | 1 + > lisp/ox-latex.el | 68 +++++++++++++++++++++++++++++++++++++++-----------= ------ > 2 files changed, 49 insertions(+), 20 deletions(-) >=20 > diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS > index ea7a2de..9592f88 100644 > --- a/etc/ORG-NEWS > +++ b/etc/ORG-NEWS > @@ -398,6 +398,7 @@ set using the hh:mm:ss format. > ~org-clone-subtree-with-time-shift~ now accepts 0 as an argument for > the number of clones, which removes the repeater from the original > subtree and creates one shifted, repeating clone. > +*** None-floating tables, graphics and blocks can have captions > ** Miscellaneous > *** Strip all meta data from ITEM special property > ITEM special property does not contain TODO, priority or tags anymore. > diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el > index 11fa00d..918949b 100644 > --- a/lisp/ox-latex.el > +++ b/lisp/ox-latex.el > @@ -1109,21 +1109,31 @@ caption nor label, return the empty string. > For non-floats, see `org-latex--wrap-label'." > (let* ((label (org-latex--label element info nil t)) > (main (org-export-get-caption element)) > + (attr (org-export-read-attribute :attr_latex element)) > + (nonfloat (and (member :float attr) > + (not (plist-get attr :float)) > + main)) > (short (org-export-get-caption element t)) > - (caption-from-attr-latex > - (org-export-read-attribute :attr_latex element :caption))) > + (caption-from-attr-latex (plist-get attr :caption))) > (cond > ((org-string-nw-p caption-from-attr-latex) > (concat caption-from-attr-latex "\n")) > ((and (not main) (equal label "")) "") > ((not main) (concat label "\n")) > ;; Option caption format with short name. > - (short (format "\\caption[%s]{%s%s}\n" > - (org-export-data short info) > - label > - (org-export-data main info))) > - ;; Standard caption format. > - (t (format "\\caption{%s%s}\n" label (org-export-data main info))))= )) > + (t > + (format (if nonfloat "\\captionof{%s}%s{%s%s}\n" > + "\\caption%s%s{%s%s}\n") > + (if nonfloat > + (let ((type (org-element-type element))) > + (case type > + (paragraph "figure") > + (src-block "listing") > + (t (symbol-name type)))) > + "") > + (if short (format "[%s]" (org-export-data short info)) "") > + label > + (org-export-data main info)))))) >=20=20 > (defun org-latex-guess-inputenc (header) > "Set the coding system in inputenc to what the buffer is. > @@ -1975,14 +1985,15 @@ used as a communication channel." > ;; Retrieve latex attributes from the element around. > (attr (org-export-read-attribute :attr_latex parent)) > (float (let ((float (plist-get attr :float))) > - (cond ((and (not float) (plist-member attr :float)) nil) > - ((string=3D float "wrap") 'wrap) > + (cond ((string=3D float "wrap") 'wrap) > ((string=3D float "sideways") 'sideways) > ((string=3D float "multicolumn") 'multicolumn) > ((or float > (org-element-property :caption parent) > (org-string-nw-p (plist-get attr :caption))) > - 'figure)))) > + (if (and (member :float attr) (not float)) 'nonfloat > + 'figure)) > + ((and (not float) (plist-member attr :float)) nil)))) > (placement > (let ((place (plist-get attr :placement))) > (cond > @@ -2087,6 +2098,13 @@ used as a communication channel." > (if caption-above-p caption "") > comment-include image-code > (if caption-above-p "" caption))) > + (nonfloat > + (format "\\begin{center}%s > +%s > +%s\\end{center}" > + (if caption-above-p caption "") > + image-code > + (if caption-above-p "" caption))) > (otherwise image-code)))) >=20=20 > (defun org-latex-link (link desc info) > @@ -2501,12 +2519,15 @@ contextual information." > ((not listings) > (let* ((caption-str (org-latex--caption/label-string src-block info)) > (float-env > - (cond ((and (not float) (plist-member attributes :float)) "%s") > - ((string=3D "multicolumn" float) > + (cond ((string=3D "multicolumn" float) > (format "\\begin{figure*}[%s]\n%s%%s\n%s\\end{figure*}" > (plist-get info :latex-default-figure-position) > (if caption-above-p caption-str "") > (if caption-above-p "" caption-str))) > + ((and caption (not float) > + (plist-member attributes :float)) > + (concat "%s\n" > + (replace-regexp-in-string "listing" "figure" caption-str))) > ((or caption float) > (format "\\begin{figure}[H]\n%%s\n%s\\end{figure}" > caption-str)) > @@ -2530,13 +2551,9 @@ contextual information." > (float-env > (cond > ((and (not float) (plist-member attributes :float) caption) > - (let ((caption > - (replace-regexp-in-string > - "\\\\caption" "\\captionof{listing}" caption-str > - t t))) > - (concat (and caption-above-p caption) > - "%%s" > - (and (not caption-above-p) (concat "\n" caption))))) > + (concat (and caption-above-p caption-str) > + "%s" > + (and (not caption-above-p) (concat "\n" caption-str)))) > ((and (not float) (plist-member attributes :float)) "%s") > ((string=3D "multicolumn" float) > (format "\\begin{listing*}\n%s%%s\n%s\\end{listing*}" > @@ -2867,6 +2884,12 @@ This function assumes TABLE has `org' as its `:typ= e' property and > (if caption-above-p caption "") > (when centerp "\\centering\n") > fontsize)) > + ((and (not float-env) caption) > + (concat > + (and centerp "\\begin{center}\n" ) > + (if caption-above-p caption "") > + (cond ((and fontsize centerp) fontsize) > + (fontsize (concat "{" fontsize))))) > (centerp (concat "\\begin{center}\n" fontsize)) > (fontsize (concat "{" fontsize))) > (cond ((equal "tabu" table-env) > @@ -2886,6 +2909,11 @@ This function assumes TABLE has `org' as its `:typ= e' property and > (float-env > (concat (if caption-above-p "" caption) > (format "\n\\end{%s}" float-env))) > + ((and (not float-env) caption) > + (concat > + (if caption-above-p "" caption) > + (and centerp "\n\\end{center}") > + (and fontsize (not centerp) "}"))) > (centerp "\n\\end{center}") > (fontsize "}"))))))) >=20=20 > --=20 > 2.4.4 >=20 >=20 --=20 Aaron Ecay