A document. Its content (Section, Paragraph, List, Table, Figure, Math...) is laid out by the template and saved where to: says, or kept in into:. Statements such as for, if and let work inside it.
Holds statements.Holds statements in { }. Scripts only.
AttributeOption
Value
Description
template
plain|paper|report|letter|invoice
The look: plain (the default), paper, report, letter or invoice.
title
a string with { }
The document's title.
subtitle
a string with { }
A line under the title.
author
a string with { }
The author, or several separated by ; (Author elements can add affiliations and emails).
date
a string with { }
The date shown under the title, such as { @now()->format('d MMMM yyyy') }.
keywords
a string with { }
Keywords, as a list: ['cellular automata', 'Game of Life'] (in XML, cellular automata, Game of Life). They are shown under the abstract and saved in the file's properties.
to
a string with { }
Where to save it, by extension: paper.pdf, paper.tex, paper.docx, paper.md or paper.html. Save several with a list: [paper.pdf, paper.docx].
into
a new variable's name
A variable that receives the document, for ->save(), ->pages() or ->convert(to: markdown) later.
paper
a4 | a3 | a5 | b5 | letter | legal
Paper size: a4 (the default), a3, a5, b5, letter, legal, or a size such as '15cm x 20cm'.
landscape
true or false
true turns the paper sideways.
margin
a string with { }
Margins: one size (2.5cm), or top/right/bottom/left like CSS ('2cm 2.5cm').
font
serif|sans|mono
Body text: serif (Times), sans (Helvetica) or mono (Courier).
heading_font
serif|sans|mono
Headings: serif, sans or mono.
size
a string with { }
Body text size in points, such as 11.
line_height
a string with { }
Baseline to baseline as a multiple of the text size, such as 1.4.
align
justify|left|center|right
Body text: justify, left, center or right.
accent
a string with { }
The colour of headings and the title page: '#1f4e79' or a name such as 'navy'.
numbered
true or false
false leaves sections without numbers.
title_page
true or false
true puts the title, authors, date and abstract on a page of their own.
chapters
true or false
true starts each top-level section on a new page.
citations
numeric|author-year
numeric ([1]) or author-year ((Conway, 1970)).
header
a string with { }
The page header: 'left | centre | right', with [page], [pages], [title], [author] and [date].
footer
a string with { }
The page footer, like header. The default shows the page number.
rules
booktabs|grid|none
Table lines: booktabs (above, below and under the header), grid or none.
language
a string with { }
The language, such as en or en-GB, for Word and HTML.
Example
<KScript.Document template="paper" title="Gliders" author="Ada Lovelace" to="gliders.pdf">
<Section title="Introduction">
<Paragraph>A glider moves one cell every \( 4 \) generations.</Paragraph>
</Section>
</KScript.Document>
import KScript.Document
Document(template: paper, title: 'Gliders', author: 'Ada Lovelace', to: 'gliders.pdf') {
Section(title: 'Introduction') {
Paragraph "A glider moves one cell every \( 4 \) generations."
}
}
LaTeX, from its text, a latex value or a .tex file, read as a document part reads it: sections, paragraphs, lists, maths, quotes, figures and the usual text commands. Its text is used as written, so braces are LaTeX's.
Holds text with { } values. Scripts only. Goes inside <KScript.Document>Document or <fn>fn.
AttributeOption
Value
Description
path
a file path
A .tex file, relative to the script.
value
expression
A latex value, such as what a function that returns a latex block gives.
Markdown, from its text or a file: # headings become sections, with paragraphs, lists, tables, code, quotes, images and maths ([ ] in scripts, also $ \(and\) $$ in files).
Holds text with { } values. Scripts only. Goes inside <KScript.Document>Document or <fn>fn.
A displayed equation in LaTeX, numbered unless numbered: false. Its text is used as written, so braces are LaTeX's. Inside matrix, cases and aligned, a new line ends a row.
Holds text with { } values. Scripts only. Goes inside <KScript.Document>Document or <fn>fn.
AttributeOption
Value
Description
id
a string with { }
A name for [#id] cross-references, such as id: "intro".
A paragraph. Its text may hold bold, italic, code, links, ( maths ), [@key] citations, [#id] cross-references and ^[footnotes]. A blank line starts a new paragraph.
Holds text with { } values. Scripts only. Goes inside <KScript.Document>Document or <fn>fn.
AttributeOption
Value
Description
id
a string with { }
A name for [#id] cross-references, such as id: "intro".
align
left|center|right|justify
left, center, right or justify (the document's setting is the default).
lines
true or false
true keeps the line breaks in the text, as in an address or a poem.
Example
<KScript.Document title="Gliders" to="gliders.pdf">
<Paragraph>Gliders travel **diagonally**, one cell every \( 4 \) generations.^[Down and to the right.]</Paragraph>
</KScript.Document>
import KScript.Document
Document(title: 'Gliders', to: 'gliders.pdf') {
Paragraph "Gliders travel **diagonally**, one cell every \( 4 \) generations.^[Down and to the right.]"
}
A section with a numbered heading. A Section inside a Section is a subsection.
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Document>Document or <fn>fn.
AttributeOption
Value
Description
titlerequired
a string with { }
The heading. It may hold bold, italic and ( maths ).
id
a string with { }
A name for [#id] cross-references, such as id: "intro".
numbered
true or false
false leaves this section without a number.
new_page
true or false
true starts it on a new page.
Example
<KScript.Document title="Gliders" to="gliders.pdf">
<Section title="Methods" id="methods">
<Paragraph>We ran each pattern for 1000 generations.</Paragraph>
</Section>
</KScript.Document>
import KScript.Document
Document(title: 'Gliders', to: 'gliders.pdf') {
Section(title: 'Methods', id: 'methods') {
Paragraph "We ran each pattern for 1000 generations."
}
}
A work to cite, written out: id: is the key for [@key], and other attributes are BibTeX fields (author, title, year, journal, volume, pages, publisher, url, doi...).
Self-closing.A statement on its own. Scripts only. Goes inside <Bibliography>Bibliography. Other attributes are more fields of the source, such as journal, volume, pages, url or doi.Other options are more fields of the source, such as journal, volume, pages, url or doi.
AttributeOption
Value
Description
idrequired
a string with { }
The citation key, as in [@conway1970].
type
a string
article, book, inproceedings, misc...
author
a string with { }
Authors, separated by ' and ' as in BibTeX.
title
a string with { }
The title.
year
a string with { }
The year.
Example
<KScript.Document title="Gliders" to="gliders.pdf">
<Paragraph>Life was first described in 1970 [@gardner1970].</Paragraph>
<Bibliography>
<Source id="gardner1970" type="article" author="Martin Gardner" title="Mathematical Games" journal="Scientific American" year="1970" volume="223" pages="120--123" />
</Bibliography>
</KScript.Document>
import KScript.Document
Document(title: 'Gliders', to: 'gliders.pdf') {
Paragraph "Life was first described in 1970 [@gardner1970]."
Bibliography {
Source(id: 'gardner1970', type: 'article', author: 'Martin Gardner', title: 'Mathematical Games', journal: 'Scientific American', year: 1970, volume: 223, pages: '120--123')
}
}
A table: from rows:, or from Tr rows inside it. Tables with a caption are numbered. It takes the same rows, columns, align and header as the terminal's table.
Holds statements.Holds statements in { }. Scripts only. Goes inside <KScript.Document>Document or <fn>fn.
AttributeOption
Value
Description
caption
a string with { }
The caption, shown above the table as 'Table 1: ...'.
id
a string with { }
A name for [#id] cross-references, such as id: "intro".
rows
expression
The rows: a list of maps (each a row), or a list of lists (the first is the heading row).
columns
expression
Which values of each map to show, in order: a list of keys ['name', 'age'], or a map from heading to key { Name: 'name' }. Defaults to the first row's keys.
align
expression
left, center or right for each column, such as ['left', 'right']. Numbers line up right by default.
widths
expression
Relative column widths for a table across the page, such as [3, 1, 1].
rules
booktabs|grid|none
booktabs, grid or none (the document's setting is the default).