Emacs¶
Daniel Weschke
November 25, 2019
1 Org¶
function |
description |
|---|---|
org-table-convert-region |
convert text to org-mode table |
1.1 Table¶
1.1.1 Formulas¶
C-c }to turn on/off the reference visualization grid.C-c ?inside a field to get the references to the filed in different notations.org-table-recalculateC-c *recalculate the current table line.C-u C-c *recalculate all table lines.C-u C-u C-c *recompute the table until it no longer changes.C-c C-cif you’re on the#+TBLFMline.
org-table-eval-formulaC-c =for editing column formulas.C-u C-c =for editing field formulas.C-u C-u C-c =insert the active equation for the field back into the current field, so that it can be edited there.
C-c '(org-table-edit-formulas) edit the formulas of the current table in a separate buffer. Select a reference by using theS-<left/right/up/down>keys.To insert a field formula start with
:=To insert a column formula strat with
=
| Number 1 | Number 2 | Total | |
|----------+----------+-------+------|
| 1 | 2 | 3 | 3.00 |
| 3 | 4 | 7 | |
| | | 0 | |
| 5 | 6 | 11 | |
|----------+----------+-------+------|
| 3 | 2 | | |
#+TBLFM: @2$4..@-1$4=vsum($1..$2)::@6$1=vcount([@2$1..@-1$1])
#+TBLFM: @6$2=vcount(map(<if(gt(#1,3), 1, [])>,@2$2..@-1$2))
#+TBLFM: @2$4=vsum(@2$1..@2$2);%.2f
| binary | Total | |
|--------+-------+------------------------------------|
| 001 | | |
| 010 | 4 | where the 1st flag is set |
| 100 | 3 | where the 2nd flag is set |
| 101 | 3 | where the 3rd flag is set |
| 111 | 2 | where the 1st and 2nd flag are set |
| 110 | | |
#+TBLFM: @3$2=vcount(map(<if(eq(and(#1,100),100), 1, [])>,@2$1..@7$1))
#+TBLFM: @4$2=vcount(map(<if(eq(and(#1,010),010), 1, [])>,@2$1..@7$1))
#+TBLFM: @5$2=vcount(map(<if(eq(and(#1,001),001), 1, [])>,@2$1..@7$1))
#+TBLFM: @6$2=vcount(map(<if(eq(and(#1,110),110), 1, [])>,@2$1..@7$1))
| Number 1 | Number 2 | Total | |
|----------+----------+------------+----------|
| 1 m | 2 mm | m + 2 mm | 1.002 m |
| 3 mm | 4 m | 3 mm + 4 m | 4003. mm |
#+TBLFM: @2$3=vsum($1..$2)
#+TBLFM: @2$4=usimplify(vsum($1..$2))
#+TBLFM: @3$3=vsum($1..$2)
#+TBLFM: @3$4=usimplify(vsum($1..$2))
| Number 1 | Number 2 | Total | |
|----------+----------+---------------+---------------|
| 1 € | 2 € | #ERROR | #ERROR |
| 3 EUR | 4 EUR | 7 EUR | 7 EUR |
| 3 EUR | 4 USD | 3 EUR + 4 USD | 3 EUR + 4 USD |
#+TBLFM: @2$3=vsum($1..$2)
#+TBLFM: @2$4=usimplify(vsum($1..$2))
#+TBLFM: @3$3=vsum($1..$2)
#+TBLFM: @3$4=usimplify(vsum($1..$2))
#+TBLFM: @4$3=vsum($1..$2)
#+TBLFM: @4$4=usimplify(vsum($1..$2))
1.1.2 Manipulate result tables with elisp¶
see also https://www.gnu.org/software/emacs/manual/html_node/elisp/List-Elements.html
Example:
'(("something1" "something2") hline ("a" 1) ("b" 5) ("c" 100))
Result:
something1 |
something2 |
|---|---|
a |
1 |
b |
5 |
c |
100 |
Example:
(print table)
(print (car table))
(print (cdr table))
(("something1" "something2") ("a" 1) ("b" 5) ("c" 100))
("something1" "something2")
(("a" 1) ("b" 5) ("c" 100))
Result:
(("something1" "something2") ("a" 1) ("b" 5) ("c" 100))
("something1" "something2")
(("a" 1) ("b" 5) ("c" 100))
Example:
(print (cdr table))
a |
1 |
b |
5 |
c |
100 |
Result:
a |
1 |
b |
5 |
c |
100 |
1.1.3 Understanding the header :var with table data¶
as we might know:
#+begin_src elisp
'(("h" "a") hline ("l" "l") ("o"))
#+end_src
h |
a |
|---|---|
l |
l |
o |
but (:hlines yes does not change the result, but setting :colnames does, see
below)
#+begin_src elisp :var data='(("h" "a") hline ("l" "l") ("o"))
data
#+end_src
l |
l |
o |
because emacs cuts the table in header and content, but only if there is one
single hline below the first row, otherwise we get the full table.
#+begin_src elisp :var data='(("h" "a") ("l" "l") hline ("o"))
data
#+end_src
h |
a |
l |
l |
o |
setting :colnames (yes, no, nil) will print the whole table.
If :colnames is set to yes or nil then a header hline is shown.
If set to no then no header hline is shown.
All this is true if there is a hline after the first row or not.
#+begin_src elisp :var data='(("h" "a") hline ("l" "l") ("o")) :colnames no
data
#+end_src
h |
a |
l |
l |
o |
#+begin_src elisp :var data='(("h" "a") hline ("l" "l") ("o")) :colnames yes
data
#+end_src
h |
a |
|---|---|
l |
l |
o |
1.1.3.1 hlines¶
With :hlines yes also hline will be shown.
Note: Remember the special case with only one hline after the first row, see above.
#+begin_src elisp :var data='(("h" "a") hline ("l" "l") ("o") hline) :hlines yes
data
#+end_src
h |
a |
|---|---|
l |
l |
o |
we get the same result without hline after the first row and setting :colnames yes
#+begin_src elisp :var data='(("h" "a") ("l" "l") ("o") hline) :colnames yes :hlines yes
data
#+end_src
h |
a |
|---|---|
l |
l |
o |
1.1.3.2 hlines with other languages e. g. Python¶
To see how to write a table in other languages we print out an org table in the language we wish to create one.
A test table
#+NAME: test-table
| h | a |
|---+---|
| l | l |
| o | |
h |
a |
|---|---|
l |
l |
o |
A block to generate the output in another language, here e. g. in Python. The header settings
:colnames no- to get the full table, because of the hline after the first row:hlines yes- to get the hline logic, otherwise these are striped out:results value raw- to get the raw output and not the interpreted/processed output (a table):wrap example- put the output inside an example block
#+HEADER: :colnames no
#+HEADER: :hlines yes
#+HEADER: :results value raw
#+HEADER: :wrap example
#+BEGIN_SRC python :var tab=test-table
return tab
#+END_SRC
[['h', 'a'], None, ['l', 'l'], ['o', '']]
therefore
#+begin_src python :results value
return [
['H', 'A'],
None,
['L', 'L'],
["O"],
]
#+end_src
H |
A |
|---|---|
L |
L |
O |
1.2 columnview¶
See also: https://orgmode.org/worg/org-tutorials/org-column-view-tutorial.html and https://orgmode.org/org.html#Column-View
Two use cases
See an interactive column view inside emacs. To start the column view inside emacs press
C-c C-x C-cand exit withq.Generate a table with all the entries defined. To generate press
C-c C-con the#+BEGIN: columnviewline.
Predefined properties used in the :COLUMNS: property:
Property |
Description |
|---|---|
ITEM |
The content of the headline |
TODO |
The TODO keyword of the entry |
TAGS |
The tags defined directly in the headline |
ALLTAGS |
All tags, including inherited ones |
PRIORITY |
The priority of the entry, a string with a single letter |
DEADLINE |
The deadline time string, without the angular brackets |
SCHEDULED |
The scheduling time stamp, without the angular brackets |
Modifier for the elements of the :COLUMNS: property. This modifies the columns
of the interactive column view:
Element |
Description |
|---|---|
|
display ITEM |
|
display ITEM with 20 characters for this field |
|
display ITEM named as Item (title of the column) |
|
sums the numbers in this column |
|
sums the numbers formated with ’%.1f’ in this column |
|
sums the currency numbers in this column, short for ’+;%.2f’ |
|
smallest number in column |
|
largest number in column |
|
arithmetic mean of numbers in column |
|
sums the checked state |
|
sums the checked state |
|
sums the checked state |
|
sums the time values in column, HH:MM |
|
smallest time in column |
|
largest time in column |
|
arithmetic mean of time values in column |
|
minimum age in days / hours / mins / seconds. Child items e. g. |
|
maximum age in days / hours / mins / seconds. Child items e. g. |
|
arithmetic mean of ages in days / hours / mins / seconds. Child items e. g. |
|
add low-high estimates |
Add own summery types with org-columns-summery-type.
Example: generating table, not using predefined properties
* Header for the section with a columnview table
:PROPERTIES:
:ID: name_of_the_table
:COLUMNS: %NAME %12DESCRIPTION %12ANNOTATION(Annotation) %NUMBER(Nr.)
:NUMBER_ALL: 1 2 3 -
:END:
# This is a comment and the block below will have the content of all the entries.
# You may perform C-c C-c on the first line of the block to generate the result.
#+BEGIN: columnview :id "name_of_the_table" :skip-empty-rows t
#+END
** Header for first entry
:PROPERTIES:
:NAME: foo
:DESCRIPTION: blah
:NUMBER: 2
:END:
** Header for second entry
:PROPERTIES:
:NAME: baz
:ANNOTATION: blup
:NUMBER: -
:END:
** Header for third entry
Without properties, to pack some entry together, but without additional row in
the table.
*** Sub-header for third entry
:PROPERTIES:
:NAME: bar
:END:
** Header for fourth entry
:PROPERTIES:
:NAME: *name for group*
:DESCRIPTION: with possible group parameter
:END:
With properties, to pack some entry together.
*** Sub-header for fourth entry
:PROPERTIES:
:NAME: sub entry
:END:
Result inside Emacs:
#+BEGIN: columnview :id "name_of_the_table" :skip-empty-rows t
| NAME | DESCRIPTION | Annotation | Nr. |
|------------------+-------------------------------+------------+-----|
| foo | blah | | 2 |
| baz | | blup | - |
| bar | | | |
| *name for group* | with possible group parameter | | |
| sub entry | | | |
#+END
Result of html export:
NAME |
DESCRIPTION |
Annotation |
Nr. |
|---|---|---|---|
foo |
blah |
2 |
|
baz |
blup |
||
bar |
|||
name for group |
with possible group parameter |
||
sub entry |
1.3 Escape of org functions inside a org src block¶
To show an org example with an header (or other org functions) one has to escape the section header line with a comma.
Example:
#+begin_src org
,* my section
#+end_src
Result of export:
* my section
2 Org export¶
2.1 Colored text (HTML/LaTeX)¶
#+MACRO: color @@html:<font color="#$1">$2</font>@@@@latex:\textcolor[HTML]{$1}{$2}@@
# usage {{{color(cc333333,[restricted])}}}
2.2 Image links (HTML)¶
#+MACRO: imglnk @@html:<a href="$1"><img src="$2"></a>@@
# usage {{{imglnk(path-to-file,path-to-image)}}}
2.3 Disclosure widget / Expander (HTML)¶
LaTeX note: The text will be shown normally.
#+BEGIN_EXPORT html
<details>
<summary>header</summary>
#+END_EXPORT
blah
#+BEGIN_EXPORT html
</details>
#+END_EXPORT
header
blah
2.4 Citation marks (HTML/LaTeX)¶
Citation mark [[cite:Mason1956]] and [[cite:Bathe1986]], [[cite:Mises1913]].