What could possibly preventing execution of code blocks upon export to pdf, if org-export-babel-evaluate is t? :results is set to silent on the relevant codeblock but I don't think that should affect execution upon export.

If I set :exports to results the file outputted by the code block is inserted at the end of the document.

If I set :exports to both the file is inserted correctly (ie where the link is), but then the codeblock is of course also inserted. Neither is useful as I would just like the file generated by the codeblock to be inserted at the location of the link.


#+begin_src clojure :var bc=case :colnames no :results silent :tangle ../src/roight/core.clj 
  (ns roight.core
    (:require [roight.org]

  (defn calc-bc [bc]
    (apply  #(- (* (+ %1 %2 %3) %5) (* %4 %5)) bc))

  (defn sample-business-case [case i]
    (map calc-bc (repeatedly i #(map roight.sim/sample case))))

  (let [business-case (roight.org/org-table->map bc)
        chart (incanter.charts/histogram (sample-business-case business-case 20000))]
    (incanter.core/view chart)
    (incanter.core/save chart "org/business-case.png"))
** Illustration
   #+CAPTION: Simulation of the business case
   #+NAME: fig:business_case_simulation

I am using Emacs and org-mode 8.3.2 on OSX.

Remark by Tobias: The effect described by mac cannot be reproduced with the html-file export of the following example using an emacs-lisp code block, emacs 24.3.1 and org-mode 8.3.2. The figure is shown between the first and the second sentence -- as it is expected. This rises the question whether the problem is clojure-specific.

#+begin_src emacs-lisp :exports results :results silent
(with-current-buffer (find-file-noselect "testsvg.svg")
  (delete-region (point-min) (point-max))
  (insert "<svg version=\"1.1\" baseProfile=\"full\" width=\"300\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">
  <rect width=\"100%\" height=\"100%\" fill=\"red\"/>
  <text x=\"150\" y=\"125\" font-size=\"60\" text-anchor=\"middle\">Test</text>
** Illustration
   The figure is placed below this first sentence.

   #+CAPTION: Simulation of the business case
   #+NAME: fig:business_case_simulation

   The figure is placed above this second sentence.
  • Please give a minimal example for reproducing the problem.
    – Tobias
    Jan 10, 2016 at 12:35
  • I have provided a minimal example reproducing the problem above.
    – mac
    Jan 10, 2016 at 14:30
  • The link to the image is currently the last element in your minimal example. Either, it is correct that the image is included at the end of the export or you should add a line at the end of the minimal example to demonstrate that the image is erroneously exported behind that line. Note also that an example using elisp would be better since it would work with on-board means. I do not know clojure. But, it looks like there are some unmet dependencies in your code, e.g., roight.sim -- but that is just a guess...
    – Tobias
    Jan 10, 2016 at 16:20
  • Note that you did not mention whereto you export. Do you export to LaTeX? Maybe, in this case the manual page orgmode.org/… could be relevant for you. It describes when exported source blocks become LaTeX floats and those can be shifted to the end of the document.
    – Tobias
    Jan 10, 2016 at 18:10
  • I've tried it with an emacs-lisp code block and added the test result to the question. (The code block does not fit into the comments.) Maybe, it spares someone trying to help you some work. Hope, you do not mind. If you do not like that you may delete my supplement.
    – Tobias
    Jan 10, 2016 at 18:59

2 Answers 2


When you export to PDF the intermediate format is LaTeX. In LaTeX images with captions are exported as floats. They are saved in a stack and placed into the text where they fit best in the sense of the optimization algorithm implemented in LaTeX.

You can avoid this with the LaTeX attribute :float set to nil. See the corresponding orgmode manual section "Images in LaTeX export".

In the following I give a modified version of the example that I have added to your question. There I did not yet know that you actually want to export to PDF. The new version of the example contains an emacs-lisp code block that produces a png image. This org file can be exported to PDF (via LaTeX). Please, note the #+ATTR_LATEX line.

#+begin_src emacs-lisp :exports results :results silent
(with-current-buffer (find-file-noselect "testpng.png")
  (delete-region (point-min) (point-max))
  (base64-decode-region (point-min) (point-max))
** Illustration
   The figure is placed below this first sentence.
   #+ATTR_LATEX: :float nil
   #+CAPTION: Simulation of the business case
   #+NAME: fig:business_case_simulation
   The figure is placed above this second sentence.

The following picture shows the pdf output with the :float attribute:

with :float attribute

The following picture shows the pdf output without the :float attribute:

without :float attribute


Since it inserts the result to the end of the document, I guess you might not have a #+RESULTS: tag after the code block. See some of the examles here http://orgmode.org/org.html#Header-arguments

  • I am not using the #+RESULTS tag because the code is generating an image and saving it to disk. If the same result is achievable using the #+RESULTS tag I would like to understand how.
    – mac
    Jan 10, 2016 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.