Re: [O] using pdf as output of src-block doesn't show an inline image

2016-02-07 Thread Arun Persaud
Hi

managed to get pdfs to display ;)

Here is what I added in my .emacs file:

(add-to-list 'image-type-file-name-regexps '("\\.pdf\\'" . imagemagick))
(add-to-list 'image-file-name-extensions "pdf")
(setq imagemagick-types-inhibit (remove 'PDF imagemagick-types-inhibit))
(setq org-image-actual-width 600)

This works for me, but I always need to run org-display-inline-images by
hand after I changed something in my python code. That is, the images
don't update automatically, which they did for pngs. Any idea why that is?

Another question I have now, is if the above code messes up other modes,
I guess there was/is a reason to inhibit pdfs with imagemagick. How do I
make the above changes only apply to org-mode buffers?

Arun



[O] using pdf as output of src-block doesn't show an inline image

2016-02-05 Thread Arun Persaud
Hi

I use org mode more and more to plot data using python source blocks. If
I create pngs, org mode will display these results as an inline image,
which is nice. Since I also export my org buffer via latex to pdf, it
would be nice to create pdf plots with python, so that I get vector
graphics in the pdf. This is easy to do in python's matplotlib, but once
I change to pdf output, the images don't get displayed inline in
org-mode anymore :( instead, I just get a file: link.

I had a quick look, but can't figure out how to enable this. Should be
relatively easy I would think, since emacs already can display pdfs and
right-clicking on the file: link will open a new frame with the
pdf. Is there any reason not to display them inline?

The closest I found is:
http://stackoverflow.com/questions/15407485/inline-pdf-images-in-org-mode

If it is not that easy, is there a way to run a pre-export and
post-export hook that changes my *.png files to *pdf before the export
and then changes them back to *.png after the export?

Here is a test file



#+STARTUP: inlineimages

* test

#+NAME: checkfilename
#+HEADER: :var fileout="test--checkfilename.pdf"
#+BEGIN_SRC python :session :results file
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
X = np.linspace(1, 10)
Y = np.sin(X)
ax.plot(X, Y)
fig.savefig(fileout)
plt.close(fig)
fileout
#+END_SRC

-

to create a png, just replace the .pdf in the HEADER with .png


this uses ipython and cpaste
---

; use ipython in org mode
(setq org-babel-python-command "ipython3 --no-banner --classic
--no-confirm-exit")

; use %cpaste to paste code into ipython in org mode
(defadvice org-babel-python-evaluate-session
  (before org-python-use-cpaste
  (session body &optional result-type result-params) activate)
  "Add a %cpaste and '--' to the body, so that ipython does the right
thing."
  (setq body (concat "%cpaste -q\n" body "\n--")))

---

Arun