emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Thomas S. Dye" <tsd@tsdye.com>
To: Neilen Marais <nmarais@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: example or source blocks with captions
Date: Wed, 27 Apr 2011 11:21:02 -1000	[thread overview]
Message-ID: <525733B6-041C-462B-A08D-9A841F13ED95@tsdye.com> (raw)
In-Reply-To: <BANLkTikjyCCDRj-rvMtu41Umpd3RL5Avaw@mail.gmail.com>

Aloha Neilen Marais,

A while back I took a stab at an overly ambitious project that I've  
subsequently dropped.  In that project I did manage to establish  
captions that work with org-special-blocks.  What follows is a cut and  
paste job from the bones of the project that might help you solve the  
problem of captioning constructs other than figures and tables.  It  
was aimed primarily at LaTeX export, but I seem to recall that it  
worked for html as well.

All the best,
Tom

This link establishes a caption that works with both LaTeX and html
and can be used to mark blocks that Org-mode doesn't recognize by
default.  Note that you currently have to enter these links by hand
and not with the usual =org-insert-link= function, which doesn't allow
spaces in the =PATH= argument.

#+BEGIN_listing
# <<caption-link-type>>
#+source: define-caption-link
#+begin_src emacs-lisp :exports code
   (org-add-link-type
    "caption" nil
    (lambda (path desc format)
      (cond
       ((eq format 'html)
        (format "<span class=\"caption\">%s</span>" desc))
       ((eq format 'latex)
        (format "\\caption[%s]{%s}" path desc)))))
#+end_src
[[caption:A new caption link type][A new caption link type.]]
# <<fig:caption-link>>
#+END_listing

Block-level markup is accomplished with the help of the
[[latex:package][org-special-blocks]] package.  It is used in this  
file to wrap the
[[latex:progstruct][listing]] environment defined by the  
[[latex:package][minted]] package around a source code
block to get a floating listing in the LaTeX document.  LaTeX will
keep track of floating listings and will also prepare a list of
listings that can be placed between the table of contents and the
first section of the article.  [[latex:classfile][Org-article]] makes  
the [[latex:progstruct][listing]]
environment available with the [[latex:package][listings]] package, as  
well, so this
facility can be used regardless of the package chosen to highlight
syntax and typeset source code listings.

Use a construct like this to wrap the source block in a  
[[latex:progstruct][listing]]
environment.  Typically, you will want to include a figure caption and
a label for cross referencing.  This can be done with a =#+LATEX:= line.

  : #+BEGIN_listing
  :  <source block>
  : #+LATEX: \caption{The caption.}\ref{fig:src_blk}
  : #+END_listing

To use this facility, you'll need to load [[latex:package][org-special- 
blocks]] (Listing
\ref{fig:org-special-blocks}).  This code can go in =.emacs=, or you
can load it for the session by executing the following source code
block with =C-c C-c=.

#+BEGIN_listing
#+source: special-blocks
#+begin_src emacs-lisp :exports code :results silent
   (require 'org-special-blocks)
#+end_src
[[caption:Require org-special-blocks][Require org-special-blocks.]]
# <<fig:org-special-blocks>>
#+END_listing

The [[latex:package][org-special-blocks]] package leaves it up to the  
user to see that
the HTML output is styled correctly.  A line of code like Listing
\ref{fig:css}, or something similar, when added to the  
[[latex:proglang][Org-mode]]
buffer, styles listings by putting a black box around them.

#+BEGIN_listing
#+source: css
#+begin_src org :exports code
  #+STYLE: <style>.listing {margin: 1em; padding: 1em; border: 1px  
solid black}</style>
#+end_src
[[caption:A simple CSS style for listings][A simple CSS style for  
listings.]]
# <<fig:css>>
#+END_listing

On Apr 27, 2011, at 5:57 AM, Neilen Marais wrote:

> Hi,
>
> Is it possible to caption a #+begin_src or #+begin_example block?  
> Doing
>
> #+CAPTION: dipole_analytical_balanis.mac
> #+begin_example
> ....
> #+end_example
>
> doesn't seem to do the trick. I would find this useful to include
> suggested filenames when quoting source on a web page.
>
> Thanks
> Neilen
>

  parent reply	other threads:[~2011-04-27 21:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27 15:57 example or source blocks with captions Neilen Marais
2011-04-27 19:36 ` Sébastien Vauban
2011-04-30  5:00   ` Jambunathan K
2011-04-27 21:21 ` Thomas S. Dye [this message]
2011-04-28  7:46   ` Sébastien Vauban
  -- strict thread matches above, loose matches on Subject: below --
2011-04-30  5:00 Jambunathan K

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=525733B6-041C-462B-A08D-9A841F13ED95@tsdye.com \
    --to=tsd@tsdye.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=nmarais@gmail.com \
    /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).