Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting a value outside a table in emacs org-mode

Tags:

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)

like image 968
Yotam Avatar asked Dec 22 '11 09:12

Yotam


People also ask

How do I use Emacs Org mode?

To save the document, either press the save icon, or press C-x C-s, call it 1.org. Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores.

How do you make a table in Org mode?

The easiest way to create a table is to directly type the "|" character at the beginning of a line, or after any amount of white space. This will put you in the first field of an atomic table. Once you've finished editing this cell, you can jump to the next one by pressing TAB .

Does Org mode come with Emacs?

Emacs has included Org Mode as a major mode by default since 2006. Bastien Guerry is the current maintainer, in cooperation with an active development community. Since its success in Emacs, some other systems now provide functions to work with org files.

How do I create a table in Emacs?

To create a text-based table from scratch, type M-x table-insert . This command prompts for the number of table columns, the number of table rows, cell width and cell height.


1 Answers

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.

like image 134
Juancho Avatar answered Sep 20 '22 04:09

Juancho