all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Charles Berry <ccberry@ucsd.edu>
To: emacs-orgmode@gnu.org
Subject: Re: LaTeX export with Code
Date: Mon, 7 Oct 2013 16:20:06 +0000 (UTC)	[thread overview]
Message-ID: <loom.20131007T175358-771@post.gmane.org> (raw)
In-Reply-To: 878uy6kr17.fsf@wall.flintfam.org

Sam Flint <swflint <at> flintfam.org> writes:

> 
> I regularly use org-mode for LP, and would like to be able to export the
> name of a code chunk as a caption in LaTeX.  I have looked at the
> manual, and don't see any way of doing this, are there?


Yes. Quite a few.

If you want is the src block name to be used as the caption, 
you can put this line:

#+CAPTION: use-name-as-caption

before the named src block

and execute this code before you export:

#+BEGIN_SRC emacs-lisp 
  (defun org-export-use-name-as-caption 
  (text &optional back-end info)
  "Use the block name as the caption."
  (replace-regexp-in-string 
   "label{\\([^}]*\\)}\\(use-name-as-caption\\)"
   "label{\\1}\\1"
   text))
  
  (add-to-list 'org-export-filter-src-block-functions 
               'org-export-use-name-as-caption) 
#+END_SRC


Then when you export this

#+CAPTION: use-name-as-caption
#+NAME: y-plus-z-becomes-x
#+BEGIN_SRC R
x <- y+z
#+END_SRC

the result is 


\begin{figure}[H]
\begin{verbatim}
x <- y+z
\end{verbatim}\caption{\label{y-plus-z-becomes-x}y-plus-z-becomes-x}

\end{figure}

HTH,

Chuck

      reply	other threads:[~2013-10-07 16:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-06 21:50 LaTeX export with Code Sam Flint
2013-10-07 16:20 ` Charles Berry [this message]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20131007T175358-771@post.gmane.org \
    --to=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.