Введение
KScript.Document создаёт научные и профессиональные документы: статьи, отчёты, письма и счета. Один скрипт может сохранить один и тот же документ в виде PDF, Word (.docx), LaTeX (.tex), Markdown и HTML. Поддерживаются формулы LaTeX, нумерованные разделы, таблицы и рисунки, ссылки из BibTeX, сноски и перекрёстные ссылки. PDF формирует сам KScript, так что вам не нужно устанавливать TeX, Word или что-либо ещё.
<KScript.Document template="paper" title="How Gliders Move" author="Ada Lovelace" to="'gliders.pdf'">
<Abstract>A glider returns to its own shape every \( p = 4 \) generations, one cell further on.</Abstract>
<Section title="Introduction">
<Paragraph>The Game of Life [@gardner1970] is played on a square grid. Each cell has **eight neighbours**.</Paragraph>
<Math id="eq-speed">v = \frac{\max(|\Delta x|, |\Delta y|)}{p} \, c</Math>
<Paragraph>Equation [#eq-speed] gives a pattern's speed.</Paragraph>
</Section>
<Bibliography>
<Source id="gardner1970" type="article" author="Martin Gardner" title="Mathematical Games" journal="Scientific American" year="1970" />
</Bibliography>
</KScript.Document>import KScript.Document
Document(template: paper, title: 'How Gliders Move', author: 'Ada Lovelace', to: 'gliders.pdf') {
Abstract "A glider returns to its own shape every \( p = 4 \) generations, one cell further on."
Section(title: 'Introduction') {
Paragraph "The Game of Life [@gardner1970] is played on a square grid. Each cell has **eight neighbours**."
Math(id: 'eq-speed') "v = \frac{\max(|\Delta x|, |\Delta y|)}{p} \, c"
Paragraph "Equation [#eq-speed] gives a pattern's speed."
}
Bibliography {
Source(id: 'gardner1970', type: 'article', author: 'Martin Gardner', title: 'Mathematical Games', journal: "Scientific American", year: 1970)
}
}Чтобы начать, import KScript.Document, что подключает Document и элементы, которые в него вкладываются. Всё внутри блока Document — это обычный KScript, поэтому for, if, переменные и функции работают между элементами: таблица может строиться из данных, а раздел может повторяться для каждого элемента списка.
В папке samples/documents есть полная статья, отчёт, письмо и счёт. kscript make document создаёт новый документ.