emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* parameterizing keyword values during a #+call
@ 2013-04-25 23:45 Greg Minshall
  2013-04-26  1:19 ` Eric Schulte
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Minshall @ 2013-04-25 23:45 UTC (permalink / raw)
  To: emacs-orgmode

hi.  i would have an org file that uses lots of #+calls to various
asymptote routines (babelled into the file) to produce graphics.  i
would like to export this file to both html and to latex (specifically
beamer).  for html, i would like, e.g., SVG files, and for latex, PDF
files.  the file name is normally passed to the asymptote routine via a
:file parameter, to wit
----
#+call: disc[:file images/disc.svg]() :results file
----
and the file extension (".svg" in the above) determines the format of
the asymptote output.

is there an obvious way to allow the file extension to take on different
values depending on which sort of export is driving its execution?  i
had hoped that replacing ".svg" with something like ".{{{ext()}}}",
where "ext" was a macro which selected amongst the alternatives(*),
would do the trick.  but that doesn't appear to be the case.

thanks in advance (and with full appreciation of what a pain macros
are to implement fully, halfly, anyly), Greg Minshall

(*)
#+MACRO: ext @@latex:pdf@@@@beamer:pdf@@@@html:svg@@

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-25 23:45 parameterizing keyword values during a #+call Greg Minshall
@ 2013-04-26  1:19 ` Eric Schulte
  2013-04-26 11:46   ` Greg Minshall
  2013-04-26 22:27   ` Greg Minshall
  0 siblings, 2 replies; 10+ messages in thread
From: Eric Schulte @ 2013-04-26  1:19 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Greg Minshall <minshall@umich.edu> writes:

> hi.  i would have an org file that uses lots of #+calls to various
> asymptote routines (babelled into the file) to produce graphics.  i
> would like to export this file to both html and to latex (specifically
> beamer).  for html, i would like, e.g., SVG files, and for latex, PDF
> files.  the file name is normally passed to the asymptote routine via a
> :file parameter, to wit
> ----
> #+call: disc[:file images/disc.svg]() :results file
> ----
> and the file extension (".svg" in the above) determines the format of
> the asymptote output.
>
> is there an obvious way to allow the file extension to take on different
> values depending on which sort of export is driving its execution?  i
> had hoped that replacing ".svg" with something like ".{{{ext()}}}",
> where "ext" was a macro which selected amongst the alternatives(*),
> would do the trick.  but that doesn't appear to be the case.
>

Something like the following should work.

#+call: disc[:file (if (and (boundp org-export-current-backend) (equal org-export-current-backend 'html)) "foo.svg" "foo.tex")]() :results file

And you could wrap up the extra-long Emacs-lisp in a function or macro
in your init to avoid the overlength header argument.

>
> thanks in advance (and with full appreciation of what a pain macros
> are to implement fully, halfly, anyly), Greg Minshall
>
> (*)
> #+MACRO: ext @@latex:pdf@@@@beamer:pdf@@@@html:svg@@
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-26  1:19 ` Eric Schulte
@ 2013-04-26 11:46   ` Greg Minshall
  2013-04-26 22:27   ` Greg Minshall
  1 sibling, 0 replies; 10+ messages in thread
From: Greg Minshall @ 2013-04-26 11:46 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Eric,

thanks!

> Something like the following should work.
>
> #+call: disc[:file (if (and (boundp org-export-current-backend) (equal org-export-current-backend 'html)) "foo.svg" "foo.tex")]() :results file

in fact, with the new exporter, org-export-current-backend has
bit the dust, but apparently the non-architected "backend" exists.  the
following works great!!
----
#+call: discs[:file (if (and (boundp 'backend) (equal backend 'html)) "fox.svg" "fox.pdf")]() :results file
----
(note the tick in the (boundp 'backend)).

now to wedge it into some init code.

cheers, Greg

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-26  1:19 ` Eric Schulte
  2013-04-26 11:46   ` Greg Minshall
@ 2013-04-26 22:27   ` Greg Minshall
  2013-04-26 22:34     ` Eric Schulte
  1 sibling, 1 reply; 10+ messages in thread
From: Greg Minshall @ 2013-04-26 22:27 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Eric,

> And you could wrap up the extra-long Emacs-lisp in a function or macro
> in your init to avoid the overlength header argument.

is it possible to embed the function inside the .org file itself?  (in
order to promote sharing of .org files, without needing any
more-than-necessary ancillary state to accompany the file.)

(i can imagine the file extension == file type being a parameter to the
asymptote routines, but i'd *rather* have it pass in the :file
parameter.)

cheers, Greg

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-26 22:27   ` Greg Minshall
@ 2013-04-26 22:34     ` Eric Schulte
  2013-04-26 22:50       ` Greg Minshall
  2013-04-30 14:40       ` Greg Minshall
  0 siblings, 2 replies; 10+ messages in thread
From: Eric Schulte @ 2013-04-26 22:34 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Greg Minshall <minshall@umich.edu> writes:

> Eric,
>
>> And you could wrap up the extra-long Emacs-lisp in a function or macro
>> in your init to avoid the overlength header argument.
>
> is it possible to embed the function inside the .org file itself?  (in
> order to promote sharing of .org files, without needing any
> more-than-necessary ancillary state to accompany the file.)
>
> (i can imagine the file extension == file type being a parameter to the
> asymptote routines, but i'd *rather* have it pass in the :file
> parameter.)
>

You could put the emacs-lisp code into an emacs-lisp code block which is
exported but has a result type of "none" or "silent".

Best,

>
> cheers, Greg

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-26 22:34     ` Eric Schulte
@ 2013-04-26 22:50       ` Greg Minshall
  2013-04-30 14:40       ` Greg Minshall
  1 sibling, 0 replies; 10+ messages in thread
From: Greg Minshall @ 2013-04-26 22:50 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Eric,

> You could put the emacs-lisp code into an emacs-lisp code block which
> is exported but has a result type of "none" or "silent".

ah -- i should have tried that!  that works -- thanks *very* much!

cheers, Greg

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-26 22:34     ` Eric Schulte
  2013-04-26 22:50       ` Greg Minshall
@ 2013-04-30 14:40       ` Greg Minshall
  2013-04-30 18:46         ` Gary Oberbrunner
  1 sibling, 1 reply; 10+ messages in thread
From: Greg Minshall @ 2013-04-30 14:40 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

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 $

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-30 14:40       ` Greg Minshall
@ 2013-04-30 18:46         ` Gary Oberbrunner
  2013-05-01  5:02           ` Eric Schulte
  0 siblings, 1 reply; 10+ messages in thread
From: Gary Oberbrunner @ 2013-04-30 18:46 UTC (permalink / raw)
  To: Orgmode Mailing List

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

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
  2013-04-30 18:46         ` Gary Oberbrunner
@ 2013-05-01  5:02           ` Eric Schulte
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Schulte @ 2013-05-01  5:02 UTC (permalink / raw)
  To: Gary Oberbrunner; +Cc: Orgmode Mailing List

Gary Oberbrunner <garyo@oberbrunner.com> writes:

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

It looks to me like it should work just fine.

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

I don't see the benefit of a macro expansion over the use of variables
as you demonstrate above.

Cheers,

>
>
>
> 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.  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 $
>>
>>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: parameterizing keyword values during a #+call
@ 2013-05-01 10:52 Greg Minshall
  0 siblings, 0 replies; 10+ messages in thread
From: Greg Minshall @ 2013-05-01 10:52 UTC (permalink / raw)
  To: Gary Oberbrunner; +Cc: Orgmode Mailing List

Gary,

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

i agree with Eric's comment.  if you think of the issue of trying to
parse an arbitrary (and growing) number of languages, trying to avoid
language-specific constructions in your choice of macro-designator
(things like "@@..@@" or "{{..}}" or "$.." or...), etc., you will
probably fairly quickly come to see the benefits of :var as the way of
passing in inputs.

cheers, Greg

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-05-01 10:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-25 23:45 parameterizing keyword values during a #+call Greg Minshall
2013-04-26  1:19 ` Eric Schulte
2013-04-26 11:46   ` Greg Minshall
2013-04-26 22:27   ` Greg Minshall
2013-04-26 22:34     ` Eric Schulte
2013-04-26 22:50       ` Greg Minshall
2013-04-30 14:40       ` Greg Minshall
2013-04-30 18:46         ` Gary Oberbrunner
2013-05-01  5:02           ` Eric Schulte
  -- strict thread matches above, loose matches on Subject: below --
2013-05-01 10:52 Greg Minshall

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).