emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] References to variable block names
@ 2011-01-12 11:40 Francesco Pizzolante
  2011-01-12 16:32 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Francesco Pizzolante @ 2011-01-12 11:40 UTC (permalink / raw)
  To: mailing-list-org-mode

Hi,

I'm trying to maintain my employees CVs in a single Org file using Babel (see
example hereunder).

For this, I created several level-1 headings, one for each employee.

Then, I have my main CV block (cv source block, see last "Composed CV"
heading) containing the layout of the CVs. This block is "called" for each
employee, in order to tangle a LaTeX file with the correct information.

Though, currently, I'm not able to use variables *in noweb references* (see my
employee variable in <<cv(employee="XXX")>>.

Could someone tell me how to have a generic solution, in this way or another?

Any other ideas regarding this are welcome!

Thanks a lot,
Francesco


--8<---------------cut here---------------start------------->8---
* Alex

#+srcname: cv-alex
#+begin_src latex :noweb yes :tangle alex.tex
<<cv(v-firstname="Alex",v-familyname="Pizzo",v-jobtitle="Project Manager",employee="alex")>>
#+end_src

** Profile

#+srcname: profile-alex
#+begin_src latex
Software engineering expert.
#+end_src

** Experience

#+srcname: experience-alex
#+begin_src latex
\cventry{2007--2010}{Project Manager}{MyProject}{MyCompany}{}{}
\cventry{2005--2007}{Project Manager}{MyProject2}{MyCompany2}{}{}
#+end_src

* Albert

#+srcname: cv-albert
#+begin_src latex :noweb yes :tangle albert.tex
<<cv(v-firstname="Albert",v-familyname="Pizza",employee="albert")>>
#+end_src

** Profile

#+srcname: profile-albert
#+begin_src latex
Software engineering expert.
#+end_src

** Experience

#+srcname: experience-albert
#+begin_src latex
\cventry{2009--2010}{Developer}{MyProject}{MyCompany}{}{}
\cventry{2008--2009}{Developer}{MyProject2}{MyCompany2}{}{}
#+end_src

* Composed CV                                                :noexport:

#+srcname: cv
#+begin_src latex :noweb yes :var v-jobtitle="Software Engineer"
\documentclass{mycvclass}
\usepackage[utf8x]{inputenc}

\firstname{v-firstname}
\familyname{v-familyname}
\jobtitle{v-jobtitle}

\begin{document}

\section{Profile}
<<profile-employee>>

\section{Experience}
<<experience-employee>>

\end{document}
#+end_src
--8<---------------cut here---------------end--------------->8---

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [babel] References to variable block names
  2011-01-12 11:40 [babel] References to variable block names Francesco Pizzolante
@ 2011-01-12 16:32 ` Eric Schulte
       [not found]   ` <87y66qrsko.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2011-01-12 16:32 UTC (permalink / raw)
  To: Francesco Pizzolante; +Cc: mailing-list-org-mode

Hi Francesco,

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

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.

Best -- Eric

Francesco Pizzolante <fpz@missioncriticalit.com> writes:

> Hi,
>
> I'm trying to maintain my employees CVs in a single Org file using Babel (see
> example hereunder).
>
> For this, I created several level-1 headings, one for each employee.
>
> Then, I have my main CV block (cv source block, see last "Composed CV"
> heading) containing the layout of the CVs. This block is "called" for each
> employee, in order to tangle a LaTeX file with the correct information.
>
> Though, currently, I'm not able to use variables *in noweb references* (see my
> employee variable in <<cv(employee="XXX")>>.
>
> Could someone tell me how to have a generic solution, in this way or another?
>
> Any other ideas regarding this are welcome!
>
> Thanks a lot,
> Francesco
>
>
> * Alex
>
> #+srcname: cv-alex
> #+begin_src latex :noweb yes :tangle alex.tex
> <<cv(v-firstname="Alex",v-familyname="Pizzo",v-jobtitle="Project Manager",employee="alex")>>
> #+end_src
>
> ** Profile
>
> #+srcname: profile-alex
> #+begin_src latex
> Software engineering expert.
> #+end_src
>
> ** Experience
>
> #+srcname: experience-alex
> #+begin_src latex
> \cventry{2007--2010}{Project Manager}{MyProject}{MyCompany}{}{}
> \cventry{2005--2007}{Project Manager}{MyProject2}{MyCompany2}{}{}
> #+end_src
>
> * Albert
>
> #+srcname: cv-albert
> #+begin_src latex :noweb yes :tangle albert.tex
> <<cv(v-firstname="Albert",v-familyname="Pizza",employee="albert")>>
> #+end_src
>
> ** Profile
>
> #+srcname: profile-albert
> #+begin_src latex
> Software engineering expert.
> #+end_src
>
> ** Experience
>
> #+srcname: experience-albert
> #+begin_src latex
> \cventry{2009--2010}{Developer}{MyProject}{MyCompany}{}{}
> \cventry{2008--2009}{Developer}{MyProject2}{MyCompany2}{}{}
> #+end_src
>
> * Composed CV                                                :noexport:
>
> #+srcname: cv
> #+begin_src latex :noweb yes :var v-jobtitle="Software Engineer"
> \documentclass{mycvclass}
> \usepackage[utf8x]{inputenc}
>
> \firstname{v-firstname}
> \familyname{v-familyname}
> \jobtitle{v-jobtitle}
>
> \begin{document}
>
> \section{Profile}
> <<profile-employee>>
>
> \section{Experience}
> <<experience-employee>>
>
> \end{document}
> #+end_src
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [babel] References to variable block names
       [not found]   ` <87y66qrsko.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-01-13  8:33     ` Francesco Pizzolante
  2011-01-13 16:50       ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Francesco Pizzolante @ 2011-01-13  8:33 UTC (permalink / raw)
  To: Eric Schulte; +Cc: mailing-list-org-mode

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:

--8<---------------cut here---------------start------------->8---
<<cv(v-firstname="Albert")>>
--8<---------------cut here---------------end--------------->8---

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?


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

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

--8<---------------cut here---------------start------------->8---
* Alex

#+call: cv(employee="alex")

#+srcname: cv-alex
#+begin_src latex :noweb yes :tangle alex.tex
<<cv(employee="alex")>>
#+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}
<<profile-employee>>

\end{document}
#+end_src
--8<---------------cut here---------------end--------------->8---

Any help is welcome.

Thanks,
Francesco

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [babel] References to variable block names
  2011-01-13  8:33     ` Francesco Pizzolante
@ 2011-01-13 16:50       ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2011-01-13 16:50 UTC (permalink / raw)
  To: Francesco Pizzolante; +Cc: mailing-list-org-mode

Francesco Pizzolante <fpz@missioncriticalit.com> 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:
>
> <<cv(v-firstname="Albert")>>
>
> 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}
  <<replaced-first>>
#+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
> <<cv(employee="alex")>>
> #+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}
> <<profile-employee>>
>
> \end{document}
> #+end_src
>
> Any help is welcome.
>
> Thanks,
> Francesco

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

end of thread, other threads:[~2011-01-13 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-12 11:40 [babel] References to variable block names Francesco Pizzolante
2011-01-12 16:32 ` Eric Schulte
     [not found]   ` <87y66qrsko.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-01-13  8:33     ` Francesco Pizzolante
2011-01-13 16:50       ` Eric Schulte

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