all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: jamshark70@dewdrop-world.net
Cc: "Emacs-orgmode@gnu.org" <Emacs-orgmode@gnu.org>
Subject: Re: Extract source code /with/ captions
Date: Sun, 12 Jan 2014 12:19:28 -0500	[thread overview]
Message-ID: <CAJ51ETp3sjLaCXecpNJmiN7vtcqK5i5SEuZbzazPZgq3mbcnLw@mail.gmail.com> (raw)
In-Reply-To: <CAFniQ7Xxr53ZojH+VJrHoQeg0F473c2TjA9BOXva5C_j8SF04Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3368 bytes --]

I think I have done something like that before. What I did was make it so
each code block would be written out to a file, e.g.
course-notes/script-%d.py and a link would be put in the exported pdf right
after that block. I do not know how you could get the captions though.

In the header I have this:
#+LATEX_HEADER: \newcommand{\LaunchBinary}[2]{%
#+LATEX_HEADER:   % #1: layer name,
#+LATEX_HEADER:   % #2: link text
#+LATEX_HEADER:   \leavevmode%
#+LATEX_HEADER:   \pdfstartlink  attr{/C [0.9 0 0] /Border [0 0 2]} user {
#+LATEX_HEADER:     /Subtype /Link
#+LATEX_HEADER:     /A <<
#+LATEX_HEADER:       /F <<
#+LATEX_HEADER:          /DOS (#1)
#+LATEX_HEADER:          /Mac (#1)
#+LATEX_HEADER:          /Unix (#1)
#+LATEX_HEADER:       >>
#+LATEX_HEADER:       /S /Launch
#+LATEX_HEADER:     >>
#+LATEX_HEADER:   } #2%
#+LATEX_HEADER:   \pdfendlink%
#+LATEX_HEADER: }

Then this code for the export. (I pasted it from my build file, so there
may be an extra parenthesis at the end)

(setq counter 0)

  (defun ox-mrkup-filter-src-block (text back-end info)
    (setq counter (+ counter 1))

    (let ((filename (format "course-notes-scripts/script-%d.py" counter)))
      (with-temp-buffer
        (insert (mapconcat 'identity (butlast (cdr (split-string text "\n"
t))) "\n"))
        (write-region (point-min) (point-max) filename))

      (format "%s

\\LaunchBinary{%s}{Open the python script (%s).}

" text filename filename)))

(let ((org-export-filter-src-block-functions '(ox-mrkup-filter-src-block)))
  (org-latex-export-to-latex async subtreep visible-only body-only
                 '(:with-author t
                                            :with-date t
                                            :with-title t
                                            :with-timestamps t
                                            :with-todo-keywords t
                                            :with-toc nil))))

maybe that is close to what you want?

John

-----------------------------------
John Kitchin
Associate Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu



On Sun, Jan 12, 2014 at 9:49 AM, James Harkins <jamshark70@gmail.com> wrote:

> I'm working on a set of Beamer presentations with a bunch of source
> code blocks. I would like to collect all the blocks into one text file
> per presentation, but I also need the captions and ideally a numeric
> index.
>
> That is, I'm *not* looking for the normal behavior of
> org-babel-tangle, which assembles only the source code itself without
> any other identifying information (on the assumption that the tangled
> file should be OK to be compiled). These code blocks are not part of
> one big program. They are examples that workshop participants should
> run interactively.
>
> So, for instance, where the slideshow and handouts would have a code
> block identified like so:
>
> Listing 3: Compare geometric vs. band-limited waves, aurally.
>
> ... a student should be able to open up the corresponding code file and
> find:
>
> // Listing 3: Compare geometric vs. band-limited waves, aurally.
>
> Just wondering if anyone has done this. If not, I'm sure I can hack
> something up but it would save some time if somebody has some code
> lying around.
>
> Thanks in advance --
> hjh
>
>

[-- Attachment #2: Type: text/html, Size: 4214 bytes --]

  reply	other threads:[~2014-01-12 17:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-12 14:49 Extract source code /with/ captions James Harkins
2014-01-12 17:19 ` John Kitchin [this message]
2014-01-13  2:52   ` James Harkins
2014-01-13 17:06     ` Nick Dokos
2014-01-13 17:46       ` Nick Dokos
2014-01-13 18:01       ` Nick Dokos
2014-01-18  2:20         ` James Harkins
2014-01-18  3:04           ` James Harkins
2014-01-12 18:34 ` Charles Berry

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=CAJ51ETp3sjLaCXecpNJmiN7vtcqK5i5SEuZbzazPZgq3mbcnLw@mail.gmail.com \
    --to=jkitchin@andrew.cmu.edu \
    --cc=Emacs-orgmode@gnu.org \
    --cc=jamshark70@dewdrop-world.net \
    /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.