Reputation: 51
Suppose I have a these properties defined:
:PROPERTIES:
:a: 1
:b: 2
:END:
How do I define a property c such that the value is the sum of the value of property a
and the value of property b
? I have tried :c: (+ a b)
but the value of c is just the string "(+ a b)"
.
Is it possible to define a property in this way or do I have to have a code-block that is then evaluated? (Using the Properties API for instance)
Upvotes: 5
Views: 683
Reputation: 31
You could define a code block which executes on export, using the Property API:
* Code
#+NAME: PropertyCalculator
#+BEGIN_SRC emacs-lisp
(let* ( (rootval (string-to-number (org-entry-get nil "root")))
(squareval (number-to-string (* rootval rootval))) )
(org-entry-put nil "square" squareval)
)
#+END_SRC
* Content
** Property Data
:PROPERTIES:
:root: 2
:square: 5
:END:
#+CALL: PropertyCalculator()
This would leave any existing entry in place in the buffer, but overwrite in the export.
You could also correct in-buffer with (org-babel-load-file).
Upvotes: 1