From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: Re: LaTeX export figure width, when figure comes from python? Date: Sun, 31 Mar 2013 19:57:45 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8fb1ebe447da7d04d94145fa Return-path: Received: from eggs.gnu.org ([208.118.235.92]:45693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMS8G-00020J-Q9 for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 19:57:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMS8A-0002zj-IB for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 19:57:52 -0400 Received: from mail-ob0-x22e.google.com ([2607:f8b0:4003:c01::22e]:60862) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMS8A-0002zd-B0 for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 19:57:46 -0400 Received: by mail-ob0-f174.google.com with SMTP id 16so1509162obc.5 for ; Sun, 31 Mar 2013 16:57:45 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: John Hendy , Orgmode Mailing List --e89a8fb1ebe447da7d04d94145fa Content-Type: text/plain; charset=ISO-8859-1 [I can never get the reply-all thing down on this list! See below.] On Sun, Mar 31, 2013 at 7:02 PM, John Hendy wrote: > On Sun, Mar 31, 2013 at 11:03 AM, Gary Oberbrunner > wrote: > > > > On Fri, Mar 29, 2013 at 4:53 PM, John Hendy wrote: > >> > >> On Fri, Mar 29, 2013 at 3:16 PM, Gary Oberbrunner < > garyo@oberbrunner.com> > >> wrote: > >> > Now that python mode is working nicely, I'm generating lots of > graphics. > >> > > >> > #+BEGIN_SRC python :session MYpython :exports results :results file > >> > #... bunch of matplotlib stuff that produces /tmp/myfig.pdf > >> > '/tmp/myfig.pdf' > >> > #+END_SRC > >> > > >> > This works, and the LaTeX exporter includes /tmp/mfig.pdf: > >> > > >> > \includegraphics[width=.9\linewidth]{c:/tmp/myfig.pdf} > >> > > >> > My question is, is there any way to remove the width specifier? If > the > >> > figure were coming straight from org-mode source text, I could use > >> > #+ATTR_LaTeX (well actually maybe not, because there's no way to > >> > *remove* > >> > the width, but at least I could set it as desired.) But in the > >> > situation > >> > above, where the filename is coming from the exporter running the code > >> > block, there's no place for me to put the ATTR_LaTeX that works. > >> > > >> > Any ideas, exporter gurus? > >> > > >> > >> Does this post help at all? > >> - http://lists.gnu.org/archive/html/emacs-orgmode/2012-08/msg01225.html > >> > >> This would be if your compilation of that block is spitting out a > >> #+results block. Is that the case? > >> > >> Also, per a recent use of that same concept, I got updated advice to > >> use :wrap since the above wasn't working for me anymore: > >> - http://lists.gnu.org/archive/html/emacs-orgmode/2013-03/msg01599.html > >> > >> So, basically if you're generating plots, you can just print the > >> Org-mode include file syntax ([[filename.ext]]) into a results block > >> and should also be able to pass it the #+attr_latex stuff as well. > >> Something like: > >> > >> print("#+attr_latex: :width Xcm \n > >> [[filename.ext]]") > > > > > > That almost works. This does: > > > > #+name: fields_chart(labels=fields[,0], vals=fields[,1]) > > #+BEGIN_SRC python :session UDpython :exports results :results raw > > fname=do_hbar('/tmp/fields.pdf', (4,.9), vals, labels) # this creates > the > > actual plot in /tmp/fields.pdf > > "#+ATTR_LaTeX: :width 4in \n[[%s]]"%fname > > #+END_SRC > > > > Notes: > > * You have to use :results raw rather than :results org. The latter > > prepends a comma to the #+ATTR_LaTeX line, making it unusable. (Not sure > if > > that's a bug, or expected.) > > I wonder if that's similar to the question I asked as a followup to > the link I sent you to: > - https://lists.gnu.org/archive/html/emacs-orgmode/2013-03/msg01583.html > > > * In session mode, you can't use :results output because the python > > interpreter prompts also are output. But returning the string as above > > works fine. > > Did you try :wrap as well? I was having issues with :results org as > well and found out that the prior recommendation to use this was > updated to :wrap org instead... > I didn't try :wrap, but I did try :results wrap (which is what that post suggested) which did nothing different as far as I could tell. > Out of curiosity... is the "%s" syntax related to python > (unfamiliar)... just noticed how you did that and wondered if that was > via Org/emacs/babel or via python. > That's python syntax. Glad you found something that worked! > John > > > > > But now my graphics come out the right size! Thanks! > > > > -- > > Gary > -- Gary --e89a8fb1ebe447da7d04d94145fa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
[I can never get the reply-all thing down on this list! = =A0See below.]

On = Sun, Mar 31, 2013 at 7:02 PM, John Hendy <jw.hendy@gmail.com> wrote:
On S= un, Mar 31, 2013 at 11:03 AM, Gary Oberbrunner
<garyo@oberbrunner.com> = wrote:
>
> On Fri, Mar 29, 2013 at 4:53 PM, John Hendy <jw.hendy@gmail.com> wrote:
>>
>> On Fri, Mar 29, 2013 at 3:16 PM, Gary Oberbrunner <garyo@oberbrunner.com>
>> wrote:
>> > Now that python mode is working nicely, I'm generating lo= ts of graphics.
>> >
>> > #+BEGIN_SRC python :session MYpython :exports results :result= s file
>> > =A0 #... bunch of matplotlib stuff that produces /tmp/myfig.p= df
>> > =A0 '/tmp/myfig.pdf'
>> > #+END_SRC
>> >
>> > This works, and the LaTeX exporter includes /tmp/mfig.pdf: >> >
>> > \includegraphics[width=3D.9\linewidth]{c:/tmp/myfig.pdf}
>> >
>> > My question is, is there any way to remove the width specifie= r? =A0If the
>> > figure were coming straight from org-mode source text, I coul= d use
>> > #+ATTR_LaTeX (well actually maybe not, because there's no= way to
>> > *remove*
>> > the width, but at least I could set it as desired.) =A0But in= the
>> > situation
>> > above, where the filename is coming from the exporter running= the code
>> > block, there's no place for me to put the ATTR_LaTeX that= works.
>> >
>> > Any ideas, exporter gurus?
>> >
>>
>> Does this post help at all?
>> - http://lists.gnu.org/archive/html/emacs= -orgmode/2012-08/msg01225.html
>>
>> This would be if your compilation of that block is spitting out a<= br> >> #+results block. Is that the case?
>>
>> Also, per a recent use of that same concept, I got updated advice = to
>> use :wrap since the above wasn't working for me anymore:
>> - http://lists.gnu.org/archive/html/emacs= -orgmode/2013-03/msg01599.html
>>
>> So, basically if you're generating plots, you can just print t= he
>> Org-mode include file syntax ([[filename.ext]]) into a results blo= ck
>> and should also be able to pass it the #+attr_latex stuff as well.=
>> Something like:
>>
>> print("#+attr_latex: :width Xcm \n
>> [[filename.ext]]")
>
>
> That almost works. =A0This does:
>
> #+name: fields_chart(labels=3Dfields[,0], vals=3Dfields[,1])
> #+BEGIN_SRC python :session UDpython :exports results :results raw
> =A0 fname=3Ddo_hbar('/tmp/fields.pdf', (4,.9), vals, labels) #= this creates the
> actual plot in /tmp/fields.pdf
> =A0 "#+ATTR_LaTeX: :width 4in \n[[%s]]"%fname
> #+END_SRC
>
> Notes:
> =A0* You have to use :results raw rather than :results org. =A0The lat= ter
> prepends a comma to the #+ATTR_LaTeX line, making it unusable. (Not su= re if
> that's a bug, or expected.)

I wonder if that's similar to the question I asked as a fol= lowup to
the link I sent you to:
- https://lists.gnu.org/archive/html/emacs-orgmod= e/2013-03/msg01583.html

> =A0* In session mode, you can't use :results output because the py= thon
> interpreter prompts also are output. =A0But returning the string as ab= ove
> works fine.

Did you try :wrap as well? I was having issues with :results org as well and found out that the prior recommendation to use this was
updated to :wrap org instead...

I= didn't try :wrap, but I did try :results wrap (which is what that post= suggested) which did nothing different as far as I could tell.
=A0
Out of curiosity... is the "%s" syntax related to python
(unfamiliar)... just noticed how you did that and wondered if that was
via Org/emacs/babel or via python.

That's python syntax.=A0

Glad you found something that worked!
John

>
> But now my graphics come out the right size! =A0Thanks!
>
> --
> Gary



--
= Gary
--e89a8fb1ebe447da7d04d94145fa--