From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [babel] References to variable block names Date: Thu, 13 Jan 2011 09:50:19 -0700 Message-ID: <87bp3kd9ys.fsf@gmail.com> References: <87oc7mmjtk.fsf@mundaneum.com> <87y66qrsko.fsf@gmail.com> <874o9dmcdp.fsf@mundaneum.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=38456 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdQNZ-0004sv-C9 for emacs-orgmode@gnu.org; Thu, 13 Jan 2011 11:50:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdQNX-0001fr-S7 for emacs-orgmode@gnu.org; Thu, 13 Jan 2011 11:50:29 -0500 Received: from mail-iy0-f169.google.com ([209.85.210.169]:38459) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdQNX-0001fg-MD for emacs-orgmode@gnu.org; Thu, 13 Jan 2011 11:50:27 -0500 Received: by iyj17 with SMTP id 17so1883131iyj.0 for ; Thu, 13 Jan 2011 08:50:26 -0800 (PST) In-Reply-To: <874o9dmcdp.fsf@mundaneum.com> (Francesco Pizzolante's message of "Thu, 13 Jan 2011 09:33:22 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Francesco Pizzolante Cc: mailing-list-org-mode Francesco Pizzolante writes: > Dear Eric, > > Thanks for your answer. > >> In your example the cv source block only seems to have a single variable >> specified with a :var header argument (namely v-jobtitle), e.g. >> >> #+srcname: cv >> #+begin_src latex :noweb yes :var v-jobtitle="Software Engineer" >> ... >> #+end_src >> >> however your example noweb reference uses 4 variables. You will need to >> update the cv source block so that each variable is given a header >> argument. >> >> #+srcname: cv >> #+headers: :var v-firstname="Alex" :var v-familyname="Pizzo" >> #+headers: :var v-jobtitle="Project Manager" :var employee="alex" >> #+begin_src latex :noweb yes :var v-jobtitle="Software Engineer" >> ... >> #+end_src > > Well, the variable replacement works even if I do not specify the variables in > a header argument. It seems to work like a simple string replace for each > 'variable="value"' parameter in the noweb reference. > > When I write this: > > <> > > When I tangle/evaluate the code, it replaces any occurrence of "v-firstname" > in the cv source code by "Albert" even if the variable is not given a header > argument... > > Seems like the header argument is "just" used to give a default value for the > replacement. > > Is this the expected behavior? > Hmm, well it is not what I would have expected :) However I suppose this behavior does make sense, in effect placing variables in the call line e.g. #+call: cv(v-firstname="Alex",v-familyname="Pizzo",v-jobtitle="Project Manager",employee="alex") Is fully equivalent to the following alternate syntax #+call: cv[:var v-firstname="Alex" :var v-familyname="Pizzo" :var v-jobtitle="Project Manager" :var employee="alex"]() which simply applies the series of variable arguments to the original code block, so yes, I suppose given the semantics of the call line (which I hadn't worked out fully previously) this is the expected behavior. > > >> Then ensure that you can call the cv function using a call line, e.g. >> >> #+call: cv(v-firstname="Alex",v-familyname="Pizzo",v-jobtitle="Project Manager",employee="alex") >> >> Once that is working then the noweb reference should work as well. > > I tried what you say, but it seems that a variable in a noweb reference does > not get replaced by its value. From my point of view, it seems that: > > - either, the noweb references are replaced before the variables get replaced > by their values; > I believe you've put your finger on the issue, we are most likely replacing the noweb references before the variables are replaced in the code block, as an example please see the following... #+source: replaced-first #+begin_src latex \begin{itemize} \item first \item data \item third \end{itemize} #+end_src #+begin_src latex :var data="second" :noweb yes \section{ordinals} \label{sec:ordinals} <> #+end_src in which calling `org-babel-expand-src-block' C-c C-v v on the second code block results in \section{ordinals} \label{sec:ordinals} \begin{itemize} \item first \item second \item third \end{itemize} > > - or, the variable replacement does not work in noweb references. > > Here's a shorter example where, whatever I try, I keep getting the Profile > section empty: > I see now what you are trying to do, replacing variable names embedded in noweb references is tricky, and I see how it is useful in this example, but I'm afraid it is not something that we support. The application of a variable to a code block body is language-dependent, and is expected to have it's effects limited to "code" rather than to "meta-information" as you have tried in your example below. maybe, instead of the structure below, you could change your cv code block to the following (e.g. resolve the profile inside the header arguments, where we expect manipulation of block-level objects). #+srcname: cv #+begin_src latex :noweb yes :var employee-profile=profile-alex \documentclass{mycvclass} \usepackage[utf8x]{inputenc} \begin{document} \section{Profile} employee-profile \end{document} #+end_src also, arbitrary elisp is allowed in variable assignments, so you have much freedom for manipulation in that regard. Hope this Helps -- Eric > > * Alex > > #+call: cv(employee="alex") > > #+srcname: cv-alex > #+begin_src latex :noweb yes :tangle alex.tex > <> > #+end_src > > ** Profile > > #+srcname: profile-alex > #+begin_src latex > Software engineering expert. > #+end_src > > * Composed CV > #+srcname: cv > #+begin_src latex :noweb yes :var employee="alex" > \documentclass{mycvclass} > \usepackage[utf8x]{inputenc} > > \begin{document} > > \section{Profile} > <> > > \end{document} > #+end_src > > Any help is welcome. > > Thanks, > Francesco