emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* src blocks, listings package and captions
@ 2011-08-24 15:58 Giles Chamberlin
  2011-08-25  7:50 ` Bastien
  2011-08-25 15:11 ` Eric Schulte
  0 siblings, 2 replies; 5+ messages in thread
From: Giles Chamberlin @ 2011-08-24 15:58 UTC (permalink / raw)
  To: emacs-orgmode


I'm using the listings package and org-version 7.4 to generate latex/pdf
output including source snippets.  I'd like to add captions: "Figure 1:
My code" and tried with the following to no avail:

#+caption: My code
#+begin_src clojure
 ;; stuff
#+end_src

Do I have to wrap this in \begin{figure}\caption{} or is there a simpler
way?


-- 
Giles Chamberlin
Engineering Director
Cisco Systems Ltd 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src blocks, listings package and captions
  2011-08-24 15:58 src blocks, listings package and captions Giles Chamberlin
@ 2011-08-25  7:50 ` Bastien
  2011-08-25 15:47   ` Thomas S. Dye
  2011-08-25 15:11 ` Eric Schulte
  1 sibling, 1 reply; 5+ messages in thread
From: Bastien @ 2011-08-25  7:50 UTC (permalink / raw)
  To: Giles Chamberlin; +Cc: emacs-orgmode

Hi Giles,

Giles Chamberlin <giles.chamberlin@cisco.com> writes:

> I'm using the listings package and org-version 7.4 to generate latex/pdf
> output including source snippets.  I'd like to add captions: "Figure 1:
> My code" and tried with the following to no avail:
>
> #+caption: My code
> #+begin_src clojure
>  ;; stuff
> #+end_src
>
> Do I have to wrap this in \begin{figure}\caption{} or is there a simpler
> way?

Since captions make sense for figures, I think you have to wrap this
in \begin{figure}\caption{}.  But maybe there is a way to automatically
wrap source blocks into a caption-aware LaTeX environment -- Eric might
give a more useful answer.

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src blocks, listings package and captions
  2011-08-24 15:58 src blocks, listings package and captions Giles Chamberlin
  2011-08-25  7:50 ` Bastien
@ 2011-08-25 15:11 ` Eric Schulte
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2011-08-25 15:11 UTC (permalink / raw)
  To: Giles Chamberlin; +Cc: emacs-orgmode

Giles Chamberlin <giles.chamberlin@cisco.com> writes:

> I'm using the listings package and org-version 7.4 to generate latex/pdf
> output including source snippets.  I'd like to add captions: "Figure 1:
> My code" and tried with the following to no avail:
>
> #+caption: My code
> #+begin_src clojure
>  ;; stuff
> #+end_src
>
> Do I have to wrap this in \begin{figure}\caption{} or is there a simpler
> way?

Currently code blocks are not wrapped in begin/end{figure} environments
as are links and tables.  I do not know of an easy way to do this aside
from manually inserting the LaTeX using #+LaTeX: lines in the Org-mode
file.  I personally would like to treat code blocks in the same way as
links and tables, but I'm not sure if there is a specific reason we do
not do this currently.

Thanks -- Eric

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src blocks, listings package and captions
  2011-08-25  7:50 ` Bastien
@ 2011-08-25 15:47   ` Thomas S. Dye
  2011-08-31 14:44     ` Giles Chamberlin
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2011-08-25 15:47 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Giles Chamberlin

Bastien <bzg@altern.org> writes:

> Hi Giles,
>
> Giles Chamberlin <giles.chamberlin@cisco.com> writes:
>
>> I'm using the listings package and org-version 7.4 to generate latex/pdf
>> output including source snippets.  I'd like to add captions: "Figure 1:
>> My code" and tried with the following to no avail:
>>
>> #+caption: My code
>> #+begin_src clojure
>>  ;; stuff
>> #+end_src
>>
>> Do I have to wrap this in \begin{figure}\caption{} or is there a simpler
>> way?
>
> Since captions make sense for figures, I think you have to wrap this
> in \begin{figure}\caption{}.  But maybe there is a way to automatically
> wrap source blocks into a caption-aware LaTeX environment -- Eric might
> give a more useful answer.
>
> Thanks,

Aloha Giles,

A caption-aware LaTeX environment is provided by the minted package.
If you use org-special-blocks, then you can wrap your source block in
#+BEGIN_listing ... #+END_listing.  You can get a caption and label by
also including something like this within the special block:

#+LATEX: \caption{The caption.}\label{fig:src_blk}

If you want to stick with the listings package, then you will need to
define a listing environment that mimics what the minted package does.
There are at least two ways to do this in LaTeX (and probably others).
One way is to use the float package and then do something like this:

    {\newfloat{listing}{h}{lol}
    \newcommand\listingscaption{Listing}
    \floatname{listing}{\listingscaption}
    \newcommand\listoflistingscaption{List of Listings}
    \providecommand\listoflistings{\listof{listing}{\listoflistingscaption}}
    \floatplacement{listing}{htb!}

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src blocks, listings package and captions
  2011-08-25 15:47   ` Thomas S. Dye
@ 2011-08-31 14:44     ` Giles Chamberlin
  0 siblings, 0 replies; 5+ messages in thread
From: Giles Chamberlin @ 2011-08-31 14:44 UTC (permalink / raw)
  To: emacs-orgmode

tsd@tsdye.com (Thomas S. Dye) writes:

> A caption-aware LaTeX environment is provided by the minted package.

Thanks to Eric, Bastien and Thomas for their help.  I've switched from
listings to minted as I wasn't particularly wed to either and have
successfully implemented Thomas' suggestions.  

Apologies for the delay in responding: I've been in the mountains with
no connection to the world: bliss!

-- 
Giles Chamberlin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-08-31 14:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-24 15:58 src blocks, listings package and captions Giles Chamberlin
2011-08-25  7:50 ` Bastien
2011-08-25 15:47   ` Thomas S. Dye
2011-08-31 14:44     ` Giles Chamberlin
2011-08-25 15:11 ` Eric Schulte

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).