emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Generated images in buffer
@ 2010-11-28  7:04 Dov Grobgeld
  2010-11-28  7:34 ` Jeff Horn
  0 siblings, 1 reply; 7+ messages in thread
From: Dov Grobgeld @ 2010-11-28  7:04 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1133 bytes --]

I'm still feel quite a newbie to org-mode and I've been looking for a way to
include "dependent" images within the emacs buffer, but I still haven't
found it.

As an example, assume that I have manully created a diagram with ditaa code,
and once I am finishede diting  I'd like to press a keystroke e.g. Ctrl-C
Ctrl-C and have the contents change to the generated output image, and the
ditaa code will be hidden. When subsequently navigating to the image there
should be some indicator that this is a generated image and some keystroke
should allow turning the image back to its source code.

The same idea could be used for any system generating images, e.g. LaTeX
formulas, asymptote, a python script using cairo, etc.

Similarly if the source code is svg I might not want to display the source
code at all (which might be large), but would like to invoke inkscape to
edit the svg data. This is better done by referencing the svg as an external
image, instead of having it inline, but I would still like to easily invoke
an editor application from within emacs with a simple keystroke.

So is this currently possible?

Thanks,
Dov

[-- Attachment #1.2: Type: text/html, Size: 1235 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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] 7+ messages in thread

* Re: Generated images in buffer
  2010-11-28  7:04 Generated images in buffer Dov Grobgeld
@ 2010-11-28  7:34 ` Jeff Horn
  2010-11-28  8:11   ` Dov Grobgeld
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff Horn @ 2010-11-28  7:34 UTC (permalink / raw)
  To: Dov Grobgeld; +Cc: emacs-orgmode

On Sun, Nov 28, 2010 at 2:04 AM, Dov Grobgeld <dov.grobgeld@gmail.com> wrote:
> The same idea could be used for any system generating images, e.g. LaTeX
> formulas, asymptote, a python script using cairo, etc.

I think evaluating Babel code blocks can insert output into your org-file.

Also, I regularly use =C-c C-x C-l= to display rendered LaTeX
equations in-buffer. That keystroke only displays the current
subtree's equations. With a prefix, it will generate previews for the
entire document.

Best,
Jeff

-- 
Jeffrey Horn
Graduate Lecturer and PhD Student in Economics
George Mason University

(704) 271-4797
jhorn@gmu.edu
jrhorn424@gmail.com

http://www.failuretorefrain.com/jeff/

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

* Re: Generated images in buffer
  2010-11-28  7:34 ` Jeff Horn
@ 2010-11-28  8:11   ` Dov Grobgeld
  2010-11-28 14:46     ` Eric Schulte
  0 siblings, 1 reply; 7+ messages in thread
From: Dov Grobgeld @ 2010-11-28  8:11 UTC (permalink / raw)
  To: Jeff Horn; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1001 bytes --]

Thanks! So it possible for LaTeX, but not for other image generators. That's
a bit unfair. How difficult would it be to generalize this so that it would
support any image generator?

Regards,
Dov

On Sun, Nov 28, 2010 at 09:34, Jeff Horn <jrhorn424@gmail.com> wrote:

> On Sun, Nov 28, 2010 at 2:04 AM, Dov Grobgeld <dov.grobgeld@gmail.com>
> wrote:
> > The same idea could be used for any system generating images, e.g. LaTeX
> > formulas, asymptote, a python script using cairo, etc.
>
> I think evaluating Babel code blocks can insert output into your org-file.
>
> Also, I regularly use =C-c C-x C-l= to display rendered LaTeX
> equations in-buffer. That keystroke only displays the current
> subtree's equations. With a prefix, it will generate previews for the
> entire document.
>
> Best,
> Jeff
>
> --
> Jeffrey Horn
> Graduate Lecturer and PhD Student in Economics
> George Mason University
>
> (704) 271-4797
> jhorn@gmu.edu
> jrhorn424@gmail.com
>
> http://www.failuretorefrain.com/jeff/
>

[-- Attachment #1.2: Type: text/html, Size: 1596 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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] 7+ messages in thread

* Re: Generated images in buffer
  2010-11-28  8:11   ` Dov Grobgeld
@ 2010-11-28 14:46     ` Eric Schulte
  2010-11-28 17:27       ` Dan Davison
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2010-11-28 14:46 UTC (permalink / raw)
  To: Dov Grobgeld; +Cc: Jeff Horn, emacs-orgmode

You can place the ditaa code into a code block and then evaluate the
code block with C-c C-c.  This will insert a link to the generated image
into your Org-mode file.  If you then turn on inline images with M-x
org-toggle-inline-images you can preview the generated image from within
your Org-mode buffer.

For more information on code blocks see
http://orgmode.org/manual/Working-With-Source-Code.html#Working-With-Source-Code

Best -- Eric

Dov Grobgeld <dov.grobgeld@gmail.com> writes:

> Thanks! So it possible for LaTeX, but not for other image generators. That's
> a bit unfair. How difficult would it be to generalize this so that it would
> support any image generator?
>
> Regards,
> Dov
>
> On Sun, Nov 28, 2010 at 09:34, Jeff Horn <jrhorn424@gmail.com> wrote:
>
>> On Sun, Nov 28, 2010 at 2:04 AM, Dov Grobgeld <dov.grobgeld@gmail.com>
>> wrote:
>> > The same idea could be used for any system generating images, e.g. LaTeX
>> > formulas, asymptote, a python script using cairo, etc.
>>
>> I think evaluating Babel code blocks can insert output into your org-file.
>>
>> Also, I regularly use =C-c C-x C-l= to display rendered LaTeX
>> equations in-buffer. That keystroke only displays the current
>> subtree's equations. With a prefix, it will generate previews for the
>> entire document.
>>
>> Best,
>> Jeff
>>
>> --
>> Jeffrey Horn
>> Graduate Lecturer and PhD Student in Economics
>> George Mason University
>>
>> (704) 271-4797
>> jhorn@gmu.edu
>> jrhorn424@gmail.com
>>
>> http://www.failuretorefrain.com/jeff/
>>
> _______________________________________________
> 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] 7+ messages in thread

* Re: Generated images in buffer
  2010-11-28 14:46     ` Eric Schulte
@ 2010-11-28 17:27       ` Dan Davison
  2010-11-28 20:43         ` Dov Grobgeld
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Davison @ 2010-11-28 17:27 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Dov Grobgeld, Jeff Horn, emacs-orgmode

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

> You can place the ditaa code into a code block and then evaluate the
> code block with C-c C-c.  This will insert a link to the generated image
> into your Org-mode file.  If you then turn on inline images with M-x
> org-toggle-inline-images you can preview the generated image from within
> your Org-mode buffer.

Hi Dov,

Following on from the above, you can make the images in the emacs buffer
automatically refresh[1] after execution with

(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)

Dan


Footnotes:

[1] On reading the docstring, one might think that this would be the
right code, but it doesn't seem to refresh the image:

  (add-hook 'org-babel-after-execute-hook
            (lambda () (org-display-inline-images nil t)))




>
> For more information on code blocks see
> http://orgmode.org/manual/Working-With-Source-Code.html#Working-With-Source-Code
>
> Best -- Eric
>
> Dov Grobgeld <dov.grobgeld@gmail.com> writes:
>
>> Thanks! So it possible for LaTeX, but not for other image generators. That's
>> a bit unfair. How difficult would it be to generalize this so that it would
>> support any image generator?
>>
>> Regards,
>> Dov
>>
>> On Sun, Nov 28, 2010 at 09:34, Jeff Horn <jrhorn424@gmail.com> wrote:
>>
>>> On Sun, Nov 28, 2010 at 2:04 AM, Dov Grobgeld <dov.grobgeld@gmail.com>
>>> wrote:
>>> > The same idea could be used for any system generating images, e.g. LaTeX
>>> > formulas, asymptote, a python script using cairo, etc.
>>>
>>> I think evaluating Babel code blocks can insert output into your org-file.
>>>
>>> Also, I regularly use =C-c C-x C-l= to display rendered LaTeX
>>> equations in-buffer. That keystroke only displays the current
>>> subtree's equations. With a prefix, it will generate previews for the
>>> entire document.
>>>
>>> Best,
>>> Jeff
>>>
>>> --
>>> Jeffrey Horn
>>> Graduate Lecturer and PhD Student in Economics
>>> George Mason University
>>>
>>> (704) 271-4797
>>> jhorn@gmu.edu
>>> jrhorn424@gmail.com
>>>
>>> http://www.failuretorefrain.com/jeff/
>>>
>> _______________________________________________
>> 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] 7+ messages in thread

* Re: Generated images in buffer
  2010-11-28 17:27       ` Dan Davison
@ 2010-11-28 20:43         ` Dov Grobgeld
  2010-11-28 22:34           ` Dan Davison
  0 siblings, 1 reply; 7+ messages in thread
From: Dov Grobgeld @ 2010-11-28 20:43 UTC (permalink / raw)
  To: Dan Davison; +Cc: Jeff Horn, emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1523 bytes --]

Thanks! This is exactly what I was looking for. And indeed it is as easy to
output a graph from python (or any other language) as it is from ditaa:

* A ditaa image
#+begin_src ditaa :file example.png
+---------+
| cBLU    |
|         |
|    +----+
|    |cPNK|
|    |    |
+----+----+
#+end_src

#+results:
[[file:example.png]]
* A Python image
#+begin_src python :file circle.png
import cairo,math, os

width, height = 256,256
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context (surface)
ctx.set_source_rgb(0,0,0)
ctx.rectangle(0,0,width,height)
ctx.fill()
ctx.set_source_rgb(1,1,1)
ctx.move_to(width/2,height/2)
ctx.arc(width/2,height/2,width*0.25,0,math.pi*2)
ctx.fill()
surface.write_to_png("circle.png")
#+end_src

#+results:

[[file:circle.png]]

* A matplotlib graph from http://matplotlib.sourceforge.net

#+begin_src python :file graph.png
from pylab import *

t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, linewidth=1.0)

xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
savefig("graph.png",dpi=50)
#+end_src

#+results:

[[file:graph.png]]

I'm wondering over one thing though. When exporting to HTML, the ditaa
source code is omitted, but the python source code is included. Is there any
way of controlling this in begin_src?

Thanks!
Dov


On Sun, Nov 28, 2010 at 19:27, Dan Davison <dandavison7@gmail.com> wrote:

>  (add-hook 'org-babel-after-execute-hook
>            (lambda () (org-display-inline-images nil t)))
>

[-- Attachment #1.2: Type: text/html, Size: 7070 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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] 7+ messages in thread

* Re: Generated images in buffer
  2010-11-28 20:43         ` Dov Grobgeld
@ 2010-11-28 22:34           ` Dan Davison
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Davison @ 2010-11-28 22:34 UTC (permalink / raw)
  To: Dov Grobgeld; +Cc: Jeff Horn, emacs-orgmode

Dov Grobgeld <dov.grobgeld@gmail.com> writes:

> Thanks! This is exactly what I was looking for. And indeed it is as easy to
> output a graph from python (or any other language) as it is from ditaa:
>
> * A ditaa image
> #+begin_src ditaa :file example.png

[...]

> * A Python image
> #+begin_src python :file circle.png

[...]

> I'm wondering over one thing though. When exporting to HTML, the ditaa
> source code is omitted, but the python source code is included. Is there any
> way of controlling this in begin_src?

Hi Dov,

Yes, see the documentation of the :exports header argument.

http://orgmode.org/manual/Exporting-code-blocks.html#Exporting-code-blocks

Header arguments such as :exports can be set in various different ways.

http://orgmode.org/manual/Using-header-arguments.html#Using-header-arguments

The difference in behavior you see stems from the value of the variable
org-babel-default-header-args, and the language-specific versions of
that variable. Note below that although :exports in general defaults to
"code", for ditaa this default is overridden to "results". The reason
for which was that ditaa code is typically going to be there to generate
graphics, whereas that is only occasionally true for python.

#+begin_src emacs-lisp :results pp
org-babel-default-header-args
#+end_src

#+results:
: ((:session . "none")
:  (:results . "replace")
:  (:exports . "code")
:  (:cache . "no")
:  (:noweb . "no")
:  (:hlines . "no")
:  (:tangle . "no"))

#+begin_src emacs-lisp :results pp
org-babel-default-header-args:ditaa
#+end_src

#+results:
: ((:results . "file")
:  (:exports . "results"))

#+begin_src emacs-lisp :results pp
org-babel-default-header-args:python
#+end_src

#+results:
: nil


Dan


>
> Thanks!
> Dov
>
>
> On Sun, Nov 28, 2010 at 19:27, Dan Davison <dandavison7@gmail.com> wrote:
>
>>  (add-hook 'org-babel-after-execute-hook
>>            (lambda () (org-display-inline-images nil t)))
>>
> _______________________________________________
> 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] 7+ messages in thread

end of thread, other threads:[~2010-11-28 22:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-28  7:04 Generated images in buffer Dov Grobgeld
2010-11-28  7:34 ` Jeff Horn
2010-11-28  8:11   ` Dov Grobgeld
2010-11-28 14:46     ` Eric Schulte
2010-11-28 17:27       ` Dan Davison
2010-11-28 20:43         ` Dov Grobgeld
2010-11-28 22:34           ` Dan Davison

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