3

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.

Example:

** CODE
#+begin_src clojure :var bc=case :colnames no :results silent :tangle ../src/roight/core.clj 
  (ns roight.core
    (:require [roight.org]
              [roight.sim]
              [incanter.core]
              [incanter.charts]
              [incanter.pdf]))

  (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"))
#+end_src
** Illustration
   #+CAPTION: Simulation of the business case
   #+NAME: fig:business_case_simulation
   [[./business-case.png]]

I am using Emacs 25.1.50.1 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>
</svg>")
  (save-buffer))
#+end_src
** Illustration
   The figure is placed below this first sentence.

   #+CAPTION: Simulation of the business case
   #+NAME: fig:business_case_simulation
   [[./testsvg.svg]]

   The figure is placed above this second sentence.
5
  • 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

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))
  (insert "iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA
B3RJTUUH4AEKFTYTnwLJxgAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAIU
SURBVFjD7Zc9y7JgFMfrmQpcBJF0aAuiaGkqHBpTiAqiTVdtst3l+griN7Dmlj5AQ6BN1ZJLBNFg
LyQU9AK9oPfwLA/V3VO31t1w/cfL6xx+wnXO+R+/4zi+z9Mf30cKYkEsiAWxXGDpus4wTDAYZBhG
1/U3cTl3pSjKxX1FUZzX6x6WYRg3/8QwjAezW5YlSRJBEARBSJJkWZYHWIIg3MQSBOGR1KZpXsea
pukWC8Owm1gYhj2SmmXZ61iWZX8ZC0GQ61gEQR6JvVeJpVLpqfMLFYvFBw+fq0SXT/5Vb8t9g3hJ
Jf6Vpmk0TQcCAZqmNU1z3iI/NM0QC2JBLIj1aqxer/drXN+1//l8TpJkpVLZbrceThXbttvttquZ
aFlWuVyORCKdTsc90Ol0qtfriUSCoqj1eu12VDcaDRzHeZ7f7XY/A1qtVgAAkiQ5juv3+944CMdx
FotFoVCIxWLdbvcpoOl0KooijuOiKI5GI282nwupqoqiKADgfD7/9/JkMuF5HsdxAMBsNvNyIbvW
eDzOZDKpVGo4HN7xtBzHhUIhAMByufR+T/yulGRZRlFUlmXbtv/9pOt6LpcLh8OyLLusX9/PwgaD
QTKZzGazpmnatt1sNimKikajqqoeDofXbtX3td/vq9UqSZLpdDoej9dqtePx+CmmudVqbTabfD7v
9/s9bPLQy0MsiAWxIBbEeru+AFjCnWMWvjgvAAAAAElFTkSuQmCC")
  (base64-decode-region (point-min) (point-max))
  (save-buffer))
#+end_src
** Illustration
   The figure is placed below this first sentence.
   #+ATTR_LATEX: :float nil
   #+CAPTION: Simulation of the business case
   #+NAME: fig:business_case_simulation
   [[./testpng.png]]
   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

0

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

1
  • 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, privacy policy and cookie policy

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