From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Extract source code /with/ captions Date: Sun, 12 Jan 2014 12:19:28 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8fb2073c65858704efc9293f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2OhA-0008Hn-Dn for Emacs-orgmode@gnu.org; Sun, 12 Jan 2014 12:19:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W2Oh8-0008Pe-Se for Emacs-orgmode@gnu.org; Sun, 12 Jan 2014 12:19:32 -0500 Received: from mail-pd0-x235.google.com ([2607:f8b0:400e:c02::235]:32953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2Oh8-0008Pa-Ez for Emacs-orgmode@gnu.org; Sun, 12 Jan 2014 12:19:30 -0500 Received: by mail-pd0-f181.google.com with SMTP id p10so6475923pdj.40 for ; Sun, 12 Jan 2014 09:19:28 -0800 (PST) In-Reply-To: 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: jamshark70@dewdrop-world.net Cc: "Emacs-orgmode@gnu.org" --e89a8fb2073c65858704efc9293f Content-Type: text/plain; charset=ISO-8859-1 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 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 > > --e89a8fb2073c65858704efc9293f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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 r= ight after that block. I do not know how you could get the captions though.=

In the header I have this:
#+LATEX_HEADER: \newcommand{\Launch= Binary}[2]{%
#+LATEX_HEADER:=A0=A0 % #1: layer name,
#+LATEX_HEADER:= =A0=A0 % #2: link text
#+LATEX_HEADER:=A0=A0 \leavevmode%
#+LATEX_HEA= DER:=A0=A0 \pdfstartlink=A0 attr{/C [0.9 0 0] /Border [0 0 2]} user {
#+LATEX_HEADER:=A0=A0=A0=A0 /Subtype /Link
#+LATEX_HEADER:=A0=A0=A0=A0 /= A <<
#+LATEX_HEADER:=A0=A0=A0=A0=A0=A0 /F <<
#+LATEX_HEAD= ER:=A0=A0=A0=A0=A0=A0=A0=A0=A0 /DOS (#1)
#+LATEX_HEADER:=A0=A0=A0=A0=A0= =A0=A0=A0=A0 /Mac (#1)
#+LATEX_HEADER:=A0=A0=A0=A0=A0=A0=A0=A0=A0 /Unix = (#1)
#+LATEX_HEADER:=A0=A0=A0=A0=A0=A0 >>
#+LATEX_HEADER:=A0=A0=A0=A0= =A0=A0 /S /Launch
#+LATEX_HEADER:=A0=A0=A0=A0 >>
#+LATEX_HEADER= :=A0=A0 } #2%
#+LATEX_HEADER:=A0=A0 \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)

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

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

=A0=A0=A0=A0=A0 (format "%s

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

" text fil= ename filename)))

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

maybe that is close to what you want?
=

John

-----------------------------------
J= ohn Kitchin
Associate Professor
Doherty Hall A207F
Department of C= hemical 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 H= arkins <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 fin= d:

// 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


--e89a8fb2073c65858704efc9293f--