From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: example filter for code blocks? Date: Sun, 29 Sep 2013 20:45:08 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bdca522dae4af04e78f25e7 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQRgo-0000Ok-J8 for emacs-orgmode@gnu.org; Sun, 29 Sep 2013 20:50:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VQRgm-0004d0-IL for emacs-orgmode@gnu.org; Sun, 29 Sep 2013 20:50:18 -0400 Received: from mail-pb0-x231.google.com ([2607:f8b0:400e:c01::231]:57586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQRgl-0004cL-Ms for emacs-orgmode@gnu.org; Sun, 29 Sep 2013 20:50:16 -0400 Received: by mail-pb0-f49.google.com with SMTP id xb4so4852426pbc.22 for ; Sun, 29 Sep 2013 17:50:14 -0700 (PDT) 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: "Thomas S. Dye" Cc: "emacs-orgmode@gnu.org" --047d7bdca522dae4af04e78f25e7 Content-Type: text/plain; charset=ISO-8859-1 indeed, there is specific code for DOS/Mac I think. I grabbed that code from here: http://stackoverflow.com/questions/2341364/link-to-external-application-in-latex-beamer which suggests these options are possible /DOS (xxx) /Unix (xxx) /Mac (#1) I have not tried to see if you can put them all in. Let me know if it works to put them all in. I have some Mac users in my class that might need that! 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, Sep 29, 2013 at 8:33 PM, Thomas S. Dye wrote: > Hi John, > > John Kitchin writes: > > > Hi everyone, > > Thanks for the tips in using export filters for code blocks. I thought I > > would share my current solution. The goal was to export all the code > blocks > > in an org-file to files systematically named part1/script-%d.py where %d > is > > a number. I didnot want to tangle exactly, because I wanted to avoid > naming > > the code block tangle files. > > > > Then, I wanted to insert a pdf link that would open the file, after the > > syntax highlighted code. > > > > I wanted this because it is not convenient to copy and paste the > > syntax-highlighted code into an editor. I teach from the pdf that is > > generated, and it would be convenient to just open the code, edit and > rerun > > to explore solutions. > > > > So, here is the solution: > > > > At the top of my orgfile, I have this definition which creates a pdf > link. > > > > #+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: >> > > #+LATEX_HEADER: /S /Launch > > #+LATEX_HEADER: >> > > #+LATEX_HEADER: } #2% > > #+LATEX_HEADER: \pdfendlink% > > #+LATEX_HEADER: } > > With this in my LaTeX file: > > \LaunchBinary{lkfs-structure.org}{Open the file Org mode file.} > > I get a red boxed link in the pdf output. > > When I click on it, Adobe Reader complains: > > Could not find an application to open the file ' '. > > I can't understand the code for LaunchBinary, but noticed "DOS" and > wondered if the code is somehow dependent on the operating system. > > I'm using a Mac. > > All the best, > Tom > > > > > > > Then, I use the code snippet below to export the file to latex. It is > > stored in a noexport section at the end of the document. basically I set > a > > counter, and wrote a filter function for src blocks. the function > captures > > the lines between the first and last (first is \begin{minted}... and last > > is \end{minted} in this case. I write those lines to a file named > according > > to the counter, and finally insert \LaunchBinary... into the string > > returned by the filter. everything else in this let block is just > > fine-tuning the latex packages, and export behavior. > > > > (let ( > > ;; these packages are loaded in the latex file > > (org-latex-default-packages-alist > > '(("utf8" "inputenc" nil) > > ("T1" "fontenc" nil) > > ("" "fixltx2e" nil) > > ("" "natbib" t) > > ("" "url" t) > > ("" "graphicx" t) > > ("" "textcomp" t) > > ("" "underscore" t) > > ("" "amsmath" t) > > ("version=3" "mhchem" t) > > ("tight,pdftex" "web" nil) > > ("" "exerquiz" nil) > > ("ImplMulti" "dljslib" nil) > > )) > > (async nil) > > (subtreep nil) > > (visible-only nil) > > (body-only nil)) > > > > (setq counter 0) > > > > (defun ox-mrkup-filter-src-block (text back-end info) > > (setq counter (+ counter 1)) > > > > (let ((filename (format "part1-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)))) > > > > > > After building the pdf with pdflatex, I get a link with a red box around > it > > that I can click on, and on my system it opens the python file in the > > python editor I have configured to open the file! > > > > > > Thanks again! > > > > 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 > > Hi everyone, > > Thanks for the tips in using export filters for code blocks. I thought > > I would share my current solution. The goal was to export all the code > > blocks in an org-file to files systematically named part1/script-%d.py > > where %d is a number. I didnot want to tangle exactly, because I > > wanted to avoid naming the code block tangle files. > > > > Then, I wanted to insert a pdf link that would open the file, after > > the syntax highlighted code. > > > > I wanted this because it is not convenient to copy and paste the > > syntax-highlighted code into an editor. I teach from the pdf that is > > generated, and it would be convenient to just open the code, edit and > > rerun to explore solutions. > > > > So, here is the solution: > > > > At the top of my orgfile, I have this definition which creates a pdf > > link. > > > > #+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: >> > > #+LATEX_HEADER: /S /Launch > > #+LATEX_HEADER: >> > > #+LATEX_HEADER: } #2% > > #+LATEX_HEADER: \pdfendlink% > > #+LATEX_HEADER: } > > > > Then, I use the code snippet below to export the file to latex. It is > > stored in a noexport section at the end of the document. basically I > > set a counter, and wrote a filter function for src blocks. the > > function captures the lines between the first and last (first is > > \begin{minted}... and last is \end{minted} in this case. I write those > > lines to a file named according to the counter, and finally insert > > \LaunchBinary... into the string returned by the filter. everything > > else in this let block is just fine-tuning the latex packages, and > > export behavior. > > > > (let ( > > ;; these packages are loaded in the latex file > > (org-latex-default-packages-alist > > '(("utf8" "inputenc" nil) > > ("T1" "fontenc" nil) > > ("" "fixltx2e" nil) > > ("" "natbib" t) > > ("" "url" t) > > ("" "graphicx" t) > > ("" "textcomp" t) > > ("" "underscore" t) > > ("" "amsmath" t) > > ("version=3" "mhchem" t) > > ("tight,pdftex" "web" nil) > > ("" "exerquiz" nil) > > ("ImplMulti" "dljslib" nil) > > )) > > (async nil) > > (subtreep nil) > > (visible-only nil) > > (body-only nil)) > > > > (setq counter 0) > > > > (defun ox-mrkup-filter-src-block (text back-end info) > > (setq counter (+ counter 1)) > > > > (let ((filename (format "part1-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)))) > > > > After building the pdf with pdflatex, I get a link with a red box > > around it that I can click on, and on my system it opens the python > > file in the python editor I have configured to open the file! > > > > Thanks again! > > > > 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 > > > > > > -- > Thomas S. Dye > http://www.tsdye.com > --047d7bdca522dae4af04e78f25e7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
indeed, there is specific code for DOS/Mac I thi= nk.

I grabbed that code from here: ht= tp://stackoverflow.com/questions/2341364/link-to-external-application-in-la= tex-beamer

which suggests these options are possible
         =
/DOS (xxx)
         /Unix (xxx)
         /Mac (#1)

I have not tried to see i=
f you can put them all in. Let me know if it works to put them all in.
<= /code>
I have some Mac users in my class that might need th=
at!


Jo= hn

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

<= /div>

On Sun, Sep 29, 2013 at 8:33 PM, Thomas = S. Dye <tsd@tsdye.com> wrote:
Hi John,

John Kitchin <jkitchin@andrew= .cmu.edu> writes:

> Hi everyone,
> Thanks for =A0the tips in using export filters for code blocks. I thou= ght I
> would share my current solution. The goal was to export all the code b= locks
> in an org-file to files systematically named part1/script-%d.py where = %d is
> a number. I didnot want to tangle exactly, because I wanted to avoid n= aming
> the code block tangle files.
>
> Then, I wanted to insert a pdf link that would open the file, after th= e
> syntax highlighted code.
>
> I wanted this because it is not convenient to copy and paste the
> syntax-highlighted code into an editor. I teach from the pdf that is > generated, and it would be convenient to just open the code, edit and = rerun
> to explore solutions.
>
> So, here is the solution:
>
> At the top of my orgfile, I have this definition which creates a pdf l= ink.
>
> #+LATEX_HEADER: \newcommand{\LaunchBinary}[2]{%
> #+LATEX_HEADER: =A0 % #1: layer name,
> #+LATEX_HEADER: =A0 % #2: link text
> #+LATEX_HEADER: =A0 \leavevmode%
> #+LATEX_HEADER: =A0 \pdfstartlink =A0attr{/C [0.9 0 0] /Border [0 0 2]= } user {
> #+LATEX_HEADER: =A0 =A0 /Subtype /Link
> #+LATEX_HEADER: =A0 =A0 /A <<
> #+LATEX_HEADER: =A0 =A0 =A0 /F <<
> #+LATEX_HEADER: =A0 =A0 =A0 =A0 =A0/DOS (#1)
> #+LATEX_HEADER: =A0 =A0 =A0 >>
> #+LATEX_HEADER: =A0 =A0 =A0 /S /Launch
> #+LATEX_HEADER: =A0 =A0 >>
> #+LATEX_HEADER: =A0 } #2%
> #+LATEX_HEADER: =A0 \pdfendlink%
> #+LATEX_HEADER: }

With this in my LaTeX file:

\LaunchBinary{lkfs-= structure.org}{Open the file Org mode file.}

I get a red boxed link in the pdf output.

When I click on it, Adobe Reader complains:

Could not find an application to open the file ' '.

I can't understand the code for LaunchBinary, but noticed "DOS&quo= t; and
wondered if the code is somehow dependent on the operating system.

I'm using a Mac.

All the best,
Tom

>
>
> Then, I use the code snippet below to export the file to latex. It is<= br> > stored in a noexport section at the end of the document. basically I s= et a
> counter, and wrote a filter function for src blocks. the function capt= ures
> the lines between the first and last (first is \begin{minted}... and l= ast
> is \end{minted} in this case. I write those lines to a file named acco= rding
> to the counter, and finally insert \LaunchBinary... into the string > returned by the filter. everything else in this let block is just
> fine-tuning the latex packages, and export behavior.
>
> (let (
> =A0 =A0 =A0 ;; these packages are loaded in the latex file
> =A0 =A0 =A0 (org-latex-default-packages-alist
> =A0 =A0 =A0 =A0'(("utf8" "inputenc" nil)
> =A0 =A0 =A0("T1" "fontenc" nil)
> =A0 =A0 =A0("" "fixltx2e" nil)
> =A0 =A0 =A0("" "natbib" t)
> =A0 =A0 =A0("" "url" t)
> =A0 =A0 =A0("" "graphicx" t)
> =A0 =A0 =A0 =A0 =A0("" "textcomp" t)
> =A0 =A0 =A0 =A0 =A0("" "underscore" t)
> =A0 =A0 =A0("" "amsmath" t)
> =A0 =A0 =A0 =A0 =A0("version=3D3" "mhchem" t)
> =A0 =A0 =A0 =A0 =A0("tight,pdftex" "web" nil)
> =A0 =A0 =A0 =A0 =A0("" "exerquiz" nil)
> =A0 =A0 =A0 =A0 =A0("ImplMulti" "dljslib" nil)
> =A0 =A0 =A0 =A0 ))
> =A0 =A0 =A0 (async nil)
> =A0 =A0 =A0 (subtreep nil)
> =A0 =A0 =A0 (visible-only nil)
> =A0 =A0 =A0 (body-only nil))
>
> (setq counter 0)
>
> =A0 (defun ox-mrkup-filter-src-block (text back-end info)
> =A0 =A0 (setq counter (+ counter 1))
>
> =A0 =A0 (let ((filename (format "part1-scripts/script-%d.py"= counter)))
> =A0 =A0 =A0 (with-temp-buffer
> =A0 =A0 =A0 =A0 (insert (mapconcat 'identity (butlast (cdr (split-= string text "\n"
> t))) "\n"))
> =A0 =A0 =A0 =A0 (write-region (point-min) (point-max) filename))
>
> =A0 =A0 =A0 (format "%s
>
> \\LaunchBinary{%s}{Open the python script (%s).}
>
> " text filename filename)))
>
> (let ((org-export-filter-src-block-functions '(ox-mrkup-filter-src= -block)))
> =A0 (org-latex-export-to-latex async subtreep visible-only body-only > =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 :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 :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 :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 :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 :with-toc nil))))
>
>
> After building the pdf with pdflatex, I get a link with a red box arou= nd it
> that I can click on, and on my system it opens the python file in the<= br> > python editor I have configured to open the file!
>
>
> Thanks again!
>
> 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
> Hi everyone,
> Thanks for the tips in using export filters for code blocks. I thought=
> I would share my current solution. The goal was to export all the code=
> blocks in an org-file to files systematically named part1/script-%d.py=
> where %d is a number. I didnot want to tangle exactly, because I
> wanted to avoid naming the code block tangle files.
>
> Then, I wanted to insert a pdf link that would open the file, after > the syntax highlighted code.
>
> I wanted this because it is not convenient to copy and paste the
> syntax-highlighted code into an editor. I teach from the pdf that is > generated, and it would be convenient to just open the code, edit and<= br> > rerun to explore solutions.
>
> So, here is the solution:
>
> At the top of my orgfile, I have this definition which creates a pdf > link.
>
> #+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<= br> > {
> #+LATEX_HEADER: /Subtype /Link
> #+LATEX_HEADER: /A <<
> #+LATEX_HEADER: /F <<
> #+LATEX_HEADER: /DOS (#1)
> #+LATEX_HEADER: >>
> #+LATEX_HEADER: /S /Launch
> #+LATEX_HEADER: >>
> #+LATEX_HEADER: } #2%
> #+LATEX_HEADER: \pdfendlink%
> #+LATEX_HEADER: }
>
> Then, I use the code snippet below to export the file to latex. It is<= br> > stored in a noexport section at the end of the document. basically I > set a counter, and wrote a filter function for src blocks. the
> function captures the lines between the first and last (first is
> \begin{minted}... and last is \end{minted} in this case. I write those=
> lines to a file named according to the counter, and finally insert
> \LaunchBinary... into the string returned by the filter. everything > else in this let block is just fine-tuning the latex packages, and
> export behavior.
>
> (let (
> ;; these packages are loaded in the latex file
> (org-latex-default-packages-alist
> '(("utf8" "inputenc" nil)
> ("T1" "fontenc" nil)
> ("" "fixltx2e" nil)
> ("" "natbib" t)
> ("" "url" t)
> ("" "graphicx" t)
> ("" "textcomp" t)
> ("" "underscore" t)
> ("" "amsmath" t)
> ("version=3D3" "mhchem" t)
> ("tight,pdftex" "web" nil)
> ("" "exerquiz" nil)
> ("ImplMulti" "dljslib" nil)
> ))
> (async nil)
> (subtreep nil)
> (visible-only nil)
> (body-only nil))
>
> (setq counter 0)
>
> (defun ox-mrkup-filter-src-block (text back-end info)
> (setq counter (+ counter 1))
>
> (let ((filename (format "part1-scripts/script-%d.py" counter= )))
> (with-temp-buffer
> (insert (mapconcat 'identity (butlast (cdr (split-string text &quo= t;\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))))
>
> After building the pdf with pdflatex, I get a link with a red box
> around it that I can click on, and on my system it opens the python > file in the python editor I have configured to open the file!
>
> Thanks again!
>
> 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
>
>

--
Thomas S. Dye
http://www.tsdye.com=

--047d7bdca522dae4af04e78f25e7--