emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Arun Persaud <apersaud@lbl.gov>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: using pdf as output of src-block doesn't show an inline image
Date: Fri, 5 Feb 2016 21:48:21 -0800	[thread overview]
Message-ID: <56B58925.5050204@lbl.gov> (raw)

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

             reply	other threads:[~2016-02-06  5:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-06  5:48 Arun Persaud [this message]
2016-02-08  2:27 ` using pdf as output of src-block doesn't show an inline image Arun Persaud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56B58925.5050204@lbl.gov \
    --to=apersaud@lbl.gov \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).