* «Macro» expansion in source blocks; code-sharing between blocks
@ 2014-09-18 13:17 Tobias Getzner
2014-09-18 13:26 ` Tobias Getzner
0 siblings, 1 reply; 14+ messages in thread
From: Tobias Getzner @ 2014-09-18 13:17 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I was wondering whether there exists some way of sharing literal code
(or, possibly, code results) between subsequent code blocks. E.g., I was
trying to create a document containing several tikz graphics, and I would
like to share a number of style definitions between these. When I only
export to LaTeX, I can of course just use isolated BEGIN_LATEX blocks,
and refer to shared stuff using LaTeX semantics. But I was wondering if
something like this could possibly be done using code blocks only.
It seemed to me that there are two «expansion mechanisms» for source code
in org: 1. Calling named source blocks; 2. macro expansion.
As for 1., calling a named block from within another isn’t currently
handled, is it? As for 2., macro expansion only occurs upon export,
right? While I found an interesting proposal to expand macros within
source code at [1], this supposedly only works when either doing an
export or when tangling an external file.
Are there any convenient inline-expansion methods I might have overlooked?
Best regards,
Tobias
[1] https://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg00843.html
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 13:17 «Macro» expansion in source blocks; code-sharing between blocks Tobias Getzner
@ 2014-09-18 13:26 ` Tobias Getzner
2014-09-18 14:01 ` Eric S Fraga
0 siblings, 1 reply; 14+ messages in thread
From: Tobias Getzner @ 2014-09-18 13:26 UTC (permalink / raw)
To: emacs-orgmode
On Thu, 18 Sep 2014 13:17:14 +0000, Tobias Getzner wrote:
> Are there any convenient inline-expansion methods I might have
> overlooked?
To illustrate, I was wondering if any of the following is feasible
somehow:
* Semantic expansion
#+name setup_fu
#+begin_src sh :results raw
echo 2
#+end_src
#+begin_src sh :results raw
echo 1
echo {{{call_setup_fu()}}} ← some sort of escape syntax
echo 3
#+end_src
#+results:
1
2
3
* Syntactic expansion
#+begin_macro setup_fu
echo 2
#+end_macro
#+begin_src sh :results raw
echo 1
{{{setup_fu()}}}
echo 3
#+end_src
#+results:
1
2
3
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 13:26 ` Tobias Getzner
@ 2014-09-18 14:01 ` Eric S Fraga
2014-09-18 14:40 ` Tobias Getzner
2014-09-18 23:44 ` Andreas Kiermeier
0 siblings, 2 replies; 14+ messages in thread
From: Eric S Fraga @ 2014-09-18 14:01 UTC (permalink / raw)
To: Tobias Getzner; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 823 bytes --]
On Thursday, 18 Sep 2014 at 13:26, Tobias Getzner wrote:
> On Thu, 18 Sep 2014 13:17:14 +0000, Tobias Getzner wrote:
>
>> Are there any convenient inline-expansion methods I might have
>> overlooked?
>
> To illustrate, I was wondering if any of the following is feasible
> somehow:
Yes, and you almost got it right with your syntactic expansion:
#+begin_src org
,* Syntactic expansion
,#+name: setup_fu
,#+begin_src sh :noweb yes
echo 2
,#+end_src
,#+begin_src sh :results raw :noweb yes
echo 1
<<setup_fu>>
echo 3
,#+end_src
,#+results:
1
2
3
#+end_src
Org src blocks can reference other src blocks. Note the ":noweb yes"
option and the use of <<...>>.
--
: Eric S Fraga (0xFFFCF67D), Emacs 24.4.50.1, Org release_8.3beta-366-gb2fca7
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 14:01 ` Eric S Fraga
@ 2014-09-18 14:40 ` Tobias Getzner
2014-09-18 23:44 ` Andreas Kiermeier
1 sibling, 0 replies; 14+ messages in thread
From: Tobias Getzner @ 2014-09-18 14:40 UTC (permalink / raw)
To: emacs-orgmode
On Thu, 18 Sep 2014 15:01:37 +0100, Eric S Fraga wrote:
>>> Are there any convenient inline-expansion methods I might have
>>> overlooked?
> Org src blocks can reference other src blocks. Note the ":noweb yes"
> option and the use of <<...>>.
Nice! And I see I get «semantic» expansion when I add call syntax after
the block’s name. This is quite awesome.
Not being familiar with the term, «noweb» must have slipped my attention
when I was skimming through that section. Thanks very much for the
pointer!
Best,
T.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 14:01 ` Eric S Fraga
2014-09-18 14:40 ` Tobias Getzner
@ 2014-09-18 23:44 ` Andreas Kiermeier
2014-09-19 2:59 ` Charles Berry
` (2 more replies)
1 sibling, 3 replies; 14+ messages in thread
From: Andreas Kiermeier @ 2014-09-18 23:44 UTC (permalink / raw)
To: emacs-orgmode
I don't think you need the ":noweb yes" as part of the setup_fu
header, as this block is not pulling in other materials.
Having used this type of setup only over the last couple of days, I've
come up with another question. It appears that the setup_fu is
executed twice ... once as it's own source block (though by itself not
need) and once as part of the second noweb block. This isn't a problem
if the execution time is small, but I'm trying to create a summary
table in Latex format from 2 million records - so the time is
considerable.
My two blocks (with some code removed for simplicity) are as follow:
#+NAME: tbl-refyear
#+BEGIN_SRC R :results silent :exports none
latex(tabular( <code remove> ))
#+END_SRC
#+BEGIN_SRC latex :noweb yes
\begin{table}[h]
\label{tbl:refyear}
\caption{Separation outcomes (death or any type of discharge) by
reference year.}
<<tbl-refyear()>>
\end{table}
#+END_SRC
I've tried :cache yes as part of the tbl-refyear source block, but
that didn't stop if from being run twice. Am I missing a suitable
header argument?
This is the only way I could find to wrap the latex table (which has
some complex formatting and hence why I've used it over just producing
a table) in a float with a caption (though I still can't properly
reference the label when I export to a PDF file).
Any thought would be greatly appreciated. TIA!
Andreas
On 18 September 2014 23:31, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:
>
> On Thursday, 18 Sep 2014 at 13:26, Tobias Getzner wrote:
> > On Thu, 18 Sep 2014 13:17:14 +0000, Tobias Getzner wrote:
> >
> >> Are there any convenient inline-expansion methods I might have
> >> overlooked?
> >
> > To illustrate, I was wondering if any of the following is feasible
> > somehow:
>
> Yes, and you almost got it right with your syntactic expansion:
>
> #+begin_src org
>
> ,* Syntactic expansion
>
> ,#+name: setup_fu
> ,#+begin_src sh :noweb yes
> echo 2
> ,#+end_src
>
> ,#+begin_src sh :results raw :noweb yes
> echo 1
> <<setup_fu>>
> echo 3
> ,#+end_src
>
> ,#+results:
> 1
> 2
> 3
>
> #+end_src
>
> Org src blocks can reference other src blocks. Note the ":noweb yes"
> option and the use of <<...>>.
>
>
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 24.4.50.1, Org release_8.3beta-366-gb2fca7
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 23:44 ` Andreas Kiermeier
@ 2014-09-19 2:59 ` Charles Berry
2014-09-19 10:18 ` Andreas Kiermeier
2014-09-19 7:44 ` Eric S Fraga
2014-09-19 9:04 ` Rainer M Krug
2 siblings, 1 reply; 14+ messages in thread
From: Charles Berry @ 2014-09-19 2:59 UTC (permalink / raw)
To: emacs-orgmode
Andreas Kiermeier <andreas.kiermeier <at> gmail.com> writes:
>
> My two blocks (with some code removed for simplicity) are as follow:
>
> #+NAME: tbl-refyear
> #+BEGIN_SRC R :results silent :exports none
> latex(tabular( <code remove> ))
> #+END_SRC
>
> #+BEGIN_SRC latex :noweb yes
> \begin{table}[h]
> \label{tbl:refyear}
> \caption{Separation outcomes (death or any type of discharge) by
> reference year.}
> <<tbl-refyear()>>
> \end{table}
> #+END_SRC
>
> I've tried :cache yes as part of the tbl-refyear source block, but
> that didn't stop if from being run twice. Am I missing a suitable
> header argument?
>
> This is the only way I could find to wrap the latex table (which has
> some complex formatting and hence why I've used it over just producing
> a table) in a float with a caption (though I still can't properly
> reference the label when I export to a PDF file).
>
> Any thought would be greatly appreciated. TIA!
>
Why not use library(xtable) and do it all in R?
If you are not sure this is the right choice, I suggest you look at the
help page for print.xtable - you have a lot of control over caption,
label, positioning, etc.
HTH,
Chuck
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 23:44 ` Andreas Kiermeier
2014-09-19 2:59 ` Charles Berry
@ 2014-09-19 7:44 ` Eric S Fraga
2014-09-19 9:04 ` Rainer M Krug
2 siblings, 0 replies; 14+ messages in thread
From: Eric S Fraga @ 2014-09-19 7:44 UTC (permalink / raw)
To: Andreas Kiermeier; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 434 bytes --]
On Friday, 19 Sep 2014 at 09:14, Andreas Kiermeier wrote:
> Having used this type of setup only over the last couple of days, I've
> come up with another question. It appears that the setup_fu is
> executed twice ... once as it's own source block (though by itself not
maybe say ":results none" instead of silent?
just grasping a straws here.
--
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.1, Org release_8.3beta-372-gdd70cf
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-18 23:44 ` Andreas Kiermeier
2014-09-19 2:59 ` Charles Berry
2014-09-19 7:44 ` Eric S Fraga
@ 2014-09-19 9:04 ` Rainer M Krug
2014-09-19 10:19 ` Andreas Kiermeier
2 siblings, 1 reply; 14+ messages in thread
From: Rainer M Krug @ 2014-09-19 9:04 UTC (permalink / raw)
To: Andreas Kiermeier; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3909 bytes --]
Andreas Kiermeier <andreas.kiermeier@gmail.com> writes:
> I don't think you need the ":noweb yes" as part of the setup_fu
> header, as this block is not pulling in other materials.
>
> Having used this type of setup only over the last couple of days, I've
> come up with another question. It appears that the setup_fu is
> executed twice ... once as it's own source block (though by itself not
> need) and once as part of the second noweb block. This isn't a problem
> if the execution time is small, but I'm trying to create a summary
> table in Latex format from 2 million records - so the time is
> considerable.
>
Check out the :eval header argument: if you use
,----
| #+BEGIN_SRC R :eval never :exports none
`----
this block is never executed - this should work. There are also other
values for :eval. From the help:
,----
| 14.8.2.25 `:eval'
| .................
|
| The `:eval' header argument can be used to limit the evaluation of
| specific code blocks. The `:eval' header argument can be useful for
| protecting against the evaluation of dangerous code blocks or to ensure
| that evaluation will require a query regardless of the value of the
| `org-confirm-babel-evaluate' variable. The possible values of `:eval'
| and their effects are shown below.
|
| `never or no'
| The code block will not be evaluated under any circumstances.
|
| `query'
| Evaluation of the code block will require a query.
|
| `never-export or no-export'
| The code block will not be evaluated during export but may still
| be called interactively.
|
| `query-export'
| Evaluation of the code block during export will require a query.
|
| If this header argument is not set then evaluation is determined by
| the value of the `org-confirm-babel-evaluate' variable see *Note Code
| evaluation security::.
`----
Cheers,
Rainer
> My two blocks (with some code removed for simplicity) are as follow:
>
> #+NAME: tbl-refyear
> #+BEGIN_SRC R :results silent :exports none
> latex(tabular( <code remove> ))
> #+END_SRC
>
> #+BEGIN_SRC latex :noweb yes
> \begin{table}[h]
> \label{tbl:refyear}
> \caption{Separation outcomes (death or any type of discharge) by
> reference year.}
> <<tbl-refyear()>>
> \end{table}
> #+END_SRC
>
> I've tried :cache yes as part of the tbl-refyear source block, but
> that didn't stop if from being run twice. Am I missing a suitable
> header argument?
>
> This is the only way I could find to wrap the latex table (which has
> some complex formatting and hence why I've used it over just producing
> a table) in a float with a caption (though I still can't properly
> reference the label when I export to a PDF file).
>
> Any thought would be greatly appreciated. TIA!
>
> Andreas
>
> On 18 September 2014 23:31, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:
>>
>> On Thursday, 18 Sep 2014 at 13:26, Tobias Getzner wrote:
>> > On Thu, 18 Sep 2014 13:17:14 +0000, Tobias Getzner wrote:
>> >
>> >> Are there any convenient inline-expansion methods I might have
>> >> overlooked?
>> >
>> > To illustrate, I was wondering if any of the following is feasible
>> > somehow:
>>
>> Yes, and you almost got it right with your syntactic expansion:
>>
>> #+begin_src org
>>
>> ,* Syntactic expansion
>>
>> ,#+name: setup_fu
>> ,#+begin_src sh :noweb yes
>> echo 2
>> ,#+end_src
>>
>> ,#+begin_src sh :results raw :noweb yes
>> echo 1
>> <<setup_fu>>
>> echo 3
>> ,#+end_src
>>
>> ,#+results:
>> 1
>> 2
>> 3
>>
>> #+end_src
>>
>> Org src blocks can reference other src blocks. Note the ":noweb yes"
>> option and the use of <<...>>.
>>
>>
>> --
>> : Eric S Fraga (0xFFFCF67D), Emacs 24.4.50.1, Org release_8.3beta-366-gb2fca7
>
>
--
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-19 2:59 ` Charles Berry
@ 2014-09-19 10:18 ` Andreas Kiermeier
0 siblings, 0 replies; 14+ messages in thread
From: Andreas Kiermeier @ 2014-09-19 10:18 UTC (permalink / raw)
To: Charles Berry; +Cc: emacs-orgmode
Hi Chuck
On 19 September 2014 12:29, Charles Berry <ccberry@ucsd.edu> wrote:
>
> Why not use library(xtable) and do it all in R?
>
> If you are not sure this is the right choice, I suggest you look at the
> help page for print.xtable - you have a lot of control over caption,
> label, positioning, etc.
I was trying to do that with "latex(tabular( ...))" though I can see
that I can wrap the table in a floating table environment with xtable.
In fact, I did look at xtable before settling on the above approach,
which I did because tabular does create some nice tables, including
multiple levels and totals. I was trying to avoid R's simple "table" &
prop table functions and having to construct the table and various
headings myself before wrapping it up in xtable(). But maybe that's
the way to go.
Thanks,
Andreas
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-19 9:04 ` Rainer M Krug
@ 2014-09-19 10:19 ` Andreas Kiermeier
2014-09-19 10:59 ` header arguments, inheritance, and noweb expansion Was: " Rainer M Krug
0 siblings, 1 reply; 14+ messages in thread
From: Andreas Kiermeier @ 2014-09-19 10:19 UTC (permalink / raw)
To: Rainer M Krug; +Cc: emacs-orgmode
Thanks Rainer,
but unfortunately this isn't working. I'm sure I'm doing something
wrong ... somewhere.
In case this makes any difference I have in the document header:
#+PROPERTY: header-args:R :session *R*
#+PROPERTY: header-args :results output graphics :exports results
I've now changed the source block header to ":exports none :eval no"
but now there really is nothing in the output.
In fact, the corresponding .tex file now contains:
\begin{table}[h]
\label{tbl:refyear}
\caption{Separation outcomes (death or any type of discharge) by
reference year.}
nil
\end{table}
and in the *Message* buffer I now have:
Evaluation of this R code-block (tbl-refyear) is disabled.
org-babel-exp processing...
Evaluation of this R code-block (tbl-refyear) is disabled.
executing Latex code block...
So, this source block really doesn't evaluated at all.
Thanks
Andreas
On 19 September 2014 18:34, Rainer M Krug <Rainer@krugs.de> wrote:
> Andreas Kiermeier <andreas.kiermeier@gmail.com> writes:
>
>> I don't think you need the ":noweb yes" as part of the setup_fu
>> header, as this block is not pulling in other materials.
>>
>> Having used this type of setup only over the last couple of days, I've
>> come up with another question. It appears that the setup_fu is
>> executed twice ... once as it's own source block (though by itself not
>> need) and once as part of the second noweb block. This isn't a problem
>> if the execution time is small, but I'm trying to create a summary
>> table in Latex format from 2 million records - so the time is
>> considerable.
>>
>
> Check out the :eval header argument: if you use
>
> ,----
> | #+BEGIN_SRC R :eval never :exports none
> `----
>
> this block is never executed - this should work. There are also other
> values for :eval. From the help:
>
> ,----
> | 14.8.2.25 `:eval'
> | .................
> |
> | The `:eval' header argument can be used to limit the evaluation of
> | specific code blocks. The `:eval' header argument can be useful for
> | protecting against the evaluation of dangerous code blocks or to ensure
> | that evaluation will require a query regardless of the value of the
> | `org-confirm-babel-evaluate' variable. The possible values of `:eval'
> | and their effects are shown below.
> |
> | `never or no'
> | The code block will not be evaluated under any circumstances.
> |
> | `query'
> | Evaluation of the code block will require a query.
> |
> | `never-export or no-export'
> | The code block will not be evaluated during export but may still
> | be called interactively.
> |
> | `query-export'
> | Evaluation of the code block during export will require a query.
> |
> | If this header argument is not set then evaluation is determined by
> | the value of the `org-confirm-babel-evaluate' variable see *Note Code
> | evaluation security::.
> `----
>
> Cheers,
>
> Rainer
>
>
>> My two blocks (with some code removed for simplicity) are as follow:
>>
>> #+NAME: tbl-refyear
>> #+BEGIN_SRC R :results silent :exports none
>> latex(tabular( <code remove> ))
>> #+END_SRC
>>
>> #+BEGIN_SRC latex :noweb yes
>> \begin{table}[h]
>> \label{tbl:refyear}
>> \caption{Separation outcomes (death or any type of discharge) by
>> reference year.}
>> <<tbl-refyear()>>
>> \end{table}
>> #+END_SRC
>>
>> I've tried :cache yes as part of the tbl-refyear source block, but
>> that didn't stop if from being run twice. Am I missing a suitable
>> header argument?
>>
>> This is the only way I could find to wrap the latex table (which has
>> some complex formatting and hence why I've used it over just producing
>> a table) in a float with a caption (though I still can't properly
>> reference the label when I export to a PDF file).
>>
>> Any thought would be greatly appreciated. TIA!
>>
>> Andreas
^ permalink raw reply [flat|nested] 14+ messages in thread
* header arguments, inheritance, and noweb expansion Was: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-19 10:19 ` Andreas Kiermeier
@ 2014-09-19 10:59 ` Rainer M Krug
2014-09-20 6:57 ` Andreas Kiermeier
0 siblings, 1 reply; 14+ messages in thread
From: Rainer M Krug @ 2014-09-19 10:59 UTC (permalink / raw)
To: Andreas Kiermeier; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 4723 bytes --]
Andreas Kiermeier <andreas.kiermeier@gmail.com> writes:
> Thanks Rainer,
>
> but unfortunately this isn't working. I'm sure I'm doing something
> wrong ... somewhere.
>
> In case this makes any difference I have in the document header:
>
> #+PROPERTY: header-args:R :session *R*
> #+PROPERTY: header-args :results output graphics :exports results
>
> I've now changed the source block header to ":exports none :eval no"
> but now there really is nothing in the output.
>
> In fact, the corresponding .tex file now contains:
>
> \begin{table}[h]
> \label{tbl:refyear}
> \caption{Separation outcomes (death or any type of discharge) by
> reference year.}
> nil
> \end{table}
>
> and in the *Message* buffer I now have:
>
> Evaluation of this R code-block (tbl-refyear) is disabled.
> org-babel-exp processing...
> Evaluation of this R code-block (tbl-refyear) is disabled.
> executing Latex code block...
>
> So, this source block really doesn't evaluated at all.
This boils down to the question I asked earlier about header-args and
+header args, inheritance of header arguments and this in contrast to
normal header args.
Based on this discussion, I thought that the header arguments count
*where the code is executed* and not where it is defined - well -
surprise for me.
You could try and put the code block with the definition of the code
into a subtree where you set
,----
| :PROPERTIES:
| :headser-args+: eval no
| :END:
`----
This might work?
Rainer
>
> Thanks
>
> Andreas
>
> On 19 September 2014 18:34, Rainer M Krug <Rainer@krugs.de> wrote:
>> Andreas Kiermeier <andreas.kiermeier@gmail.com> writes:
>>
>>> I don't think you need the ":noweb yes" as part of the setup_fu
>>> header, as this block is not pulling in other materials.
>>>
>>> Having used this type of setup only over the last couple of days, I've
>>> come up with another question. It appears that the setup_fu is
>>> executed twice ... once as it's own source block (though by itself not
>>> need) and once as part of the second noweb block. This isn't a problem
>>> if the execution time is small, but I'm trying to create a summary
>>> table in Latex format from 2 million records - so the time is
>>> considerable.
>>>
>>
>> Check out the :eval header argument: if you use
>>
>> ,----
>> | #+BEGIN_SRC R :eval never :exports none
>> `----
>>
>> this block is never executed - this should work. There are also other
>> values for :eval. From the help:
>>
>> ,----
>> | 14.8.2.25 `:eval'
>> | .................
>> |
>> | The `:eval' header argument can be used to limit the evaluation of
>> | specific code blocks. The `:eval' header argument can be useful for
>> | protecting against the evaluation of dangerous code blocks or to ensure
>> | that evaluation will require a query regardless of the value of the
>> | `org-confirm-babel-evaluate' variable. The possible values of `:eval'
>> | and their effects are shown below.
>> |
>> | `never or no'
>> | The code block will not be evaluated under any circumstances.
>> |
>> | `query'
>> | Evaluation of the code block will require a query.
>> |
>> | `never-export or no-export'
>> | The code block will not be evaluated during export but may still
>> | be called interactively.
>> |
>> | `query-export'
>> | Evaluation of the code block during export will require a query.
>> |
>> | If this header argument is not set then evaluation is determined by
>> | the value of the `org-confirm-babel-evaluate' variable see *Note Code
>> | evaluation security::.
>> `----
>>
>> Cheers,
>>
>> Rainer
>>
>>
>>> My two blocks (with some code removed for simplicity) are as follow:
>>>
>>> #+NAME: tbl-refyear
>>> #+BEGIN_SRC R :results silent :exports none
>>> latex(tabular( <code remove> ))
>>> #+END_SRC
>>>
>>> #+BEGIN_SRC latex :noweb yes
>>> \begin{table}[h]
>>> \label{tbl:refyear}
>>> \caption{Separation outcomes (death or any type of discharge) by
>>> reference year.}
>>> <<tbl-refyear()>>
>>> \end{table}
>>> #+END_SRC
>>>
>>> I've tried :cache yes as part of the tbl-refyear source block, but
>>> that didn't stop if from being run twice. Am I missing a suitable
>>> header argument?
>>>
>>> This is the only way I could find to wrap the latex table (which has
>>> some complex formatting and hence why I've used it over just producing
>>> a table) in a float with a caption (though I still can't properly
>>> reference the label when I export to a PDF file).
>>>
>>> Any thought would be greatly appreciated. TIA!
>>>
>>> Andreas
>
>
--
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: header arguments, inheritance, and noweb expansion Was: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-19 10:59 ` header arguments, inheritance, and noweb expansion Was: " Rainer M Krug
@ 2014-09-20 6:57 ` Andreas Kiermeier
2014-09-20 16:06 ` Charles Berry
0 siblings, 1 reply; 14+ messages in thread
From: Andreas Kiermeier @ 2014-09-20 6:57 UTC (permalink / raw)
To: Rainer M Krug; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]
On 19 September 2014 20:29, Rainer M Krug <Rainer@krugs.de> wrote:
> This boils down to the question I asked earlier about header-args and
> +header args, inheritance of header arguments and this in contrast to
> normal header args.
>
> Based on this discussion, I thought that the header arguments count
> *where the code is executed* and not where it is defined - well -
> surprise for me.
>
> You could try and put the code block with the definition of the code
> into a subtree where you set
>
> ,----
> | :PROPERTIES:
> | :headser-args+: eval no
> | :END:
> `----
>
> This might work?
Hi Rainer & list,
I've set the following property for the subtree that both code blocks are
in:
:header-args+: :eval no
but this results in no execution of either block
.
I noticed in a separate thread (
https://lists.gnu.org/archive/html/emacs-orgmode/2014-09/msg00547.html)
that there is also :float header argument. The manual seems to indicate
that it only applies to org tables (exported to latex) - I've tried using
it on the original source block that produces a latex table as output,
which of course didn't work.
But ... if it did, that is,
if this float (and placement) header argument was utilised by the latex
source block, and so wrapped the output in a float (with optional caption
& label
), then this
could
circumvent the need for the second noweb source block.
The alternative mentioned by Chuck Berry is the xtable function (in R) (
https://lists.gnu.org/archive/html/emacs-orgmode/2014-09/msg00519.html). I
just tried it and am happy to share that it does created the whole output
in one go, i.e. it does exactly what I need, including table float, caption
and label. Now I just got to sort out how to created the tables without the
use of tabular ...
Thanks to all for your help!
Cheers,
Andreas
[-- Attachment #2: Type: text/html, Size: 4400 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: header arguments, inheritance, and noweb expansion Was: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-20 6:57 ` Andreas Kiermeier
@ 2014-09-20 16:06 ` Charles Berry
2014-09-21 4:19 ` Andreas Kiermeier
0 siblings, 1 reply; 14+ messages in thread
From: Charles Berry @ 2014-09-20 16:06 UTC (permalink / raw)
To: emacs-orgmode
Andreas Kiermeier <andreas.kiermeier <at> gmail.com> writes:
>
> On 19 September 2014 20:29, Rainer M Krug <Rainer <at> krugs.de> wrote:>
[ snip ]
>
> The alternative mentioned by Chuck Berry is the xtable function (in R)
> (https://lists.gnu.org/archive/html/emacs-orgmode/2014-09/msg00519.html).
> I just tried it and am happy to share that it does created the whole
> output in one go, i.e. it does exactly what I need, including table
> float, caption and label. Now I just got to sort out how to created the
> tables without the use of tabular ...
>
I suggested xtable because that is what I often use.
But thinking a bit more, I decided to look at tables::tabular() and
at Hmisc::latex(), which I think is what you used at first.
And it turns out that latex() has args for caption, label, where, and
loads of other things. See its help page. So, it looks like you have the
control you need and the ability to use
latex( tabular(...), caption = <...>, label = <...>, ...)
to good effect.
HTH,
Chuck
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: header arguments, inheritance, and noweb expansion Was: «Macro» expansion in source blocks; code-sharing between blocks
2014-09-20 16:06 ` Charles Berry
@ 2014-09-21 4:19 ` Andreas Kiermeier
0 siblings, 0 replies; 14+ messages in thread
From: Andreas Kiermeier @ 2014-09-21 4:19 UTC (permalink / raw)
To: Charles Berry; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]
Thanks Chuck,
I thought the same, especially since I found the tabular() function by
looking at Hmisc and rms documentation (both packages by Frank Harrell).
But as it turns out the latex method for objects of class tabular is
defined in the table package and it has a much more limited set of options.
The upside is that I found the additional functions margin.table and
addmargins (I knew about prop.table) which are going to make my life easier
with R's tables.
Cheers,
Andreas
--
Dr Andreas Kiermeier | Director
Statistical Process Improvement Consulting and Training Pty Ltd
Mbl: +61 (4)23 028 565 | Email: andreas.kiermeier@gmail.com
Australia
On 21 September 2014 01:36, Charles Berry <ccberry@ucsd.edu> wrote:
> Andreas Kiermeier <andreas.kiermeier <at> gmail.com> writes:
>
> >
> > On 19 September 2014 20:29, Rainer M Krug <Rainer <at> krugs.de> wrote:>
>
> [ snip ]
>
> >
> > The alternative mentioned by Chuck Berry is the xtable function (in R)
> > (https://lists.gnu.org/archive/html/emacs-orgmode/2014-09/msg00519.html
> ).
> > I just tried it and am happy to share that it does created the whole
> > output in one go, i.e. it does exactly what I need, including table
> > float, caption and label. Now I just got to sort out how to created the
> > tables without the use of tabular ...
> >
>
> I suggested xtable because that is what I often use.
>
> But thinking a bit more, I decided to look at tables::tabular() and
> at Hmisc::latex(), which I think is what you used at first.
>
> And it turns out that latex() has args for caption, label, where, and
> loads of other things. See its help page. So, it looks like you have the
> control you need and the ability to use
>
> latex( tabular(...), caption = <...>, label = <...>, ...)
>
> to good effect.
>
> HTH,
>
> Chuck
>
>
>
[-- Attachment #2: Type: text/html, Size: 3207 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2014-09-21 4:20 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-18 13:17 «Macro» expansion in source blocks; code-sharing between blocks Tobias Getzner
2014-09-18 13:26 ` Tobias Getzner
2014-09-18 14:01 ` Eric S Fraga
2014-09-18 14:40 ` Tobias Getzner
2014-09-18 23:44 ` Andreas Kiermeier
2014-09-19 2:59 ` Charles Berry
2014-09-19 10:18 ` Andreas Kiermeier
2014-09-19 7:44 ` Eric S Fraga
2014-09-19 9:04 ` Rainer M Krug
2014-09-19 10:19 ` Andreas Kiermeier
2014-09-19 10:59 ` header arguments, inheritance, and noweb expansion Was: " Rainer M Krug
2014-09-20 6:57 ` Andreas Kiermeier
2014-09-20 16:06 ` Charles Berry
2014-09-21 4:19 ` Andreas Kiermeier
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).