emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* using pdf as output of src-block doesn't show an inline image
@ 2016-02-06  5:48 Arun Persaud
  2016-02-08  2:27 ` Arun Persaud
  0 siblings, 1 reply; 2+ messages in thread
From: Arun Persaud @ 2016-02-06  5:48 UTC (permalink / raw)
  To: emacs-orgmode

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:<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:<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

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

* Re: using pdf as output of src-block doesn't show an inline image
  2016-02-06  5:48 using pdf as output of src-block doesn't show an inline image Arun Persaud
@ 2016-02-08  2:27 ` Arun Persaud
  0 siblings, 0 replies; 2+ messages in thread
From: Arun Persaud @ 2016-02-08  2:27 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: John Kitchin

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

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

end of thread, other threads:[~2016-02-08  2:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-06  5:48 using pdf as output of src-block doesn't show an inline image Arun Persaud
2016-02-08  2:27 ` Arun Persaud

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