Tables
A table can come from data, which is usually a list of maps:
<let name="people" value="[{ name: 'Ada', born: 1815 }, { name: 'Alan', born: 1912 }]" />
<import package="KScript.Document" />
<Document title="People" to="'people.pdf'">
<Table caption="Two mathematicians." id="tab-people" rows="$people" columns="{ Name: 'name', Born: 'born' }" align="['left', 'right']" />
</Document>$people = [{ name: 'Ada', born: 1815 }, { name: 'Alan', born: 1912 }]
import KScript.Document
Document(title: 'People', to: 'people.pdf') {
Table(caption: 'Two mathematicians.', id: 'tab-people', rows: $people, columns: { Name: 'name', Born: 'born' }, align: ['left', 'right'])
}columns: is a map from heading to key (or a list of keys, which are also the headings). Without it the first map's keys are the columns. When the rows' fields are known, such as a list of maps written in the script or the records of a model, the editor completes the keys and kscript check reports one the rows don't have. Numbers line up on the right unless align: says otherwise.
Or write the rows with Tr, cells separated by |:
<KScript.Document title="Scores" to="'scores.pdf'">
<Table caption="Scores." align="['left', 'right', 'right']" widths="[3, 1, 1]" rules="grid">
<Tr header="true">Team | Played | Points</Tr>
<Tr>Red | 3 | 7</Tr>
<Tr>Blue | 3 | **9**</Tr>
</Table>
</KScript.Document>import KScript.Document
Document(title: 'Scores', to: 'scores.pdf') {
Table(caption: 'Scores.', align: ['left', 'right', 'right'], widths: [3, 1, 1], rules: grid) {
Tr(header: true) "Team | Played | Points"
Tr "Red | 3 | 7"
Tr "Blue | 3 | **9**"
}
}widths: makes the table as wide as the text, sharing the width in those proportions. Without it, columns are as wide as their text. rules: is booktabs (lines above, below and under the header, the default), grid or none; size: 0.9 makes the text smaller. A caption numbers the table, and its heading row repeats when a table runs onto a new page (in LaTeX, a table of more than 30 rows is a longtable for the same reason). A table with no rows is left out of the LaTeX and Markdown files.