docs/manual/guide/10-tables.org

fb3b538d8bb007da66099e27e5c2e4310e51dd08
orgstar/docs/manual/guide/10-tables.org

775 lines · 48117 bytes

  1#+TITLE: Tables
  2#+DESCRIPTION: Creating and editing Org tables, column widths, import and export, and spreadsheet formulas.
  3#+LEDE: Org tables are plain text that orgstar keeps aligned, edits by row and column, and recalculates with the same formulas Emacs uses.
  4
  5* Tables in Org
  6
  7A table is a run of lines that start with =|=. Fields are separated by =|=, and a line
  8that starts with =|-= is a horizontal rule:
  9
 10#+BEGIN_SRC org
 11| Name  | Qty | Price |
 12|-------+-----+-------|
 13| Apple |   3 |  0.50 |
 14| Pear  |  12 |  0.75 |
 15#+END_SRC
 16
 17orgstar follows =org-table.el= from Org 9.8.7, with =org-table-automatic-realign= on,
 18=org-table-tab-jumps-over-hlines= on, and formulas adjusted without asking when rows
 19and columns move (=org-table-fix-formulas-confirm= nil). Tables inside dynamic blocks
 20count as tables; tables inside other blocks don't.
 21
 22* Creating a table
 23
 24Type =|=, a few field names separated by =|=, and press =TAB=: orgstar aligns the line
 25as a table and moves to the next field, adding a row after the last one. Type =|-= on
 26the line below a row and press =TAB= to turn it into a full-width rule.
 27
 28=org-table-create-or-convert-from-region= builds one for you: ~C-c |~ in the Emacs
 29and Doom presets, =⌃⌘\= in the Mac preset.
 30
 31With no selection it asks =Table size Columns x Rows [e.g. 5x2]:=. An empty answer
 32makes a 5 × 2 table. When there is more than one row, a rule follows the first row.
 33
 34With text selected, the command converts the selected lines to a table instead
 35(=org-table-convert-region=). The separator is guessed:
 36
 37- tabs, when every line has a tab;
 38- otherwise commas, when every line has a comma, read as CSV: a field in double quotes
 39  can hold commas, and a line break in it becomes a space;
 40- otherwise runs of spaces.
 41
 42* Moving around and alignment
 43
 44| Key     | Org command                | Action                                                                     |
 45|---------+----------------------------+----------------------------------------------------------------------------|
 46| =TAB=   | =org-table-next-field=     | Aligns the table and moves to the next field, skipping rules. In the last field it adds a row. |
 47| =S-TAB= | =org-table-previous-field= | Aligns the table and moves to the previous field.                         |
 48| =RET=   | =org-table-next-row=       | Aligns the table and moves down a row in the same column. Before a rule or at the end of the table it inserts a row. |
 49
 50These keys work the same in the Emacs and Mac presets. In Doom they apply in insert
 51state; in normal state =RET= is Doom's "act at point" (see /Recalculating/).
 52
 53Alignment (=org-table-align=) pads every field to its column's width and redraws
 54rules to match. A column is right-aligned when at least half of its non-empty fields
 55are numbers, and left-aligned otherwise. A field that holds only a cookie =<l>=, =<c>=
 56or =<r>= (optionally with a width, such as =<r10>=) fixes the column's alignment.
 57Widths count display columns, so wide characters and hidden link markup are measured
 58as they appear.
 59
 60Alignment happens when you press =TAB=, =S-TAB= or =RET= in a table and after every
 61table command, not while you type. To align without moving, use Org ▸ Align Table:
 62
 63| Preset | Key                          |
 64|--------+------------------------------|
 65| Emacs  | =C-c C-c= in a table         |
 66| Mac    | =⌃⌘X= in a table             |
 67| Doom   | =C-c C-c=, or =SPC m b a=    |
 68
 69=C-c C-c= (Mac =⌃⌘X=) in a table is =org-ctrl-c-ctrl-c=, as in Emacs. It first evaluates a formula
 70typed in the current field (see /Entering formulas/). Then, in a row marked =#= (see
 71/Names, parameters and constants/), it recalculates that row, which also aligns the
 72table; in any other row it aligns the table. With the caret at the table's very first
 73character, it recalculates the whole table instead.
 74
 75To align every table when a file opens, set =org-startup-align-all-tables= to =true=
 76in the config file (default =false=), or put =#+STARTUP: align= in the file;
 77=#+STARTUP: noalign= turns it off for that file. See
 78[[file:13-configuration.org][Configuration]].
 79
 80* Editing rows and columns
 81
 82| Action                            | Org command                | Emacs          | Mac         | Doom                          |
 83|-----------------------------------+----------------------------+----------------+-------------+-------------------------------|
 84| Move row up                       | =org-table-move-row-up=    | =M-<up>=       | =⌃⌘↑=       | =M-<up>=, =M-k=               |
 85| Move row down                     | =org-table-move-row-down=  | =M-<down>=     | =⌃⌘↓=       | =M-<down>=, =M-j=             |
 86| Move column left                  | =org-table-move-column-left= | =M-<left>=   | =⌃⌘←=       | =M-<left>=, =M-h=             |
 87| Move column right                 | =org-table-move-column-right= | =M-<right>= | =⌃⌘→=       | =M-<right>=, =M-l=            |
 88| Insert column                     | =org-table-insert-column=  | =M-S-<right>=  | =⌃⌥⌘→=      | =M-S-<right>=, =SPC m b i c=  |
 89| Delete column                     | =org-table-delete-column=  | =M-S-<left>=   | =⌃⌥⌘←=      | =M-S-<left>=, =SPC m b d c=   |
 90| Insert row above                  | =org-table-insert-row=     | =M-S-<down>=   | =⌃⌥⌘↓=      | =M-S-<down>=, =SPC m b i r=   |
 91| Delete row                        | =org-table-kill-row=       | =M-S-<up>=     | =⌃⌥⌘↑=      | =M-S-<up>=, =SPC m b d r=     |
 92| Insert rule below                 | =org-table-insert-hline=   | =C-c -=        | =⌃⌘-=       | =C-c -=, =SPC m b -=, =SPC m b i h= |
 93| Sort rows                         | =org-table-sort-lines=     | =C-c ^=        | =⌃⇧⌘S=      | =C-c ^=            |
 94| Transpose                         | =org-table-transpose-table-at-point= | Org ▸ Transpose Table | Org ▸ Transpose Table | Org ▸ Transpose Table |
 95| Edit field in its own editor      | =org-table-edit-field=     | =C-c `=        | Org ▸ Edit Table Field | =C-c `=            |
 96
 97The new column goes to the left of the caret's column, empty. Deleting a row deletes
 98the line; it doesn't go to the clipboard. When rows and columns move, are inserted or
 99are deleted, the =#+TBLFM= line is updated to match: references are renumbered, and
100formulas for a deleted row or column are removed.
101
102The Mac preset uses the same keys for headings and list items; in a table they act on
103the table.
104
105** Sorting
106
107=C-c ^= in a table asks =Sort Table: [a]lphabetic, [n]umeric, [t]ime.  A/N/T means
108reversed:= and sorts the rows between the rules around the caret by the caret's
109column. If the caret isn't in a field, it asks for the column first. Sorting is stable.
110
111- *a* compares text without case.
112- *n* compares the number at the start of each field.
113- *t* compares a timestamp in the field, else a duration such as =1:30= or =2h 15min=,
114  else a clock time =H:MM=. Fields with none of these sort as 0.
115
116** Transposing
117
118Org ▸ Transpose Table swaps rows and columns. Rules are dropped.
119
120** The field editor
121
122=C-c `= opens the field at the caret in an editor of its own, which is easier for long
123text. =C-c '= or =⌘Return= puts it back; =Escape= or =C-c C-k= leaves it unchanged.
124Line breaks become single spaces and lines that start with =#= are dropped, as
125=org-table-finish-edit-field= does.
126
127* Narrow columns
128
129A field that holds a width cookie =<N>=, optionally with an alignment letter
130(=<l10>=, =<c8>=, =<r12>=), marks the column for narrowing. Narrowed fields show their
131first /N/ display columns followed by =…=. The text itself is unchanged.
132
133| Command                                  | Org command                       | Keys                                     |
134|------------------------------------------+-----------------------------------+------------------------------------------|
135| Org ▸ Shrink or Expand Table Column      | =org-table-toggle-column-width=   | Emacs and Doom =C-c TAB=                 |
136| Org ▸ Shrink Table Columns with Widths   | =org-table-shrink=                | No default key                           |
137| Org ▸ Expand Table Columns               | =org-table-expand=                | No default key                           |
138
139=C-c TAB= in a field toggles that column. Outside a column, for example on the leading
140=|=, it asks for =Column ranges (e.g. 2-4 6-):=, where =6-= means column 6 to the end.
141A column without a width cookie shrinks to a bare =…= when toggled. Typing in a narrowed
142field widens its column again, as editing Org's overlays does. =#+STARTUP: shrink=
143narrows every column with a width cookie when the file opens.
144
145The iOS editor narrows columns the same way, with =#+STARTUP: shrink= and the three
146commands, which are in Commands when the caret is in a table. The iOS reader shows
147tables at full width.
148
149* Importing and exporting
150
151| Command                                | Org command        |
152|----------------------------------------+--------------------|
153| Import Table from File… (command palette) | =org-table-import= |
154| Export Table to File… (command palette)   | =org-table-export= |
155
156Open the command palette with =⇧⌘P= (=M-x= in the Emacs preset, =SPC := in Doom). On
157iOS, both are under More › Table in the editor, as Import Table from File…, Export Table
158as CSV… and Export Table as TSV…, and in Commands; the file comes from, and goes to, the
159Files app.
160
161Import asks for a CSV, TSV or plain text file, inserts its contents at the caret on a
162line of its own, and converts them to a table with the separator guessed as for a
163region (see /Creating a table/).
164
165Export writes the table at the caret. A file name ending in =.csv= gets CSV: fields
166separated by commas, with fields that contain a comma or a double quote quoted and
167inner quotes doubled. Any other name gets TSV. Rules are left out.
168
169* Formulas
170
171orgstar evaluates Org's spreadsheet formulas, =org-table-recalculate= and
172=org-table-eval-formula=, natively: Calc expressions in a reimplementation of the part
173of Emacs Calc that tables use, and Lisp formulas in a small Emacs Lisp evaluator. What
174falls outside them is handed to Emacs on the Mac (see /When Emacs is needed/).
175
176Formulas live in a =#+TBLFM:= line right after the table, separated by =::=:
177
178#+BEGIN_SRC org
179| Item  | Qty | Price | Total |
180|-------+-----+-------+-------|
181| Apple |   3 |  0.50 |  1.50 |
182| Pear  |  12 |  0.75 |  9.00 |
183|-------+-----+-------+-------|
184| Sum   |     |       | 10.50 |
185,#+TBLFM: $4=$2*$3;%.2f::@>$4=vsum(@I..@II);%.2f
186#+END_SRC
187
188Blank lines between the table and =#+TBLFM:= are allowed. If there are several
189=#+TBLFM:= lines, recalculating the table uses the first; =C-c C-c= on another applies
190that line instead (=org-table-calc-current-TBLFM=).
191
192** Kinds of formula
193
194| Left side               | Kind                 | Applies to                                                       |
195|-------------------------+----------------------+------------------------------------------------------------------|
196| =$3=                    | Column formula       | Every data row of column 3, except rows marked =!=, =^=, =_=, =$= or =/= in the first column. |
197| =$<=, =$>=              | Column formula       | The first or last column.                                        |
198| =@2$3=, =@>$3=          | Field formula        | One field. Field formulas override column formulas.               |
199| =@2$2..@4$3=            | Range formula        | Every field in the rectangle.                                    |
200| =@4=                    | Row formula          | Every field of data row 4.                                       |
201| =$name=                 | Named field formula  | The field named by a =^= or =_= row (see /Names, parameters and constants/). |
202
203A left side relative to the current row, such as =@-1$2=, is an error
204(=Unknown field=), and so is one relative to a rule, such as =@I$2=, as in Org. Two
205formulas for the same field are an error.
206
207** References
208
209Rows count data lines from 1; rules don't count. Columns count from 1.
210
211| Reference            | Meaning                                                              |
212|----------------------+----------------------------------------------------------------------|
213| =$2=                 | Column 2 in the current row.                                         |
214| =$-1=, =$+1=         | The column before or after the current one.                          |
215| =$<=, =$>=, =$>>=    | The first column, the last, the one before last.                     |
216| =@3=                 | Row 3 in the current column.                                         |
217| =@-1=, =@+1=         | The row above or below.                                              |
218| =@<=, =@>=           | The first or last data row.                                          |
219| =@I=, =@II=, =@III=  | The first, second, third rule; as a row, the line after it.          |
220| =@-I=                | The rule above the current row.                                      |
221| =@I+2=               | Two data rows after the first rule.                                  |
222| =@2$3=               | Row 2, column 3.                                                     |
223| =$0=                 | The current column.                                                  |
224| =@0=                 | The current row: =@0$2= is =$2=.                                     |
225| =@#=, =$#=           | The current row's or column's number, as a value.                    |
226| =@2$1..@4$3=         | A range: the fields of the rectangle, as a vector.                   |
227| =$1..$3=             | Columns 1 to 3 of the current row.                                   |
228| =@I..@II=            | The current column from the first rule to the second.                |
229
230In a Calc formula a single field becomes a number in parentheses, and a range becomes
231a vector such as =[1,2,3]=. Without the =E= flag, empty fields count as 0 on their own
232and are left out of ranges.
233
234A field's text goes into the formula as it is, so a field holding text such as =N/A= or
235=TBD= becomes Calc variables and the result is a formula: =$1+5= with =N/A= in =$1=
236gives =N / A + 5=. The =N= flag reads every field as a number instead, with text as 0.
237
238** Names, parameters and constants
239
240The first column can mark special rows, as in Org's spreadsheet:
241
242| Mark  | Row                                                                                   |
243|-------+---------------------------------------------------------------------------------------|
244| =!=   | Column names: =$qty= in a formula means the column whose =!= row field is =qty=.      |
245| =^=   | Names for the fields in the row above, usable as =$name=.                            |
246| =_=   | Names for the fields in the row below.                                               |
247| =$=   | Parameters: fields like ~rate=0.2~, usable as =$rate=.                               |
248| =#=   | Marked for recalculation.                                                            |
249| =*=   | Marked for recalculation.                                                            |
250| =/=   | Not recalculated.                                                                    |
251
252When any row's first field is one of =!=, =^=, =_=, =$=, =#= or =*=, column formulas
253in a whole-table recalculation apply only to the rows marked =#= or =*=, as
254=org-table-calculate-mark-regexp= decides in Org. So a table with a =!= names row and
255no =#= rows gets no column formulas applied; mark the rows to calculate. Field
256formulas apply either way. Rows marked =!=, =^=, =_=, =$= or =/= are never changed by
257column formulas.
258
259#+BEGIN_SRC org
260| ! | qty | price | total |
261|---+-----+-------+-------|
262| # |   2 |     3 |     6 |
263| # |   4 |   0.5 |     2 |
264,#+TBLFM: $4=$qty*$price
265#+END_SRC
266
267A =$name= that isn't a column name, parameter or named field is looked up as
268=org-table-get-constant= does:
269
270- in =#+CONSTANTS:= lines of the file or its setup file, written ~name=value~ and
271  separated by spaces (~#+CONSTANTS: c=299792458 g=9.81~);
272- =$PROP_xyz= reads the =xyz= property of the entry holding the table, with
273  inheritance.
274
275A name that isn't found becomes =#UNDEFINED_NAME=. A parameter named =%= in a =$= row,
276for example ~%=%.2f~, is put in front of the flags of every formula that has a =;=,
277so ~$3=$2/3;~ is formatted with =%.2f=.
278
279** Remote references
280
281=remote(NAME, REF)= reads a field or range from another table:
282
283#+BEGIN_SRC org
284,#+NAME: rates
285| item | rate |
286|------+------|
287| a    |    2 |
288| b    |    3 |
289
290| x | y | z |
291|---+---+---|
292| 4 | 8 | 5 |
293,#+TBLFM: $2=$1*remote(rates,@2$2)::$3=vsum(remote(rates,@2$2..@>$2))
294#+END_SRC
295
296=NAME= is found in this order:
297
2981. a table after =#+NAME: NAME= or =#+TBLNAME: NAME= in the same file;
2992. the first table in the entry whose =ID= property is =NAME=, in the same file;
3003. the first table in the entry with that =ID= in any indexed file in your sidebar
301   folders, read from the file on disk.
302
303=REF= may use spreadsheet-style references such as =B3= (column B, row 3), which
304become =@3$2=. A =REF= without a row, such as =$1..$2=, reads the row of the other
305table that has the current row's number. =NAME= can itself be a reference: in
306=remote($1,@1$1)=, the current row's first field holds the table's name.
307
308** Calc expressions
309
310Calc formulas use Calc's number rules: integers are exact, and decimal numbers are
311rounded to 12 significant digits after every operation. Results are shown with up to
3128 significant digits unless a format flag says otherwise (=org-calc-default-modes=).
313
314Operators, from lowest to highest precedence (the lowest, ~||~, is logical or: the left
315side if it is nonzero, else the right side):
316
317| Operator                           | Meaning                                                   |
318|------------------------------------+-----------------------------------------------------------|
319| =&&=                               | Logical and: the left side if it is zero, else the right side. |
320| =!=                                | Logical not.                                              |
321| ~==~, ~!=~, =<=, =>=, ~<=~, ~>=~    | Comparisons, giving 1 or 0. They can't be chained.        |
322| =+=, =-=                           | Addition and subtraction.                                 |
323| =/=, =%=, =\=                      | Division, modulo (sign of the divisor), integer division rounding down. |
324| =*=                                | Multiplication. Values side by side also multiply: =2 3=, =2 (x)=. |
325| unary =-=                          | Negation.                                                 |
326| =^=                                | Power.                                                    |
327| =!=, =!!= after a value            | Factorial, double factorial.                              |
328| =%= after a value                  | Percent: =5%= is =0.05=. Followed by a value, =%= is modulo instead. |
329
330Parentheses group, =[a, b, c]= writes a vector, =<2026-10-05 Mon>= writes a date, and
331=nan= is "not a number". =1:3= writes the fraction one third and =1:2:3= one and two
332thirds; =16#FF= writes an integer in base 16 (any base from 2 to 36).
333
334Functions:
335
336| Function                                   | Result                                                        |
337|--------------------------------------------+---------------------------------------------------------------|
338| =vsum=, =vprod=                            | Sum or product of a vector.                                   |
339| =vcount=                                   | Number of elements.                                           |
340| =vmean=, =vmedian=                         | Mean, median.                                                 |
341| =vgmean=, =vhmean=                         | Geometric mean, harmonic mean.                                |
342| =vmax=, =vmin=                             | Largest, smallest element.                                    |
343| =vvar=, =vsdev=                            | Sample variance, sample standard deviation.                   |
344| =vpvar=, =vpsdev=                          | Population variance, population standard deviation.           |
345| =vcov(x, y)=, =vpcov(x, y)=, =vcorr(x, y)= | Sample and population covariance, correlation coefficient.    |
346| =vflat=                                    | The arguments as one vector.                                  |
347| =agmean(a, b)=                             | Arithmetic-geometric mean.                                    |
348| =max(a, b, …)=, =min(a, b, …)=             | Largest, smallest argument.                                   |
349| =if(c, a, b)=                              | =a= if =c= is nonzero, else =b=.                              |
350| =abs=                                      | Absolute value.                                               |
351| =floor=, =ceil=, =trunc=                   | Round down, up, toward zero, to an integer.                   |
352| =round(x)=, =round(x, n)=                  | Round to an integer, or to /n/ decimal places.                |
353| =rounde=, =roundu=                         | As =round=, with halves going to even, or up.                 |
354| =frac(x)=                                  | The fraction nearest to /x/.                                  |
355| =fdiv(a, b)=                               | /a/ divided by /b/ as a fraction.                             |
356| =float(x)=, =pfloat(x)=                    | /x/ as a decimal number.                                      |
357| =sign=                                     | -1, 0 or 1.                                                   |
358| =mod(a, b)=, =idiv(a, b)=                  | As =%= and =\=.                                               |
359| =gcd(a, b)=, =lcm(a, b)=                   | Greatest common divisor, least common multiple.               |
360| =fact=, =dfact=                            | Factorial and double factorial of a non-negative integer.     |
361| =choose(n, m)=, =perm(n, m)=               | Binomial coefficient and permutations, of integers.           |
362| =sqrt=, =exp=, =ln=, =log10=               | Square root, exponential, natural and base-10 logarithm.      |
363| =log(x, b)=                                | Logarithm of /x/ to base /b/.                                 |
364| =pow(x, y)=, =nroot(x, n)=, =exp10(n)=     | /x/ to the power /y/, /n/-th root, 10 to an integer power.    |
365| =hypot(a, b)=                              | The square root of /a/² + /b/².                               |
366| =sin=, =cos=, =tan=                        | Trigonometry, in degrees unless the =R= flag is set.          |
367| =arcsin=, =arccos=, =arctan=, =arctan2(y, x)= | Inverse trigonometry, in degrees unless =R=.               |
368| =sinh=, =cosh=, =tanh=                     | Hyperbolic functions.                                         |
369| =arcsinh=, =arccosh=, =arctanh=            | Inverse hyperbolic functions.                                 |
370| =deg=, =rad=                               | Radians to degrees, degrees to radians.                       |
371| =eq=, =neq=, =lt=, =gt=, =leq=, =geq=      | As ~==~, ~!=~, =<=, =>=, ~<=~ and ~>=~.                       |
372| =land=, =lor=, =lnot=                      | As =&&=, ~||~ and =!=.                                        |
373
374The statistics functions take any number of vectors and numbers, as in
375=vmean($2..$4, $6)=.
376
377Calc leaves what it can't reduce to a number as a formula, and so does orgstar for
378sums, differences, products, quotients and powers:
379
380- A name is a variable: =2*x + x= is =3 x=. Calc's constants =pi=, =e=, =phi= and =gamma=
381  stay names too: =$1^2*pi= gives =9 pi= for 3.
382- Division by zero stays unevaluated: =$1/$2= with 6 and an empty field gives =6/0=,
383  and =x/0 + 1= gives =x / 0 + 1=.
384- =inf=, =-inf= and =uinf= (infinity of unknown sign) follow Calc's rules: =inf - inf= is
385  =nan=, =1/inf= is =0=, =2^inf= is =inf=.
386- =vsum=, =vprod=, =vmean= and =vcount= take vectors holding such formulas.
387
388Other functions of a formula, comparisons and conditions on one, and complex results
389need Emacs.
390
391** Mode flags and formats
392
393After the formula, a =;= starts its flags, as in ~$3=$1/$2;%.2f~ or ~$4=$1*2;f2~:
394
395| Flag      | Meaning                                                                                   |
396|-----------+-------------------------------------------------------------------------------------------|
397| =nN=      | Float format with /N/ significant digits.                                                 |
398| =fN=      | Fixed format with /N/ decimal places.                                                     |
399| =sN=      | Scientific format with /N/ digits.                                                        |
400| =eN=      | Engineering format with /N/ digits.                                                       |
401| =pN=      | Calc precision, 3 to 18 digits (12 by default). See below for limits.                     |
402| =D=, =R=  | Angles in degrees (the default) or radians.                                               |
403| =F=       | Prefer fractions: =1/3= stays =1:3=.                                                      |
404| =N=       | Treat every field as a number; text counts as 0.                                          |
405| =S=       | Symbolic: results that aren't exact stay as formulas, such as =sqrt(2)=.                  |
406| =E=       | Keep empty fields: in ranges they stay in, and count as =nan= in Calc.                    |
407| =L=       | Literal: in Lisp formulas, insert fields as they are written.                             |
408| =T=       | Durations: read =H:MM= and =H:MM:SS= fields as times, show the result as =HH:MM:SS=.      |
409| =U=       | As =T=, showing =HH:MM=.                                                                  |
410| =t=       | As =T=, showing decimal hours with two places, such as =1.50=.                            |
411
412Above =p14=, functions worked out from decimal approximations (=sqrt= of a non-square,
413=exp=, =ln=, =log=, non-integer powers, trigonometric and hyperbolic functions) may need
414Emacs, and above =p16= so may the statistics functions and powers of decimal numbers.
415
416With =S=, the functions that may give an inexact result (=sqrt=, =exp=, =ln=, =log=,
417=log10=, =pow=, =nroot=, =hypot=, the inverse trigonometric and hyperbolic functions,
418=fact=, =dfact=, the standard deviations, =vgmean=, =vhmean=, the covariances and
419=agmean=), powers other than integer powers, and =sin=, =cos= and =tan= in radians need
420Emacs.
421
422The flag =u= needs Emacs. Any other text after the flags is a
423=format= string applied to the result, such as =%.2f= or =%d=; =format= supports
424=%s=, =%S=, =%d=, =%o=, =%x=, =%X=, =%c=, =%e=, =%f= and =%g=.
425
426** Durations
427
428With =T=, =U= or =t=, fields like =1:30= or =10:00:30= are read as hours, minutes and
429seconds:
430
431#+BEGIN_SRC org
432| start    | end     | sum      | diff  | hours |
433|----------+---------+----------+-------+-------|
434| 1:30     | 0:45    | 02:15:00 | 00:45 |  3.00 |
435| 10:00:30 | 2:15:10 | 12:15:40 | 07:45 | 20.02 |
436,#+TBLFM: $3=$1+$2;T::$4=$1-$2;U::$5=$1*2;t
437#+END_SRC
438
439** Dates
440
441Timestamps in fields, active or inactive, take part in Calc arithmetic as dates. The
442difference of two dates is a number of days, with a fraction when the timestamps have
443times. A date plus a number is a date, written back as an inactive timestamp:
444
445#+BEGIN_SRC org
446| start            | end              | days | later            |
447|------------------+------------------+------+------------------|
448| <2026-10-05 Mon> | <2026-10-12 Mon> |    7 | [2026-10-12 Mon] |
449,#+TBLFM: $3=$2-$1::$4=$1+7
450#+END_SRC
451
452A date is its day number underneath, counted from 1 January of year 1, so the sum of two
453dates is a number and =vmean= of two dates is the day number halfway between them.
454=vsum=, =vmax=, =vmin=, =max=, =min=, =abs= and the comparisons work on dates; =floor=,
455=ceil=, =trunc= and =round= keep a date and drop or round its time. A timestamp with a
456time, even =00:00=, keeps showing one. Calc leaves =abs= of day 0 (=<-1-12-31>=)
457unevaluated, so that needs Emacs.
458
459| Function                                   | Result                                                                             |
460|--------------------------------------------+------------------------------------------------------------------------------------|
461| =year=, =month=, =day=                     | Parts of the date.                                                                 |
462| =hour=, =minute=, =second=                 | Parts of the time, 0 for a date without one.                                       |
463| =weekday=                                  | 0 for Sunday to 6 for Saturday.                                                    |
464| =yearday=                                  | Day of the year, 1 for 1 January.                                                  |
465| =date(y, m, d)=, =date(y, m, d, h, mi, s)= | The date, with a time when an hour is given. =date(m, d)= is this year.            |
466| =date(d)=                                  | The day number of date /d/, or the date of day number /d/.                         |
467| =now()=                                    | The current date and time.                                                         |
468| =incmonth(d, n)=, =incyear(d, n)=          | /n/ months or years later (1 by default), on the last day if the month is shorter. |
469| =newmonth(d, n)=, =newyear(d, n)=          | Day /n/ of the month or year (1 by default; 0 is the last day).                    |
470| =newweek(d, w)=                            | The day on or before /d/ that falls on weekday /w/ (0, Sunday, by default).        |
471| =badd(d, n)=, =bsub(d, n)=                 | /n/ business days later or earlier, skipping Saturdays and Sundays.                |
472| =bsub(d1, d2)=                             | Business days from /d2/ to /d1/.                                                   |
473| =julian(d)=                                | The Julian day number of /d/, or the date of a Julian day number.                  |
474| =unixtime(d)=                              | Seconds since 1970-01-01 00:00 UTC, or the date of a number of seconds.            |
475
476As in Calc, a timestamp year under 100 is read as 19xx or 20xx: 00 to 39 is 20xx, 40 to
47799 is 19xx. =badd= and =bsub= work only for dates in the years 1 to 2737, the range of
478Calc's holiday table; outside it they need Emacs, which leaves them unevaluated.
479
480=julian= of a date with a time and =unixtime= use the local time zone. Emacs applies
481the current year's daylight saving rules to every date, which orgstar doesn't, so in a
482time zone with daylight saving time these need Emacs.
483
484With =N=, =T=, =U= or =t= a timestamp field counts as 0. A result that is a date is
485=#ERROR= with =N=, and with =T=, =U= or =t= it stops the recalculation with the error
486Org gives.
487
488** Lisp formulas
489
490A formula that starts with ='(= is Emacs Lisp. Each reference becomes a Lisp string,
491or a number with =N=, or the field's text inserted as is with =L=. A range becomes the
492values separated by spaces, so wrap it in a quoted list:
493
494#+BEGIN_SRC org
495| name  | greeting |
496|-------+----------|
497| Ada   | Ada!     |
498| Grace | Grace!   |
499,#+TBLFM: $2='(concat $1 "!")
500
501| n |
502|---|
503| 1 |
504| 2 |
505|---|
506| 3 |
507,#+TBLFM: @>$1='(apply '+ '(@I..@II));N
508#+END_SRC
509
510The evaluator supports:
511
512- special forms: =quote=, =function=, =lambda=, =progn=, =prog1=, =if=, =when=,
513  =unless=, =cond=, =and=, =or=, =let=, =let*=, =setq=, =push=, =pop=, =while=,
514  =dolist=, =dotimes=, =with-output-to-string=, =ignore-errors=, =condition-case=,
515  =save-match-data=, =defun=, =defvar=, =defconst=, =let-alist=, =cl-incf= and =cl-decf=
516  on a variable, with dynamic binding, as Org evaluates formulas;
517- =pcase= with literal, symbol, quoted, backquoted and =pred= patterns, where =pred=
518  takes a function name or a lambda;
519- =cl-loop= with =for VAR in LIST=, =for VAR from START to END=, and one kind of
520  =collect= or =sum=, with =do=;
521- arithmetic: =+=, =-=, =*=, =/=, =%=, =mod=, =1+=, =1-=, =abs=, =max=, =min=, =float=,
522  =floor=, =ceiling=, =round=, =truncate=, ~=~, =<=, =>=, ~<=~, ~>=~, ~/=~, =zerop=,
523  =expt=, =sqrt=, =exp=, =log=, =sin=, =cos=, =tan=, =asin=, =acos=, =atan=, =isnan=,
524  =random=, =logand=, =logior=, =logxor=, =ash=, and the variables =float-pi=, =pi= and
525  =float-e=;
526- predicates: =not=, =null=, =eq=, =eql=, =equal=, =numberp=, =integerp=, =floatp=,
527  =stringp=, =listp=, =consp=, =symbolp=;
528- lists: =car=, =cdr=, =cadr=, =cddr=, =cons=, =list=, =nth=, =nthcdr=, =elt=, =aref=,
529  =append=, =length=, =reverse=, =number-sequence=, =memq=, =member=, =memql=, =assoc=,
530  =assq=, =delq=, =delete=, =mapcar=, =mapc=, =mapconcat=, =funcall=, =apply=,
531  =identity=, =ignore=, =last=, =butlast=, =delete-dups=, =nreverse=, =sort= (both
532  calling conventions; these three need Emacs when they would change a list that
533  another variable, list or argument may share), =seq-reduce=, =seq-filter=, =seq-remove=, =seq-map=, =seq-uniq=,
534  =cl-reduce= (with =:initial-value=), =cl-remove-if=, =cl-remove-if-not=, =cl-find= and
535  =cl-position= (with =:test=);
536- strings: =concat=, =format=, =format-message=, ~string=~, =string-equal=, =string<=,
537  =string-lessp=, =upcase=, =downcase=, =capitalize=, =substring=, =string-to-number=,
538  =number-to-string=, =int-to-string=, =string-prefix-p=, =string-suffix-p=,
539  =string-empty-p=, =string-trim=, =split-string=, =prin1-to-string=, =string-join=,
540  =string-to-char=, =char-to-string=, =string-pad=, =string-width=, =string-search=,
541  =string-replace=;
542- regular expressions: =string-match=, =string-match-p=, =match-beginning=, =match-end=,
543  =match-string=, =replace-match= and =replace-regexp-in-string= on strings, and
544  =regexp-quote=;
545- time: =current-time=, =format-time-string=, =float-time=, =time-add=, =time-subtract=,
546  =time-to-days=, =date-to-time=, =days-between=, =org-time-string-to-time=,
547  =org-time-string-to-absolute= and the =calendar-= functions that diary sexps use, in
548  the local time zone and the proleptic Gregorian calendar;
549- output and errors: =princ=, =prin1=, =print=, =terpri=, =message=, =error=,
550  =user-error=;
551- Org's lookup functions =org-lookup-first=, =org-lookup-last= and =org-lookup-all=.
552
553Regular expressions use Emacs's syntax and the syntax table of an Org buffer, and
554=case-fold-search= is on unless the formula binds it to =nil=. These need Emacs:
555numbered groups =\\(?N:=, categories =\\c=, syntax classes and character classes
556such as =\\w=, =\\b= or =[[:alpha:]]= against text with characters past ASCII,
557and case folding of a letter past ASCII, including =capitalize=. =condition-case=
558binds its variable to the error symbol and data, such as =(wrong-type-argument listp 1)=;
559reading that variable for an error whose data orgstar doesn't know, such as
560=args-out-of-range=, needs Emacs, as does a handler that names a specific condition
561when the error isn't one of =wrong-type-argument=, =args-out-of-range=, =arith-error=,
562=void-variable=, =invalid-function=, =wrong-number-of-arguments=, =error= and
563=user-error=. =format-time-string= takes =%Y=, =%y=, =%m=,
564=%d=, =%e=, =%H=, =%k=, =%I=, =%l=, =%M=, =%S=, =%p=, =%a=, =%A=, =%b=, =%h=, =%B=, =%u=,
565=%w=, =%j=, =%F=, =%D=, =%R=, =%T=, =%s=, =%z=, =%n=, =%t= and =%%=, without flags or
566widths; other codes need Emacs, as do float times in =time-add= and =time-subtract=. =date-to-time= and =days-between= read dates as
567=YYYY-MM-DD=, with an optional =HH:MM= or =HH:MM:SS=.
568
569Any other function, or a macro not listed, needs Emacs. An error inside a Lisp formula
570writes =#ERROR= in the field, as does a Calc error.
571
572* Entering formulas
573
574There are three ways to set a formula.
575
576*In the field.* Type ~=expr~ in a field and press =TAB= or =RET=: orgstar stores
577~$N=expr~ as the column's formula and evaluates it, as
578=org-table-maybe-eval-formula= does. Type ~:=expr~ instead to store a field formula
579~@R$C=expr~.
580
581*With a prompt.* =org-table-eval-formula= asks for the formula (~Column formula $N=~
582or ~Field formula @R$C=~) with the stored one filled in, stores it and evaluates it in
583the current field. Clearing the prompt and pressing =Return= removes the stored
584formula, as in Emacs, and the echo area shows =Formula removed=. You can also delete a
585formula in the formula editor below or from the =#+TBLFM:= line.
586
587| Command                       | Emacs    | Mac                         | Doom     |
588|-------------------------------+----------+-----------------------------+----------|
589| Org ▸ Set Column Formula      | ~C-c =~  | Org ▸ Set Column Formula    | ~C-c =~  |
590| Org ▸ Set Field Formula       | none     | Org ▸ Set Field Formula     | none     |
591
592Org's ~C-u C-c =~ for field formulas has no equivalent key, because orgstar has no
593prefix argument; use the menu item or type ~:=~ in the field.
594
595*In the formula editor.* =C-c '= in a table or on its =#+TBLFM:= line
596(=org-table-edit-formulas=) opens the formulas in an editor of their own, one per line,
597grouped under =# Column Formulas=, =# Field and Range Formulas= and
598=# Named Field Formulas=. A formula can continue on indented lines. =C-c '= or
599=⌘Return= installs the formulas; =Escape= or =C-c C-k= leaves them unchanged.
600Installing doesn't recalculate. The echo area says so and points to Recalculate Table:
601=C-c C-c= on the =#+TBLFM:= line, or =⌃⌘X= there in the Mac preset.
602
603The formulas are stored sorted the way =org-table-formula-less-p= sorts them.
604
605* Recalculating
606
607| Command                          | Org command                       | Emacs                         | Mac                         | Doom                                |
608|----------------------------------+-----------------------------------+-------------------------------+-----------------------------+-------------------------------------|
609| Recalculate Table                | =org-table-recalculate= with =C-u= | =C-c C-c= on =#+TBLFM:=      | =⌃⌘X= on =#+TBLFM:=         | =SPC m b r=, =C-c C-c= on =#+TBLFM:= |
610| Recalculate Table Row            | =org-table-recalculate=           | =C-c *=                       | =⌃⌘*= (=⌃⇧⌘8= on a US keyboard) | =C-c *=                             |
611| Iterate Table Formulas           | =org-table-iterate=               | =C-u C-u C-c *=               | —                           | —                                   |
612
613In Doom's normal state, =RET= in a table recalculates it when it has a =#+TBLFM:=
614line and aligns it otherwise; on a =#+TBLFM:= line it recalculates.
615
616When the table has a rule below its first data row, recalculating the whole table
617leaves the rows above that rule, the header, alone. With marked rows, the marks decide
618instead (see /Names, parameters and constants/). Each
619command evaluates the column formulas row by row, then the field formulas, then aligns
620the table. Each formula is evaluated once. Iterate Table Formulas recalculates the whole
621table again and again until it stops changing, for formulas that depend on each other's
622results, at most ten times. The echo area says =Convergence after 3 iterations=, or
623=Table was already stable=; after ten passes that still change the table it says =No
624convergence after 10 iterations=, and the ten passes stay. =C-u C-c *= also recalculates
625the whole table in the Emacs preset.
626
627A formula that fails, such as one whose reference leads outside the table, stops the
628command there. As in Emacs, the fields written before it stay, the table isn't aligned,
629the caret goes to the start of its field (on a =#+TBLFM= line it stays put), and the echo
630area shows the error.
631=TAB=, =S-TAB= and =RET= in a row marked =#= stop there too, without moving on.
632
633A row marked =#= is recalculated when you press =TAB=, =S-TAB= or =RET= in it, before
634the caret moves (=org-table-maybe-recalculate-line=), and with =C-c C-c= (Mac =⌃⌘X=).
635Other rows are recalculated only by the commands above. Emacs skips a second automatic
636recalculation of the same row by the same command in a row; orgstar recalculates each
637time, which gives the same result unless a formula depends on its own value.
638
639* When Emacs is needed
640
641When a formula uses something the native evaluator doesn't have, the command reports
642what it was and the Mac recalculates the table in Emacs instead. This happens for:
643
644- symbolic results beyond those under /Calc expressions/, such as a function of a field
645  holding text;
646- Calc functions not listed above, intervals such as =[1..5]=, precisions beyond those
647  given under /Mode flags and formats/, parts of the =S= flag, and the =u= flag;
648- complex results, vector results, and numbers too large for 64-bit integers;
649- Lisp functions not listed above.
650
651The echo area shows =Recalculating in Emacs (reason)…=, then =Recalculated in Emacs=.
652orgstar runs =emacs -Q --batch= on a copy of the file, so your Emacs init file,
653packages and customizations are not loaded, then replaces the table with Emacs's
654result. It looks for Emacs at the path in the =ORGSTAR_EMACS= environment variable,
655then =/opt/homebrew/bin/emacs=, =/usr/local/bin/emacs=,
656=/Applications/Emacs.app/Contents/MacOS/Emacs=, =/run/current-system/sw/bin/emacs= and
657=/usr/bin/emacs=. If none is found, the echo area shows the reason, as
658=This table's formulas can't be calculated here: reason.=, and the table is unchanged.
659Emacs gets your =PATH= with =/opt/homebrew/bin=, =/usr/local/bin=,
660=/Library/TeX/texbin=, =/usr/bin= and =/bin= added, as code blocks and export do, so
661programs a formula starts are found when orgstar was opened from the Dock. The run
662stops after 60 seconds. If you edit the table while Emacs is working, its result is
663discarded.
664
665Edit ▸ Cancel Running Task (=⌘.=) stops the recalculation; the echo area shows
666=Recalculation canceled= and the table is unchanged. Starting another recalculation or
667export in Emacs cancels the one that is running.
668
669The [[file:../install.org][Mac App Store version]] doesn't run Emacs, so it recalculates
670only the tables orgstar computes itself. In any other table it applies the formulas in
671Emacs's order up to the first one it can't compute and stops there, as Emacs does when a
672formula fails: the fields written before it stay, unaligned, and the rest are unchanged.
673The echo area shows =The table was recalculated up to (formula), which can't be
674calculated here: (reason).=, where /formula/ is the left-hand side, such as =$4=. When nothing
675was written, it shows =This table's formulas can't be calculated here: (reason).= and the
676table is unchanged.
677
678If the table's formulas contain Lisp, orgstar asks first:
679=This table's formulas run Lisp. Run them? (yes, no, always)=. =always= trusts this
680table's text in this file, so the question isn't asked again until the text changes.
681
682Entering a formula that needs Emacs with ~C-c =~, Set Field Formula or ~=~ in a field
683is not handed to Emacs. The formula is stored in the =#+TBLFM:= line and the field is
684left as it was; the echo area shows =The formula was stored; recalculating it needs
685Emacs= and the reason. =TAB= and =RET= still move to the next field. Recalculate the
686table to run the formula in Emacs. In the Mac App Store version the echo area shows
687=The formula was stored; it can't be calculated here:= and the reason, and recalculating
688doesn't run it.
689
690For how orgstar and Emacs share files, see
691[[file:15-alongside-emacs.org][Using orgstar alongside Emacs]].
692
693* table.el tables
694
695Tables drawn with =+= corners and =-= and =|= borders, as the =table.el= package makes
696them, are recognized and kept as written:
697
698#+BEGIN_SRC org
699+-------+-------+
700| Name  | Value |
701+-------+-------+
702| a     | 1     |
703+-------+-------+
704#+END_SRC
705
706Edit the text in the cells as usual. =TAB= and =S-TAB= line the borders up, then move to
707the next or previous cell, wrapping around at the ends of the table, as table.el's
708=table-forward-cell= and =table-backward-cell= do; the caret goes to the cell's first
709character. =C-c C-c= (Mac =⌃⌘X=) lines the borders up without moving. Lining up makes
710each column as wide as its widest text, and never narrower than its rules: text typed
711into a cell uses up the spaces at its end first, as table.el does when you type.
712
713Org edits table.el tables in table.el's own buffer, with =C-c '=, and says so for =TAB=
714and =C-c C-c=; orgstar does the editing in place instead. Tables with merged cells, which
715span rows or columns, can be moved through but not lined up ("Can't align a table.el
716table with merged cells"). Formulas, sorting and the other table commands don't apply.
717
718HTML export renders them as tables, with cells that span rows and columns, and Markdown
719export writes them as a code block. See [[file:12-export.org][Export]].
720
721* Plotting
722
723Plot Table (=org-plot/gnuplot=, =C-c " g= in the Emacs and Doom presets, and in the
724command palette; More › Table on iOS) draws the table at the caret, or the first table
725after it, as the =#+PLOT:= lines above it say:
726
727#+BEGIN_SRC org
728#+PLOT: title:"Sales" ind:1 deps:(2 3) type:2d with:linespoints file:"sales.png"
729| month | north | south |
730|-------+-------+-------|
731|     1 |    20 |    12 |
732|     2 |    25 |    18 |
733#+END_SRC
734
735| Option     | Meaning                                                                     |
736|------------+-----------------------------------------------------------------------------|
737| =type=     | =2d= (the default), =3d= or =grid=                                          |
738| =ind=      | The column of x values, counting from 1; 0 (the default) plots against row numbers |
739| =deps=     | The columns to plot, as a list such as =(2 3)=; all but =ind= by default    |
740| =with=     | =lines= (the default), =points=, =linespoints=, =impulses=, =boxes=, =histograms=, =steps=, =fsteps= |
741| =title=    | The plot's title                                                            |
742| =file=     | Where the image goes, relative to the Org file's folder; without it the plot shows in a sheet |
743| =labels=   | Names for the columns, as a list; a header row above a rule names them otherwise |
744| =map=      | With =t=, a =3d= plot is seen from above                                    |
745| =ymin=, =ymax=, =xmin=, =xmax= | The axes' ranges; =min= and =max= are =ymin= and =ymax=   |
746| =ticks=    | How many marks the y axis has                                               |
747| =transpose= | With =yes=, rows become columns                                            |
748| =set=, =line=, =script=, =timefmt= | gnuplot commands, a line of gnuplot, a gnuplot script file and the time format, for gnuplot |
749
750Options are read as Org reads them, quirks included: an option's name also matches inside
751a longer word (=timeind:t= sets =ind=), an unquoted value ends at a =.=, =,= or =;=, =set:=
752options before the last =line:= are dropped, and each =set:= and =line:= that's kept comes
753twice, as Org reads the options twice. An ind column of timestamps is plotted as dates, and one of text as labels.
754
755On the Mac, when gnuplot is installed (orgstar looks on the same =PATH= as code blocks), the
756table goes to gnuplot as Emacs sends it: the same data file and script, so every option and
757gnuplot's own terminals and styles apply. A plot without =file:= is drawn to an image and shown
758in a sheet. Without gnuplot, and on iOS, orgstar draws the plot itself with Swift Charts: =2d=
759as lines, points or bars by =with:=, =grid= as a heat map, =3d= as a surface (a wireframe in a
760file). =file:= then takes =.png=, =.jpg= or =.pdf=, 640 by 480 points as gnuplot's default; the
761gnuplot-only options are ignored. If inline images are showing, a link to the file shows the
762new plot.
763
764=type:radar= needs gnuplot; orgstar reports it.
765
766The [[file:../install.org][Mac App Store version]] doesn't use gnuplot: it always draws
767the plot with Swift Charts, and reports =type:radar= in the same way.
768
769* On iOS
770
771The iOS app evaluates formulas natively with the same engine. Tables that need Emacs
772are not recalculated there; the app reports =This table needs Emacs, which runs on the
773Mac= with the reason. Import and export are under More › Table, with Plot Table.
774Narrow columns work in the editor, as described under /Narrow columns/. See
775[[file:14-ios.org][iOS]].
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form