emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel generated images and +ATTR_LATEX
@ 2013-10-23 18:32 Mark Edgington
  2013-10-23 20:50 ` Michael Gauland
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Edgington @ 2013-10-23 18:32 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]

Hello all,

I have noticed that it seems not possible to evaluate a babel block of code
which generates an image, and to have a #+ATTR_LATEX line exist which
immediately precedes the generated link to the image.  In other words, If
there's already a #+ATTR_LATEX line, I need to move it after the block is
evaluated, or else it doesn't immediately precede the generated link.

For example, if I have the following...

#+begin_src python :exports none :results file
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    fig=plt.figure(figsize=(3,2))
    plt.plot([1,3,2])
    fig.tight_layout()
    figname = '/tmp/myfig.jpg'
    plt.savefig(figname)
    return(figname) # return this to org-mode
#+end_src

#+RESULTS:
#+ATTR_LATEX: :float figure :placement [htb!] :width 0.38\textwidth

... when I evaluate the code-block, the image-link gets inserted directly
after the #+RESULTS line, and before the #+ATTR_LATEX line.  Without the
+ATTR_LATEX line, directly preceding the image-link, no image is inserted
into the PDF which is created when exporting via the latex-exporter.

So, it would be ideal if either:
 (1) #+ATTR_LATEX lines applied to whatever image link which appears next,
even if there are additional lines starting with # that are between the
image-link and the #+ATTR_LATEX line,
OR (2) when evaluating an org-babel block, the results were placed *after*
any #... lines that follow a #+RESULTS line.

Does this make sense, or am I possibly not understanding something about
how to make it so that I don't have to modify my document anywhere else
after I change and evaluate an org-babel block?  (currently I need to
relocate the #+ATTR_LATEX line any time I evaluate an image-generating
block)

I'm using the latest org-mode (8.2.1-117-gaff4f1).

Regards,

Mark

[-- Attachment #2: Type: text/html, Size: 2115 bytes --]

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

* Re: org-babel generated images and +ATTR_LATEX
  2013-10-23 18:32 org-babel generated images and +ATTR_LATEX Mark Edgington
@ 2013-10-23 20:50 ` Michael Gauland
  2013-10-24  2:30   ` Mark Edgington
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Gauland @ 2013-10-23 20:50 UTC (permalink / raw)
  To: emacs-orgmode

Mark,
I think you want to use named results. My images typically look something
like this:

   #+NAME: architecture
   #+HEADER: :exports results
   #+HEADER: :file (org-babel-temp-file "./figure-" ".eps")
   #+HEADER: :cache yes
   #+BEGIN_SRC plantuml
   ...
   #+END_SRC

   #+NAME: fig-architecture
   #+CAPTION: Overview of mini-me architecture.
   #+ATTR_LaTeX: :width \textwidth :placement [h!bt]
   #+RESULTS: architecture
  
[[file:c:/Users/mgauland/AppData/Local/Temp/babel-5988Tli/figure-5988XRB.eps]]

Does that help?

Kind Regards,
Mike

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

* Re: org-babel generated images and +ATTR_LATEX
  2013-10-23 20:50 ` Michael Gauland
@ 2013-10-24  2:30   ` Mark Edgington
  2013-10-24 20:14     ` Michael Gauland
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Edgington @ 2013-10-24  2:30 UTC (permalink / raw)
  To: emacs-orgmode

Hi Mike,

That does help -- when testing it, I found that the problem had more to do
with my header options than to do with the presence or absence of a #+NAME
line.  But still, with the header options I gave in my original example,
org-babel's behavior does seem strange (maybe buggy?) to me.  My working
code now looks like:

#+begin_src python :exports results :results file :eval no-export
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    fig=plt.figure(figsize=(3,2))
    plt.plot([1,3,2])
    fig.tight_layout()
    figname = '/tmp/myfig.jpg'
    plt.savefig(figname)
    return(figname) # return this to org-mode
#+end_src

#+ATTR_LATEX: :float figure :placement [htb!] :width 0.38\textwidth 
#+RESULTS:

Anyhow, something that wasn't clear to me about your example is how you make
the filename which is generated via org-babel-temp-file available for use
within the code-block?

Regards,

Mark

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

* Re: org-babel generated images and +ATTR_LATEX
  2013-10-24  2:30   ` Mark Edgington
@ 2013-10-24 20:14     ` Michael Gauland
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Gauland @ 2013-10-24 20:14 UTC (permalink / raw)
  To: emacs-orgmode

Mark Edgington <edgimar <at> gmail.com> writes:
> Anyhow, something that wasn't clear to me about your example is how you make
> the filename which is generated via org-babel-temp-file available for use
> within the code-block?

Babel takes care of that (plantuml interprets the :file argument as the name
of the file it should generate). I'm not sure the best way to get the file
name in to a Python block. You could probably pass the generated name in as
a :var parmater.

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

end of thread, other threads:[~2013-10-24 20:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 18:32 org-babel generated images and +ATTR_LATEX Mark Edgington
2013-10-23 20:50 ` Michael Gauland
2013-10-24  2:30   ` Mark Edgington
2013-10-24 20:14     ` Michael Gauland

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