From mboxrd@z Thu Jan 1 00:00:00 1970 From: tsd@tsdye.com (Thomas S. Dye) Subject: Re: src blocks, listings package and captions Date: Thu, 25 Aug 2011 05:47:42 -1000 Message-ID: References: <87ei0ac4ko.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([140.186.70.92]:43113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qwc9q-0008Cr-9Z for emacs-orgmode@gnu.org; Thu, 25 Aug 2011 11:47:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qwc9o-0000TO-Dp for emacs-orgmode@gnu.org; Thu, 25 Aug 2011 11:47:54 -0400 Received: from oproxy3-pub.bluehost.com ([69.89.21.8]:54483) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Qwc9o-0000Qf-6Y for emacs-orgmode@gnu.org; Thu, 25 Aug 2011 11:47:52 -0400 In-Reply-To: <87ei0ac4ko.fsf@gnu.org> (Bastien's message of "Thu, 25 Aug 2011 09:50:47 +0200") 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: Bastien Cc: emacs-orgmode@gnu.org, Giles Chamberlin Bastien writes: > Hi Giles, > > Giles Chamberlin 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