简介
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 用于新建一个文档。