emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Greg Minshall <minshall@umich.edu>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: parameterizing keyword values during a #+call
Date: Tue, 30 Apr 2013 10:40:02 -0400	[thread overview]
Message-ID: <11889.1367332802@greg-minshalls-mbp.local> (raw)
In-Reply-To: Your message of "Fri, 26 Apr 2013 16:34:42 -0600." <87ehdw53b1.fsf@gmail.com>

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 $

  parent reply	other threads:[~2013-04-30 14:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25 23:45 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 [this message]
2013-04-30 18:46         ` Gary Oberbrunner
2013-05-01  5:02           ` Eric Schulte
2013-05-01 10:52 Greg Minshall

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11889.1367332802@greg-minshalls-mbp.local \
    --to=minshall@umich.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    --subject='Re: parameterizing keyword values during a #+call' \
    /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

Code repositories for project(s) associated with this 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).