emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jos'h Fuller <Jos'h.Fuller@arcproductions.com>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Tangling without clutter?
Date: Wed, 14 Mar 2012 18:39:49 +0000	[thread overview]
Message-ID: <44B0EAE8544C834188E8790873CDE1CC3EA82A@ARCEXCHANGE.arc.local> (raw)
In-Reply-To: <m1ehsv59g1.fsf@tsdye.com>

Hi!

> Does the :no-expand header argument do what you want?  See
> http://orgmode.org/manual/no_002dexpand.html#no_002dexpand.

I tried using it like this:

  #+name: function-demo
  #+begin_src python :exports both :noweb yes :results output :no-expand
    <<function-definition>>
    
    print entable([["One", 2, 59],["Four", 5, 27], ["Seven", 8, 9]])
  #+end_src

But it didn't seem to affect the results at all. I may be using it wrong, the documentation is a bit sparse, without any examples...

It seems like I almost need some variant of the "tangle" argument to :noweb where syntax references are expanded for evaluation, but not for anything else. 

Thanks for taking a look!

Jos'h


> -----Original Message-----
> From: Thomas S. Dye [mailto:tsd@tsdye.com]
> Sent: Wednesday, March 14, 2012 2:23 PM
> To: Jos'h Fuller
> Cc: emacs-orgmode@gnu.org
> Subject: Re: Tangling without clutter?
> 
> Jos'h Fuller <Jos'h.Fuller@arcproductions.com> writes:
> 
> > Hi!
> >
> > I was writing some documentation about how to use a Python function,
> so I decided to try the tangling feature. However, the result, when
> exported to PDF, is unsatisfactory because the referenced code block is
> included twice -- first in the original location, then again where I
> referenced it with <<function-definition>>.
> >
> > This is, of course, exactly what it needs to do to be able to execute
> the code properly and show the result. But it doesn't look nice. Is
> there any way to suppress the second printing inside the function-demo
> block?
> >
> > If this isn't clear from the example below, I can provide examples of
> the duplication in action as well as what I'd like the output to look
> like.
> >
> > Thanks very much!
> >
> > Example file:
> > #+TITLE:     Tangle Test
> > #+LANGUAGE:  en
> > #+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:nil -:t f:t *:t
> <:t
> > #+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-
> toc
> >
> > * Tangled Code
> >   I want to show the definition of a function first:
> >   #+name: function-definition
> >   #+begin_src python :tangle yes :exports code
> >     def entable(data):
> >         if not data: return "/No data./"
> >
> >         columns = len(data[0])
> >         sizes   = [0,]*columns
> >         for row in data:
> >             sizes = [max(x) for x in zip(sizes, [len(str(t)) for t in
> row])]
> >
> >         format = "| " + " | ".join(["%%%ds" % x for x in sizes])+" |"
> >         return "\n".join([format % tuple(row) for row in data])
> >   #+end_src
> >
> >   Now I want to show a demonstration of how the function might be
> >   called. I need the function to be included so that demonstration
> >   code can be executed, but I don't want to include the function
> >   definition twice:
> >
> >   #+name: function-demo
> >   #+begin_src python :tangle yes :exports both :noweb yes :results
> output
> >     <<function-definition>>
> >
> >     print entable([["One", 2, 3],["Four", 5, 6], ["Seven", 8, 9]])
> >   #+end_src
> >
> >   Which gives us this result:
> >
> >   #+results: function-demo
> >   : |   One | 2 | 3 |
> >   : |  Four | 5 | 6 |
> >   : | Seven | 8 | 9 |
> >
> >
> Aloha!
> 
> Does the :no-expand header argument do what you want?  See
> http://orgmode.org/manual/no_002dexpand.html#no_002dexpand.
> 
> hth,
> Tom
> --
> Thomas S. Dye
> http://www.tsdye.com

  reply	other threads:[~2012-03-14 18:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-14 17:34 Tangling without clutter? Jos'h Fuller
2012-03-14 18:22 ` Thomas S. Dye
2012-03-14 18:39   ` Jos'h Fuller [this message]
2012-03-14 19:13     ` Eric Schulte
2012-03-14 19:35       ` Jos'h Fuller
2012-03-14 18:34         ` Eric Schulte
2012-03-14 22:08           ` Jos'h Fuller
2012-03-14 20:52             ` Eric Schulte
2012-03-15  6:25         ` Viktor Rosenfeld
2012-03-15  8:42           ` Jacek Generowicz

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=44B0EAE8544C834188E8790873CDE1CC3EA82A@ARCEXCHANGE.arc.local \
    --to=jos'h.fuller@arcproductions.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).