From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: Re: parameterizing keyword values during a #+call Date: Tue, 30 Apr 2013 14:46:56 -0400 Message-ID: References: <87ehdw53b1.fsf@gmail.com> <11889.1367332802@greg-minshalls-mbp.local> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff1c4aafe547404db986ce2 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:55029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXFZs-0006zz-Mp for emacs-orgmode@gnu.org; Tue, 30 Apr 2013 14:47:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXFZq-0007Vu-OX for emacs-orgmode@gnu.org; Tue, 30 Apr 2013 14:47:00 -0400 Received: from mail-ob0-x233.google.com ([2607:f8b0:4003:c01::233]:65044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXFZq-0007VU-HP for emacs-orgmode@gnu.org; Tue, 30 Apr 2013 14:46:58 -0400 Received: by mail-ob0-f179.google.com with SMTP id oi10so712764obb.24 for ; Tue, 30 Apr 2013 11:46:57 -0700 (PDT) In-Reply-To: <11889.1367332802@greg-minshalls-mbp.local> 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: Orgmode Mailing List --e89a8ff1c4aafe547404db986ce2 Content-Type: text/plain; charset=ISO-8859-1 I've been having the same issue (exporting to HTML and PDF, and need all my graphics filenames to adjust automatically). I mostly don't use #+CALL though; I just have src blocks. #+BEGIN_SRC python :session UDpython :exports results :results file do_hbar('/tmp/machines-by-os.pdf', (8,1.5), data) #+END_SRC Is there any way of interpolating the elisp value into the middle of a src block? I guess I can add another #+HEADER line: #+HEADER: :var filename=(ext "/tmp/machines-by-os") #+BEGIN_SRC python :session UDpython :exports results :results file do_hbar(filename, (8,1.5), data) #+END_SRC Is that the recommended method? Org-mode macros that got expanded in the middle of babel source block text would be cool. Just saying. On Tue, Apr 30, 2013 at 10:40 AM, Greg Minshall wrote: > Eric, > > just for completeness, and in case this may be of use to other people, > below is the result of my question + your suggestions. the following > illustrates org-mode plus asymptote producing a .svg file during html > export, and a pdf file during any other (presumably, latex) export. > > thanks again, Greg > ---- > # trying to get graphics that works for both latex/beamer and for html > > # here's a suggestion from Eric Schulte > # http://article.gmane.org/gmane.emacs.orgmode/71301 > # with this clarification > # http://article.gmane.org/gmane.emacs.orgmode/71393 > # which produced the following > > # we define an emacs lisp macro ext that produces a file extension > # of "svg" or "pdf" depending on whether we are exporting to html or > # to some other source. this macro is called when computing the > # output file name argument in a call to an asymptote routine as in: > # > # #+call: rectangle[:file (ext twod-1)](TSIZE=1.0) :results file > # > # which calls an asymptote routine (defined in our file) called > # rectangle to produce a file called twod-1.svg or twod-1.pdf. > > # define the ext emacs lisp macro (i think in the following you *need* > # ":exports results" -- instead of ":exports none" -- to make sure the > # code is executed during export; the ":results silent" keeps any > # output -- or nil -- from showing up in the output file.) > > #+begin_src emacs-lisp :exports results :results silent > (defmacro ext (base) > (format "%s.%s" base > (if (and (boundp 'backend) (equal backend 'html)) "svg" > "pdf"))) > #+end_src > > > # follows an example use of the above macro > > # first, define a asymptote function (org-named "rectangle") that > # draws a rectangle > #+name: rectangle > #+begin_src asymptote :var TSIZE=1.0 :exports none > import trembling; > size(100); > int off = 2, width = 100, height = 30; > string tsize = format("%g", TSIZE); > tremble tr0=tremble(angle=0); // no trembling > tremble tr10=tremble(angle=10,frequency=0.1,random=50,fuzz=1); > > picture rectangle(pair sw, pair ne, int offset, string text, tremble tr) > { > picture pic; > path g = > > (sw.x+offset,sw.y+offset)--(ne.x-offset,sw.y+offset)--(ne.x-offset,ne.y-offset)--(sw.x+offset,ne.y-offset)--cycle; > label(pic, text, ((sw.x+ne.x)/2, (sw.y+ne.y)/2)); > draw(pic, tr.deform(g)); > return pic; > } > > add(rectangle((0,0),(width,height),0, "", tr0)); > add(rectangle((0,0),(width,height),off, tsize, tr10)); > #+end_src > > # now, invoke the above asymptote function, producing a file called > # either twod-1.svg or twod-1.pdf: > > #+call: rectangle[:file (ext twod-1)](TSIZE=1.0) :results file > > # now, you can C-c C-e l o or C-c C-e h o and see the image in the > # two formats > > # $Id: parameterizing.org,v 1.2 2013/04/30 14:37:29 minshall Exp $ > > -- Gary --e89a8ff1c4aafe547404db986ce2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I've been having the same issue (exporting to HTML and= PDF, and need all my graphics filenames to adjust automatically).

=
I mostly don't use #+CALL though; I just have src blocks.

#+BEGIN_SRC python :session UDpython :exports resu= lts :results file
=A0 do_hbar('/tmp/machines-by-os.pdf= 9;, (8,1.5), data)
#+END_SRC

Is there any way of interpolating the elisp value into the middle of a src = block? =A0I guess I can add another #+HEADER line:

#+HEADER: :var filename=3D(ext "/tmp/machines-b= y-os")
#+BEGIN_SRC python :session UDpython :exports results :results file
=A0 do_hbar(filename, (8,1.5), data)
#+END_SRC
<= /div>

Is that the recommended method?

Org-mode macros that got expanded in the middle of bab= el source block text would be cool. Just saying.

=


On Tue,= Apr 30, 2013 at 10:40 AM, Greg Minshall <minshall@umich.edu> wrote:
Eric,

just for completeness, and in case this may be of use to other people,
below is the result of my question + your suggestions. =A0the following
illustrates org-mode plus asymptote producing a .svg file during html
export, and a pdf file during any other (presumably, latex) export.

thanks again, Greg
----
# trying to get graphics that works for both latex/beamer and for html

# here's a suggestion from Eric Schulte
# http://article.gmane.org/gmane.emacs.orgmode/71301
# with this clarification
# http://article.gmane.org/gmane.emacs.orgmode/71393
# which produced the following

# we define an emacs lisp macro ext that produces a file extension
# of "svg" or "pdf" depending on whether we are exporti= ng to html or
# to some other source. =A0this macro is called when computing the
# output file name argument in a call to an asymptote routine as in:
#
# #+call: rectangle[:file (ext twod-1)](TSIZE=3D1.0) :results file
#
# which calls an asymptote routine (defined in our file) called
# rectangle to produce a file called twod-1.svg or twod-1.pdf.

# define the ext emacs lisp macro (i think in the following you *need*
# ":exports results" -- instead of ":exports none" -- t= o make sure the
# code is executed during export; the ":results silent" keeps any=
# output -- or nil -- from showing up in the output file.)

#+begin_src emacs-lisp :exports results :results silent
=A0 =A0 (defmacro ext (base)
=A0 =A0 =A0 (format "%s.%s" base
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (and (boundp 'backend) (equal backend &= #39;html)) "svg" "pdf")))
#+end_src


# follows an example use of the above macro

# first, define a asymptote function (org-named "rectangle") that=
# draws a rectangle
#+name: rectangle
#+begin_src asymptote :var TSIZE=3D1.0 :exports none
=A0 import trembling;
=A0 size(100);
=A0 int off =3D 2, width =3D 100, height =3D 30;
=A0 string tsize =3D format("%g", TSIZE);
=A0 tremble tr0=3Dtremble(angle=3D0); =A0 // no trembling
=A0 tremble tr10=3Dtremble(angle=3D10,frequency=3D0.1,random=3D50,fuzz=3D1)= ;

=A0 picture rectangle(pair sw, pair ne, int offset, string text, tremble tr= ) {
=A0 =A0 picture pic;
=A0 =A0 path g =3D
=A0 =A0 =A0 (sw.x+offset,sw.y+offset)--(ne.x-offset,sw.y+offset)--(ne.x-off= set,ne.y-offset)--(sw.x+offset,ne.y-offset)--cycle;
=A0 =A0 label(pic, text, ((sw.x+ne.x)/2, (sw.y+ne.y)/2));
=A0 =A0 draw(pic, tr.deform(g));
=A0 =A0 return pic;
=A0 }

=A0 add(rectangle((0,0),(width,height),0, "", tr0));
=A0 add(rectangle((0,0),(width,height),off, tsize, tr10));
#+end_src

# now, invoke the above asymptote function, producing a file called
# either twod-1.svg or twod-1.pdf:

#+call: rectangle[:file (ext twod-1)](TSIZE=3D1.0) :results file

# now, you can C-c C-e l o or C-c C-e h o and see the image in the
# two formats

# $Id: parameterizi= ng.org,v 1.2 2013/04/30 14:37:29 minshall Exp $




--
Gary
--e89a8ff1c4aafe547404db986ce2--