-
-
Notifications
You must be signed in to change notification settings - Fork 212
Table manipulation
The following table operations can affect not only plain Markdown tables, but also any kind of table including those loaded from CSV.
CSV example
.tablesort {2} order:{descending}
.csv {people.csv}
The .tablesort
function sorts a table based on the values of a specific column.
Parameter | Description | Accepts |
---|---|---|
column |
Index of the column, starting from 1. | 1 to number of columns. |
order |
Sorting order. |
ascending (default), descending
|
.tablesort {2} order:{descending}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
Result:
| Name | Age | City | |------|-----|------| | Lisa | 32 | LA | | John | 25 | NY | | Mike | 19 | CHI |
The .tablefilter
function keeps or removes rows based on the values of a specific column.
Parameter | Description | Accepts |
---|---|---|
column |
Index of the column, starting from 1. | 1 to number of columns. |
filter |
Lambda that returns whether each row should be kept, with the value of its cell in the corresponding column as input. |
Dynamic →Boolean lambda
|
.tablefilter {2} {@lambda x: .x::isgreater {20}}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
Result:
| Name | Age | City | |------|-----|------| | John | 25 | NY | | Lisa | 32 | LA |
The .tablecompute
function computes the cells in a column and appends the result to a new row.
Parameter | Description | Accepts |
---|---|---|
column |
Index of the column, starting from 1. | 1 to number of columns. |
compute |
Lambda that returns the computed value, with the collection of the cells in the column as input. |
Iterable →Dynamic lambda
|
See Iterable to learn more about available operations on collections.
Example:
.tablecompute {2} {@lambda x: .x::average::round}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
Result:
| Name | Age | City | |------|-----|------| | John | 25 | NY | | Lisa | 32 | LA | | Mike | 19 | CHI | | | 25 | |
Multiple table operations can be chained. The order of the operations goes from inner to outer:
.tablecompute {2} {@lambda x: .x::average::round}
.tablesort {2}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
Result:
| Name | Age | City | |------|-----|------| | Mike | 19 | CHI | | John | 25 | NY | | Lisa | 32 | LA | | | 25 | |
The .tablecolumn
function extracts values from the cells of a specific column, and returns them as an Iterable.
Parameter | Description | Accepts |
---|---|---|
column |
Index of the column, starting from 1. | 1 to number of columns. |
.var {values}
.tablecolumn {2}
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
.values::first
Result:
25
Additionally, the .tablecolumns
function returns all the columns from the table, as an iterable of iterables.
This is more efficient in case you need to access multiple columns from the same table.
.var {columns}
.tablecolumn
| Name | Age | City |
|------|-----|------|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
.foreach {.columns}
col:
.col::first
Result:
John 25 NY
- Figures
- Image size
- TeX formulae
- Table caption
- Code caption
- Decorative headings
- Alerts (quote types)
- Quotation source
- Cross-references
- Page breaks
- Text symbols (text replacement)
- Document metadata
- Theme
- CSS
- Fonts
- Page format
- Page margin content
- Page counter
- Automatic page break
- Numbering
- Paragraph style
- Caption position
- Table of contents
- Bibliography
- Footnotes
- Stacks (row, column, grid)
- Container
- Align
- Float
- Figure
- Clip
- Box
- Collapsible
- Landscape
- Whitespace
- Variables
- Optionality
- Math
- Conditional statements
- Loops
- Let
- Destructuring
- String manipulation
- Table manipulation: sorting, computing, and more
- Generators
- String
- Number
- Markdown content
- Boolean
- None
- Enumeration entry
- Iterable
- Dictionary
- Range
- Lambda
- Size(s)
- Color
- Dynamic
- Paper: abstract, definitions, theorems, and more