Yotam
Yotam

Reputation: 10685

getting a value outside a table in emacs org-mode

Suppose I have a table created by org-mode

| thing | value |
| t1    | 1     |
| t2    | 3     |
| t3    |  21   |
|-------+-------|
| total | 25    |

Is there a way inside org mode document to get the value from the total value cell in the table? (apart from manually copy the value)

Upvotes: 8

Views: 1291

Answers (1)

Juancho
Juancho

Reputation: 7372

The following post addresses your same question: http://permalink.gmane.org/gmane.emacs.orgmode/28056

You should name your table first, then refer to it via an inline src call:

#+TBLNAME: test-table
| thing | value |
|-------+-------|
| t1    | 1     |
| t2    | 3     |
| t3    |  21   |
|-------+-------|
| total | 25    |

The result I wanted is src_emacs-lisp[:var d=test-table[6,1]]{d}

Explanation: you call a very trivial elisp inline source block that only prints the variable d, which was assigned to an element in the table.

If you want the second column of the last row, you can try:

The result I wanted is src_emacs-lisp[:var tbl=test-table]{(nth 1 (nth (- (length tbl) 1) tbl))}

Where the 1 gets the 2nd item, and the (- (length tbl) 1) gets the last row (note that this last example is not purist LISP, just works).

Here we get the complete table into elisp (as a list of lists), and extract the desired item through list manipulation.

Note that the actual result will be substituted during export. You won't see it magically in the org-mode text itself.

Upvotes: 9

Related Questions