emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] strategies for generating multiple graphics files from same code block
@ 2010-08-09 21:04 Erik Iverson
  2010-08-09 23:00 ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Erik Iverson @ 2010-08-09 21:04 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I'm using org-mode to write R code and generate figures.

I have multiple files generated per code block, one png and one PDF.
This is so that I can display the graphic:

1) Inline in my org-mode buffer (png)
2) Upon export to HTML, viewable in the browser (png)
3) Included in a separate PDF, *not* from exporting my org-mode
file.  For this, I would like a PDF version of the graphic to be
generated, and pdflatex can use it (pdf)

So, for points 1 and 2 above, no problem.

* Figure 1
Here is the first figure.

#+begin_src R :file figure1.png :width 960 :exports both :tangle fig1.R
   plot(1,1)
#+end_src

For point 3, I use tangling to write the source code to a file.  I 
notice that the graphical code is wrapped by the export process by a 
call to png() and dev.off().

My question, is there any facility to have the tangled code generate a 
PDF, instead of PNG?  I still need the png for goals 1 and 2, but the 
pdf for goal 3.  Anyone else have any other strategies for realizing all 
3 of my goals?

I suppose one would be to define a named code block, and use the noweb 
syntax:

Define the plot
#+srcname: fig-test
#+begin_src R
   plot(1,1)
#+end_src

Tangle, but don't export
#+begin_src R :file figure1.pdf :exports none :tangle fig1.R :noweb yes
  <<fig-test>>
#+end_src

Export, but don't tangle
#+begin_src R :file figure1.png :exports both :noweb yes
  <<fig-test>>
#+end_src

This is not too bad, but maybe there's an alternative approach?

Thanks!
Erik Iverson

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

* Re: [babel] strategies for generating multiple graphics files from same code block
  2010-08-09 21:04 [babel] strategies for generating multiple graphics files from same code block Erik Iverson
@ 2010-08-09 23:00 ` Eric Schulte
  2010-08-09 23:37   ` Erik Iverson
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2010-08-09 23:00 UTC (permalink / raw)
  To: Erik Iverson; +Cc: emacs-orgmode

Hi Erik,

There is a planned feature for Org-babel which should subsume these use
cases, namely backend-conditional header arguments.  These would allow
you to specify different header arguments (including file) depending on
the export target, be that html, latex, or none if you are just
interactively evaluating inside of an Org-mode buffer.

This is still in the early stages, and is waiting until I have a
reasonable amount of free time.

Cheers -- Eric

Erik Iverson <eriki@ccbr.umn.edu> writes:

> Hello,
>
> I'm using org-mode to write R code and generate figures.
>
> I have multiple files generated per code block, one png and one PDF.
> This is so that I can display the graphic:
>
> 1) Inline in my org-mode buffer (png)
> 2) Upon export to HTML, viewable in the browser (png)
> 3) Included in a separate PDF, *not* from exporting my org-mode
> file.  For this, I would like a PDF version of the graphic to be
> generated, and pdflatex can use it (pdf)
>
> So, for points 1 and 2 above, no problem.
>
> * Figure 1
> Here is the first figure.
>
> #+begin_src R :file figure1.png :width 960 :exports both :tangle fig1.R
>   plot(1,1)
> #+end_src
>
> For point 3, I use tangling to write the source code to a file.  I
> notice that the graphical code is wrapped by the export process by a
> call to png() and dev.off().
>
> My question, is there any facility to have the tangled code generate a
> PDF, instead of PNG?  I still need the png for goals 1 and 2, but the
> pdf for goal 3.  Anyone else have any other strategies for realizing
> all 3 of my goals?
>
> I suppose one would be to define a named code block, and use the noweb
> syntax:
>
> Define the plot
> #+srcname: fig-test
> #+begin_src R
>   plot(1,1)
> #+end_src
>
> Tangle, but don't export
> #+begin_src R :file figure1.pdf :exports none :tangle fig1.R :noweb yes
>  <<fig-test>>
> #+end_src
>
> Export, but don't tangle
> #+begin_src R :file figure1.png :exports both :noweb yes
>  <<fig-test>>
> #+end_src
>
> This is not too bad, but maybe there's an alternative approach?
>
> Thanks!
> Erik Iverson
>
> _______________________________________________
> 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] 5+ messages in thread

* Re: [babel] strategies for generating multiple graphics files from same code block
  2010-08-09 23:00 ` Eric Schulte
@ 2010-08-09 23:37   ` Erik Iverson
  2010-08-10 18:21     ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Erik Iverson @ 2010-08-09 23:37 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Sounds good, and perhaps another 'export' target could be tangling of the code.


On 08/09/2010 06:00 PM, Eric Schulte wrote:
> Hi Erik,
>
> There is a planned feature for Org-babel which should subsume these use
> cases, namely backend-conditional header arguments.  These would allow
> you to specify different header arguments (including file) depending on
> the export target, be that html, latex, or none if you are just
> interactively evaluating inside of an Org-mode buffer.
>
> This is still in the early stages, and is waiting until I have a
> reasonable amount of free time.
>
> Cheers -- Eric
>
> Erik Iverson<eriki@ccbr.umn.edu>  writes:
>
>> Hello,
>>
>> I'm using org-mode to write R code and generate figures.
>>
>> I have multiple files generated per code block, one png and one PDF.
>> This is so that I can display the graphic:
>>
>> 1) Inline in my org-mode buffer (png)
>> 2) Upon export to HTML, viewable in the browser (png)
>> 3) Included in a separate PDF, *not* from exporting my org-mode
>> file.  For this, I would like a PDF version of the graphic to be
>> generated, and pdflatex can use it (pdf)
>>
>> So, for points 1 and 2 above, no problem.
>>
>> * Figure 1
>> Here is the first figure.
>>
>> #+begin_src R :file figure1.png :width 960 :exports both :tangle fig1.R
>>    plot(1,1)
>> #+end_src
>>
>> For point 3, I use tangling to write the source code to a file.  I
>> notice that the graphical code is wrapped by the export process by a
>> call to png() and dev.off().
>>
>> My question, is there any facility to have the tangled code generate a
>> PDF, instead of PNG?  I still need the png for goals 1 and 2, but the
>> pdf for goal 3.  Anyone else have any other strategies for realizing
>> all 3 of my goals?
>>
>> I suppose one would be to define a named code block, and use the noweb
>> syntax:
>>
>> Define the plot
>> #+srcname: fig-test
>> #+begin_src R
>>    plot(1,1)
>> #+end_src
>>
>> Tangle, but don't export
>> #+begin_src R :file figure1.pdf :exports none :tangle fig1.R :noweb yes
>>   <<fig-test>>
>> #+end_src
>>
>> Export, but don't tangle
>> #+begin_src R :file figure1.png :exports both :noweb yes
>>   <<fig-test>>
>> #+end_src
>>
>> This is not too bad, but maybe there's an alternative approach?
>>
>> Thanks!
>> Erik Iverson
>>
>> _______________________________________________
>> 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] 5+ messages in thread

* Re: [babel] strategies for generating multiple graphics files from same code block
  2010-08-09 23:37   ` Erik Iverson
@ 2010-08-10 18:21     ` Eric Schulte
  2010-08-10 21:51       ` Dan Davison
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2010-08-10 18:21 UTC (permalink / raw)
  To: Erik Iverson; +Cc: emacs-orgmode

Hi Erik,

Given that arbitrary lisp forms can be used to assign header arguments,
the following can be used to achieve this functionality under the
current setup.

--8<---------------cut here---------------start------------->8---
#+Title: Export Target Conditional Header Arguments

The following generates an =.eps= image for LaTeX export and a =.png=
image for html export.
#+begin_src gnuplot :term (if (and (boundp 'latexp) latexp) "postscript" "png") :file (if (and (boundp 'latexp) latexp) "sin.eps" "sin.png")
  plot sin(x)
#+end_src
--8<---------------cut here---------------end--------------->8---

So, given that maybe the next development push for babel should focus on
the ability to break header arguments over multiple lines, rather than
on syntactic sugar for the above.

Cheers -- Eric

Erik Iverson <eriki@ccbr.umn.edu> writes:

> Sounds good, and perhaps another 'export' target could be tangling of the code.
>

The above does not address tangling, however this could be fixed by
having ob-tangle could set a tanglep global variable in the spirit of
htmlp and latexp.

>
>
> On 08/09/2010 06:00 PM, Eric Schulte wrote:
>> Hi Erik,
>>
>> There is a planned feature for Org-babel which should subsume these use
>> cases, namely backend-conditional header arguments.  These would allow
>> you to specify different header arguments (including file) depending on
>> the export target, be that html, latex, or none if you are just
>> interactively evaluating inside of an Org-mode buffer.
>>
>> This is still in the early stages, and is waiting until I have a
>> reasonable amount of free time.
>>
>> Cheers -- Eric
>>
>> Erik Iverson<eriki@ccbr.umn.edu>  writes:
>>
>>> Hello,
>>>
>>> I'm using org-mode to write R code and generate figures.
>>>
>>> I have multiple files generated per code block, one png and one PDF.
>>> This is so that I can display the graphic:
>>>
>>> 1) Inline in my org-mode buffer (png)
>>> 2) Upon export to HTML, viewable in the browser (png)
>>> 3) Included in a separate PDF, *not* from exporting my org-mode
>>> file.  For this, I would like a PDF version of the graphic to be
>>> generated, and pdflatex can use it (pdf)
>>>
>>> So, for points 1 and 2 above, no problem.
>>>
>>> * Figure 1
>>> Here is the first figure.
>>>
>>> #+begin_src R :file figure1.png :width 960 :exports both :tangle fig1.R
>>>    plot(1,1)
>>> #+end_src
>>>
>>> For point 3, I use tangling to write the source code to a file.  I
>>> notice that the graphical code is wrapped by the export process by a
>>> call to png() and dev.off().
>>>
>>> My question, is there any facility to have the tangled code generate a
>>> PDF, instead of PNG?  I still need the png for goals 1 and 2, but the
>>> pdf for goal 3.  Anyone else have any other strategies for realizing
>>> all 3 of my goals?
>>>
>>> I suppose one would be to define a named code block, and use the noweb
>>> syntax:
>>>
>>> Define the plot
>>> #+srcname: fig-test
>>> #+begin_src R
>>>    plot(1,1)
>>> #+end_src
>>>
>>> Tangle, but don't export
>>> #+begin_src R :file figure1.pdf :exports none :tangle fig1.R :noweb yes
>>>   <<fig-test>>
>>> #+end_src
>>>
>>> Export, but don't tangle
>>> #+begin_src R :file figure1.png :exports both :noweb yes
>>>   <<fig-test>>
>>> #+end_src
>>>
>>> This is not too bad, but maybe there's an alternative approach?
>>>
>>> Thanks!
>>> Erik Iverson
>>>
>>> _______________________________________________
>>> 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] 5+ messages in thread

* Re: [babel] strategies for generating multiple graphics files from same code block
  2010-08-10 18:21     ` Eric Schulte
@ 2010-08-10 21:51       ` Dan Davison
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Davison @ 2010-08-10 21:51 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Hi Erik,
>
> Given that arbitrary lisp forms can be used to assign header arguments,
> the following can be used to achieve this functionality under the
> current setup.
>
> #+Title: Export Target Conditional Header Arguments
>
> The following generates an =.eps= image for LaTeX export and a =.png=
> image for html export.
> #+begin_src gnuplot :term (if (and (boundp 'latexp) latexp) "postscript" "png") :file (if (and (boundp 'latexp) latexp) "sin.eps" "sin.png")
>   plot sin(x)
> #+end_src
>
> So, given that maybe the next development push for babel should focus on
> the ability to break header arguments over multiple lines, rather than
> on syntactic sugar for the above.

Alternatively, I believe we should be able to use sbe to put the elisp
code in blocks:

--8<---------------cut here---------------start------------->8---
#+begin_src gnuplot :term (sbe "get-image-type") :file (sbe "get-file-path")
  plot sin(x)
#+end_src

#+source: get-image-type
#+begin_src emacs-lisp
(if (and (boundp 'latexp) latexp) "postscript" "png")
#+end_src

#+source: get-file-path
#+begin_src emacs-lisp
(if (and (boundp 'latexp) latexp) "sin.eps" "sin.png")
#+end_src
--8<---------------cut here---------------end--------------->8---

As a matter of fact this currently fails on export with 'Invalid read
syntax: "#"', but that's a bug.

Dan

>
> Cheers -- Eric
>
> Erik Iverson <eriki@ccbr.umn.edu> writes:
>
>> Sounds good, and perhaps another 'export' target could be tangling of the code.
>>
>
> The above does not address tangling, however this could be fixed by
> having ob-tangle could set a tanglep global variable in the spirit of
> htmlp and latexp.
>
>>
>>
>> On 08/09/2010 06:00 PM, Eric Schulte wrote:
>>> Hi Erik,
>>>
>>> There is a planned feature for Org-babel which should subsume these use
>>> cases, namely backend-conditional header arguments.  These would allow
>>> you to specify different header arguments (including file) depending on
>>> the export target, be that html, latex, or none if you are just
>>> interactively evaluating inside of an Org-mode buffer.
>>>
>>> This is still in the early stages, and is waiting until I have a
>>> reasonable amount of free time.
>>>
>>> Cheers -- Eric
>>>
>>> Erik Iverson<eriki@ccbr.umn.edu>  writes:
>>>
>>>> Hello,
>>>>
>>>> I'm using org-mode to write R code and generate figures.
>>>>
>>>> I have multiple files generated per code block, one png and one PDF.
>>>> This is so that I can display the graphic:
>>>>
>>>> 1) Inline in my org-mode buffer (png)
>>>> 2) Upon export to HTML, viewable in the browser (png)
>>>> 3) Included in a separate PDF, *not* from exporting my org-mode
>>>> file.  For this, I would like a PDF version of the graphic to be
>>>> generated, and pdflatex can use it (pdf)
>>>>
>>>> So, for points 1 and 2 above, no problem.
>>>>
>>>> * Figure 1
>>>> Here is the first figure.
>>>>
>>>> #+begin_src R :file figure1.png :width 960 :exports both :tangle fig1.R
>>>>    plot(1,1)
>>>> #+end_src
>>>>
>>>> For point 3, I use tangling to write the source code to a file.  I
>>>> notice that the graphical code is wrapped by the export process by a
>>>> call to png() and dev.off().
>>>>
>>>> My question, is there any facility to have the tangled code generate a
>>>> PDF, instead of PNG?  I still need the png for goals 1 and 2, but the
>>>> pdf for goal 3.  Anyone else have any other strategies for realizing
>>>> all 3 of my goals?
>>>>
>>>> I suppose one would be to define a named code block, and use the noweb
>>>> syntax:
>>>>
>>>> Define the plot
>>>> #+srcname: fig-test
>>>> #+begin_src R
>>>>    plot(1,1)
>>>> #+end_src
>>>>
>>>> Tangle, but don't export
>>>> #+begin_src R :file figure1.pdf :exports none :tangle fig1.R :noweb yes
>>>>   <<fig-test>>
>>>> #+end_src
>>>>
>>>> Export, but don't tangle
>>>> #+begin_src R :file figure1.png :exports both :noweb yes
>>>>   <<fig-test>>
>>>> #+end_src
>>>>
>>>> This is not too bad, but maybe there's an alternative approach?
>>>>
>>>> Thanks!
>>>> Erik Iverson
>>>>
>>>> _______________________________________________
>>>> 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
>
> _______________________________________________
> 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] 5+ messages in thread

end of thread, other threads:[~2010-08-10 21:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-09 21:04 [babel] strategies for generating multiple graphics files from same code block Erik Iverson
2010-08-09 23:00 ` Eric Schulte
2010-08-09 23:37   ` Erik Iverson
2010-08-10 18:21     ` Eric Schulte
2010-08-10 21:51       ` Dan Davison

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