1

This is what I want to do:

In some-file.org:

* Table 1
#+NAME: table-1-title
Characteristcs of Data

#+BEGIN_SRC R :file table-1.svg :results output graphics file
  (
    ggplot(mtcars, aes(mpg, cyl))
    + geom_point()
  )
#+END_SRC

#+caption: > HERE I WANT TO USE THE table-1-title VAR DEFINED ABOVE <
#+attr_latex: :width 375px :placement [H]
#+RESULTS:

I want to use the table-1-title variable to set the caption. Any ideas?

  • 1
    I don't think there is an Org construct (like :var) to do that. You will likely need to use an Emacs Lisp variable, e.g. (set (make-local-variable 'foo) "value"). I would define these in a separate :noexport: section within an elisp source block. The difficulty is how to eval the variable on export. What have you tried? – Lorem Ipsum Apr 7 at 12:42
1

You can use src babel blocks for org like the following:

* Table 1
#+NAME: table-1-title
Characteristcs of Data

#+BEGIN_SRC R :file table-1.svg :results output graphics file
  (
    ggplot(mtcars, aes(mpg, cyl))
    + geom_point()
  )
#+END_SRC

#+name: result-file
#+RESULTS:
table-1.svg

#+begin_src org :results replace :var title=table-1-title file=result-file
#+caption: $title
#+attr_latex: :width 375px :placement [H]
$file
#+end_src

#+RESULTS:
#+caption: Characteristcs of Data
#+attr_latex: :width 375px :placement [H]
table-1.svg
| improve this answer | |
  • Ok I got it now. I have never thought of using an org block before. Please vote for my question so I can vote for your answer. My reputation is too low... – pietrodito May 11 at 9:15

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.