KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

문서: KScript.Document

소개

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은 새 문서를 시작해요.

문서 저장하기

블록이 끝나면 to:이(가) 문서를 저장해요. 확장자가 형식을 결정하고, 경로 목록을 지정하면 여러 형식으로 저장해요:

<KScript.Document title="Notes" to="notes.pdf, notes.docx, notes.tex">
  <Paragraph>Saved three ways.</Paragraph>
</KScript.Document>
import KScript.Document

Document(title: 'Notes', to: ['notes.pdf', 'notes.docx', 'notes.tex']) {
  Paragraph "Saved three ways."
}
확장 결과물
.pdf KScript가 레이아웃을 잡은 PDF입니다. 페이지 번호, 클릭할 수 있는 목차와 북마크, 링크, 이미지를 포함합니다.
.docx 실제 제목, 번호 매기기 목록, 각주, Word에서 편집할 수 있는 수식, 그리고 Word가 채워 주는 목차가 있는 Word 문서입니다.
.tex pdflatex를 위한 LaTeX 파일로, \section, \label/\ref, amsmath, booktabs 및 \bibitem을(를) 포함합니다. 이미지는 경로로 참조합니다.
.md $...$수식, GitHub 표, 각주를 지원하는 Markdown입니다.
.html HTML 페이지 하나에 스타일, MathML 수식, 이미지가 모두 들어 있어요.

into:는 대신 (또는 함께) 문서를 변수에 보관하므로, 나중에 저장하거나 텍스트로 변환할 수 있어요:

<import package="KScript.Document" />

<Document title="Report" into="doc">
  <Paragraph>Hello.</Paragraph>
</Document>
<do>$doc->save('report.pdf')</do>
<echo>{ $doc->pages() } pages, { $doc->words() } words</echo>
import KScript.Document

Document(title: 'Report', into: doc) {
  Paragraph "Hello."
}
$doc->save('report.pdf')
echo "{ $doc->pages() } pages, { $doc->words() } words"
메서드 기능
->save(path, as?) 파일 확장자 또는 as:에서 선택한 형식으로 저장해요.
->pages() PDF에 있는 페이지 수입니다.
->words() 텍스트에 수학 기호와 코드를 제외하고 단어가 몇 개인지 나타냅니다.
->convert(to: markdown), ->convert(to: latex) 및 ->convert(to: html) 인쇄하거나, 보내거나, 직접 저장할 수 있는 텍스트 형식의 문서입니다.
->bytes(as: pdf|docx|html) 파일을 쓰지 않고, 렌더링된 파일을 base64 값으로 반환해요.

$doc.title은(는) 제목이에요.

라우트는 문서를 먼저 저장하지 않고도 보낼 수 있어요. ->bytes(as: pdf)은 메모리에서 문서를 렌더링하고, @response()는 바이트를 보내요:

<import package="KScript.Http" />
<import package="KScript.Document" />

<fn name="invoice" params="id: int">
  <Document title="Invoice { $id }" into="doc">
    <Paragraph>Thank you for your order.</Paragraph>
  </Document>
  <return value="@response($doc->bytes(as: pdf), type: 'application/pdf', headers: { 'Content-Disposition': &quot;inline; filename=invoice-{ $id }.pdf&quot; })" />
</fn>
import KScript.Http
import KScript.Document

fn invoice(id: int) {
  Document(title: "Invoice { $id }", into: doc) {
    Paragraph "Thank you for your order."
  }
  return @response($doc->bytes(as: pdf), type: 'application/pdf', headers: { 'Content-Disposition': "inline; filename=invoice-{ $id }.pdf" })
}

소스에서 문서 만들기

Markdown 또는 LaTeX 펜스는 import 없이 markdown 또는 latex 값을 만듭니다. .text은 소스이고 .extension는 파일 확장자입니다. 아래 메서드를 사용하려면 KScript.Document를 가져오세요. @document(source)은 펜스를 문서로 바꾸며, LaTeX 소스인 경우 as: latex을 사용하면 문자열로 바꿉니다. 일반 문자열의 기본값은 Markdown입니다.

<import package="KScript.Document" />

<fn name="notes" value="```md
    # Notes
    Ship *soon*.
    ```" />

<fn name="paper" value="```latex
    \section{Draft}
    ```" />

<echo value="@notes()->convert(to: html)" />
<do>@notes()->save('notes.pdf')</do>
<do>@paper()->replace('Draft', 'Final')->save('paper')</do>
import KScript.Document

fn notes() => ```md
  # Notes
  Ship *soon*.
  ```

fn paper() => ```latex
  \section{Draft}
  ```

echo @notes()->convert(to: html)
@notes()->save('notes.pdf')
@paper()->replace('Draft', 'Final')->save('paper')

두 종류의 펜스 모두 첫 번째 소스 오프셋에는 ->find(text), 일치하는 모든 리터럴에는 ->replace(search, replacement), 텍스트나 같은 형식의 펜스를 삽입하려면 ->insert(content, at?)를 사용합니다. 오프셋은 0부터 시작하며, 오프셋을 생략하면 끝에 추가됩니다. 이 메서드들은 편집할 때마다 새 값을 반환합니다. 경로가 .md 또는 .tex로 끝나거나 확장자가 없으면 ->save(path, as?)는 소스를 씁니다.

Markdown 펜스는 이미 문서입니다. 문서의 ->convert(to: html), ->convert(to: latex), ->words(), ->pages()를 모두 가지고 있으며, ->save()는 경로의 확장자나 as:에 따라 PDF, Word, LaTeX 또는 HTML로 렌더링합니다.

LaTeX 펜스도 문서입니다. ->convert(to: html), ->convert(to: markdown), ->words(), ->pages()를 가지며, ->save('paper.pdf') 또는 ->save('paper.docx')가 이를 렌더링합니다. KScript는 문서 부분이 읽는 LaTeX를 그대로 읽습니다. 즉 섹션, 단락, 목록, 수식, 인용, 그림, 그리고 일반적인 텍스트 명령을 읽습니다. 읽지 못하는 명령은 펜스를 렌더링할 때 그 이름을 밝히는 오류가 되며, ->save('paper.tex')을 쓰면 pdflatex 같은 LaTeX 엔진을 위해 LaTeX를 있는 그대로 유지합니다.

템플릿

템플릿은 문서의 전체적인 모양입니다. template:이 전체 모양을 고릅니다. 그런 다음 페이지와 스타일 아래의 모든 설정으로 이를 바꿀 수 있습니다.

템플릿 개요
plain 기본값입니다: 세리프 글꼴 텍스트, 번호가 매겨진 섹션, 상단에 제목이 있습니다.
paper 과학 논문이에요. 가운데 정렬된 제목, 소속과 함께 있는 저자, 초록, 들여쓴 단락, 번호가 매겨진 수식과 참고문헌이 있어요.
report 제목 페이지, 목차, 색상이 적용된 산세리프 제목, 최상위 섹션마다 새 페이지에서 시작, 제목과 페이지 번호가 들어간 바닥글.
letter Letter 요소와 함께 사용하세요: 주소, 날짜, 제목, 인사말 및 서명.
invoice 주소, 청구서 세부 정보, 세금과 합계가 포함된 항목 표와 함께 Invoice 요소에서 사용하세요.

@document_templates() 목록을 보여줘요.

텍스트 작성하기

Paragraph, Item, 캡션, 제목의 텍스트에 다음을 사용할 수 있어요:

작성 방법 대상 설명
**bold**, *italic* 굵게 및 기울임꼴 (__bold__ 및 _italic_도 포함).
`code` 코드.
[text](https://...) 링크: 웹 주소, mailto:, 또는 스킴이 없는 파일이나 #place입니다. javascript:과 같은 그 밖의 내용은 텍스트로 남습니다.
\( x^2 \) 줄 안의 수학. \[ ... \]도 동작해요.
[@key], [@a; @b] 참고문헌에 있는 출처의 인용입니다.
[#id] id 번호와 일치하는 섹션, 표, 그림 또는 수식에 대한 상호 참조입니다.
^[text] 각주입니다.
--, --- en 대시(–)와 em 대시(—).

텍스트의 빈 줄은 새 단락을 시작해요. { }은 KScript의 다른 곳과 마찬가지로 값을 넣고, $name는 변수를 넣어요. 그래서 수식에는 $ 대신 \( \)를 사용해요. \( \) 안에서는 중괄호가 LaTeX용으로 유지돼요. \( \frac{1}{2} \)는 KScript 문법이 아니라 분수를 뜻해요.

Paragraph(lines: true)은 주소나 시처럼 줄바꿈을 유지합니다. align:(왼쪽, 가운데, 오른쪽, 양쪽 맞춤)은 문서의 정렬을 덮어씁니다.

구조

<KScript.Document template="report" title="Annual Report" author="The team" to="'report.pdf'">
  <Contents />

  <Section title="Summary" id="summary">
    <Paragraph>Visits rose every quarter.</Paragraph>

    <Section title="Details">
      <List style="number">
        <Item>First point.</Item>
        <Item>Second point.</Item>
        <List>
          <Item>A point under the second.</Item>
        </List>
      </List>
    </Section>
  </Section>

  <Section title="Appendix" numbered="false" new_page="true">
    <Quote by="John Conway">I'm not a mathematician who's interested in applications.</Quote>
    <Code language="python">print('hello')</Code>
  </Section>
</KScript.Document>
import KScript.Document

Document(template: report, title: 'Annual Report', author: 'The team', to: 'report.pdf') {
  Contents

  Section(title: 'Summary', id: 'summary') {
    Paragraph "Visits rose every quarter."

    Section(title: 'Details') {
      List(style: number) {
        Item "First point."
        Item "Second point."
        List {
          Item "A point under the second."
        }
      }
    }
  }

  Section(title: 'Appendix', numbered: false, new_page: true) {
    Quote(by: 'John Conway') "I'm not a mathematician who's interested in applications."
    Code(language: 'python') "print('hello')"
  }
}
요소 개요
Author(affiliation, email) 저자입니다. 텍스트는 이름입니다. 또는 문서에 author: "Ada Lovelace; Alan Turing"를 지정하세요.
Abstract 제목 아래의 요약입니다.
Section(title, id, numbered, new_page) 섹션입니다. 섹션 안의 섹션은 하위 섹션이며, 최대 여섯 단계까지 허용됩니다. 일곱 번째 단계는 오류입니다.
Paragraph(id, align, lines) 단락이에요.
List(style, start) 및 Item 목록: bullet, number, letter 또는 roman입니다. Item 바로 뒤에 오는 List는 그 안에 중첩됩니다.
Quote(by) 인용 블록이에요.
Code(language) 고정폭 글꼴로, 작성된 그대로 유지되는 코드예요.
Contents(title, depth) PDF 파일의 페이지 번호가 포함된 목차입니다.
Markdown(path) 텍스트나 파일로 된 Markdown입니다: 아래를 참고하세요.
Latex(path, value) 텍스트, latex 값 또는 .tex 파일로 된 LaTeX입니다: 아래를 참고하세요.
PageBreak, VSpace(height), Rule 새 페이지, VSpace(height: '1cm')와 같은 간격, 그리고 페이지를 가로지르는 선입니다.

수학

Math은 한 줄을 차지하는 수식입니다. 그 텍스트는 LaTeX이며 쓴 그대로 유지되므로 중괄호와 백슬래시에 이스케이프가 필요 없습니다. 긴 수식은 여러 줄에 걸친 ```latex 블록에 넣을 수 있으며, 긴 Paragraph은 줄 끝에 \를 둘 수 있습니다(긴 문자열과 텍스트 블록을 보세요). 수식에는 번호가 매겨지며, id:를 쓰면 텍스트에서 [#id]로 그 번호를 참조할 수 있습니다:

<KScript.Document title="Maths" to="'maths.pdf'">
  <Math id="eq-gauss">\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}</Math>
  <Math numbered="false">\sum_{k=1}^{n} k = \frac{n(n+1)}{2}</Math>
  <Math>A = \begin{pmatrix} a &amp; b \\ c &amp; d \end{pmatrix}, \quad \det A = ad - bc</Math>
</KScript.Document>
import KScript.Document

Document(title: 'Maths', to: 'maths.pdf') {
  Math(id: 'eq-gauss') "\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}"
  Math(numbered: false) "\sum_{k=1}^{n} k = \frac{n(n+1)}{2}"
  Math "A = \begin{pmatrix} a & b \\\\ c & d \end{pmatrix}, \quad \det A = ad - bc"
}

"..." 문자열에서 \\는 백슬래시 하나를 쓰는 방법이므로, LaTeX 행 바꿈 \\은 \\\\로 씁니다. 환경 안에서 줄을 바꾸면 행도 끝납니다:

<KScript.Document title="Cases" to="'cases.pdf'">
  <Math>|x| = \begin{cases}
    x &amp; \text{if } x \ge 0
    -x &amp; \text{otherwise}
  \end{cases}</Math>
</KScript.Document>
import KScript.Document

Document(title: 'Cases', to: 'cases.pdf') {
  Math "|x| = \begin{cases}
    x & \text{if } x \ge 0
    -x & \text{otherwise}
  \end{cases}"
}

수학이 이해하는 것:

  • 문자, 숫자, 연산자를 TeX의 간격 규칙에 따라 표시합니다. 위첨자와 아래첨자에는 ^과 _를, 프라임에는 '을 사용합니다.
  • \frac, \dfrac, \tfrac, \binom, \sqrt, \sqrt[n].
  • 그리스 문자(\alpha부터 \Omega까지), 관계 기호(\le, \approx, \in, \subseteq, \to...), 연산자(\pm, \times, \cdot, \cup...), 화살표, 그리고 \infty, \partial, \nabla, \forall, \exists 같은 기호.
  • 한계를 가진 큰 연산자: \sum, \prod, \int, \iint, \oint, \bigcup...; \sin, \log, \lim, \max, \operatorname{name}과 같은 함수.
  • \left( ... \right) 및 기타 구분 기호는 내용에 맞게 늘어납니다.
  • matrix, pmatrix, bmatrix, vmatrix, cases, aligned 및 array 환경.
  • \text{...}, \mathbf, \mathit, \mathrm, \mathbb, \mathcal, \mathsf, \mathtt; 그리고 \hat, \bar, \vec, \dot, \tilde, \overline, \underline 같은 강세 기호; 그리고 공백 \,, \;, \quad, \qquad.

알 수 없는 명령은 명령 이름을 포함한 오류로 처리되므로, 오타는 완성된 PDF가 아니라 스크립트가 실행될 때 잡힙니다. 각 형식은 자체 형태로 수식을 표시합니다. PDF에는 그려서, LaTeX에서는 amsmath로, .docx에서는 Word 수식으로, HTML에서는 MathML로 표시합니다.

표

테이블은 데이터에서 만들 수 있으며, 데이터는 보통 맵의 목록이에요:

<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:는 제목에서 키로 가는 맵(또는 키 목록, 이 목록도 제목이 됩니다)입니다. 이 값이 없으면 첫 번째 맵의 키가 열이 됩니다. 행의 필드를 알고 있을 때, 예를 들어 스크립트에 작성된 맵 목록이나 모델의 레코드인 경우 편집기가 키를 자동으로 채우고 kscript check는 행에 없는 키를 알려줍니다. 숫자는 align:에서 다르게 지정하지 않는 한 오른쪽으로 정렬됩니다.

또는 행을 Tr로 쓰고, 셀은 |로 구분해요:

<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:는 표를 텍스트와 같은 너비로 만들고, 그 비율대로 너비를 나눕니다. 이 옵션이 없으면 각 열은 텍스트 너비만큼만 됩니다. rules:는 booktabs(헤더 위, 아래, 밑의 선; 기본값), grid 또는 none입니다. size: 0.9는 텍스트를 더 작게 만듭니다. 캡션은 표에 번호를 매기며, 표가 새 페이지로 넘어갈 때 헤더 행이 반복됩니다(LaTeX에서는 같은 이유로 30행이 넘는 표가 longtable가 됩니다). 행이 없는 표는 LaTeX 및 Markdown 파일에서 제외됩니다.

그림

<KScript.Document title="Gliders" to="'gliders.pdf'">
  <Figure path="glider.png" caption="A glider over four generations." id="fig-glider" width="0.8" />
</KScript.Document>
import KScript.Document

Document(title: 'Gliders', to: 'gliders.pdf') {
  Figure(path: 'glider.png', caption: 'A glider over four generations.', id: 'fig-glider', width: 0.8)
}

path:는 스크립트를 기준으로 한 PNG 또는 JPEG 파일이에요. width:는 본문 너비에 대한 비율이에요(0.5 또는 '50%'). 캡션이 있는 그림은 [#id]에 맞춰 번호가 매겨져요.

인용 및 참고 문헌

[@key]를 사용해 인용하세요. 출처는 BibTeX 파일, Source 요소, 또는 둘 다에서 가져올 수 있습니다:

<KScript.Document template="paper" title="Cited" to="'cited.pdf'">
  <Paragraph>Life is universal [@berlekamp1982; @rendell2002].</Paragraph>

  <Bibliography path="refs.bib">
    <Source id="rendell2002" type="inproceedings" author="Paul Rendell" title="Turing Universality of the Game of Life" booktitle="Collision-Based Computing" year="2002" />
  </Bibliography>
</KScript.Document>
import KScript.Document

Document(template: paper, title: 'Cited', to: 'cited.pdf') {
  Paragraph "Life is universal [@berlekamp1982; @rendell2002]."

  Bibliography(path: 'refs.bib') {
    Source(id: 'rendell2002', type: 'inproceedings', author: 'Paul Rendell', title: 'Turing Universality of the Game of Life', booktitle: "Collision-Based Computing", year: 2002)
  }
}

인용된 출처만 목록에 나옵니다. citations: numeric(기본값)를 사용하면 처음 인용된 순서대로 [1]과 같이 번호가 매겨집니다. citations: author-year를 사용하면 (Berlekamp et al., 1982)와 같은 형식으로 표시되며, 목록은 저자 순으로 정렬됩니다. Source는 BibTeX 필드를 속성으로 받으며, author는 사람 이름을 and로 구분합니다. 출처를 인용하면서 Bibliography를 생략하면 참고 문헌은 문서 끝에 배치됩니다.

존재하지 않는 id를 가리키는 인용이나 상호 참조는 오류입니다. 같은 id를 두 번 사용하는 것도 오류입니다. id:은 다른 텍스트와 마찬가지로 텍스트이므로, 반복문에서 항목마다 Section(title: $chapter.title, id: "ch-{ $chapter.number }")와 같은 값을 만들 수 있습니다.

각주와 상호 참조

^[text]는 페이지 하단에 번호가 매겨진 각주를 넣어요 (Word에서는 실제 각주로, HTML과 Markdown에서는 문서 끝에 주석으로 표시돼요). [#id]는 해당 id를 가진 섹션, 표, 그림 또는 수식의 번호로 바뀌어요. 그래서 단어는 직접 써야 해요. Section [#methods]는 "Section 2"로, Equation [#eq-speed]는 "Equation (3)"으로 표시돼요. PDF와 Word에서는 번호가 링크로 표시돼요.

Markdown

Markdown는 Markdown을 문서 내용으로 추가합니다. # 제목은 수준에 따라 중첩된 섹션이 되며, 단락, 목록, 표, 코드 블록, 인용문, --- 구분선, ![caption](image.png){#id} 그림을 포함할 수 있습니다. 제목과 수식에는 id를 지정할 수 있습니다: ## Results {#results}, \[ E = mc^2 \] {#eq-energy}.

<KScript.Document title="From Markdown" to="'notes.pdf'">
  <Markdown path="chapters/introduction.md" />
  <Markdown>
    ## Summary

    - Every chapter is a Markdown file.
    - The script puts them together.
  </Markdown>
</KScript.Document>
import KScript.Document

Document(title: 'From Markdown', to: 'notes.pdf') {
  Markdown(path: 'chapters/introduction.md')
  Markdown "
    ## Summary

    - Every chapter is a Markdown file.
    - The script puts them together.
  "
}

Markdown 파일에서는 $x$와 $$ ... $$도 수식으로 처리됩니다. 스크립트 안의 텍스트에서는 \( \)와 \[ \]를 사용하세요. $는 그곳에서 변수이기 때문입니다.

LaTeX

Latex은 문서 부분이 읽는 방식대로 LaTeX를 문서 내용으로 추가합니다. 그 텍스트는 쓴 그대로 사용되므로 중괄호와 백슬래시는 LaTeX의 것입니다. value:과 함께 latex 값을 받을 수도 있고, path:와 함께 .tex 파일을 받을 수도 있습니다.

  <import package="KScript.Document" />

  <fn name="method" value="```latex
      \subsection{Method}
      We counted \textbf{gliders} by hand.
      ```" />

  <Document title="From LaTeX" to="paper.pdf">
    <Latex>\section{Results}
Gliders travel \emph{diagonally}, and $N(t) = N_0 e^{rt}$.</Latex>
    <Latex value="@method()" />
    <Latex path="chapters/discussion.tex" />
  </Document>
import KScript.Document

fn method() => ```latex
  \subsection{Method}
  We counted \textbf{gliders} by hand.
  ```

Document(title: "From LaTeX", to: "paper.pdf") {
  Latex ```latex
    \section{Results}
    Gliders travel \emph{diagonally}, and $N(t) = N_0 e^{rt}$.
    ```
  Latex(value: @method())
  Latex(path: "chapters/discussion.tex")
}

읽을 수 없는 명령은 그 명령의 이름을 포함한 오류로 표시돼요.

부품을 컴포넌트로

A part you use in several documents, such as a finding, a method or a signature block, can be a component. Its render holds document elements, or returns the part as a md or latex block, and a document draws it by name: Finding(title: "Gliders", count: 3).

편지와 청구서

Letter은 그 안의 단락을 중심으로 편지를 구성해요. 주소에서는 \n가 새 줄을 시작해요:

<KScript.Document template="letter" to="'letter.pdf'">
  <Letter from="{'Life Lab\n12 Grid Street\nCambridge'}" to="{'Dr Ada Lovelace\nExample University'}" subject="Invitation to speak" opening="Dear Dr Lovelace," closing="Yours sincerely," signature="Alan Turing">
    <Paragraph>We would be delighted if you would give the opening talk.</Paragraph>
  </Letter>
</KScript.Document>
import KScript.Document

Document(template: letter, to: 'letter.pdf') {
  Letter(from: 'Life Lab\n12 Grid Street\nCambridge', to: 'Dr Ada Lovelace\nExample University', subject: 'Invitation to speak', opening: 'Dear Dr Lovelace,', closing: 'Yours sincerely,', signature: 'Alan Turing') {
    Paragraph "We would be delighted if you would give the opening talk."
  }
}

Invoice는 항목 목록으로 전체 청구서를 만듭니다. 각 항목에는 description, quantity(기본값 1), 그리고 price 또는 amount가 있습니다. 소계, 세금, 합계는 자동으로 계산됩니다:

<let name="items" value="[{ description: 'Consulting', quantity: 3, price: 450 }, { description: 'Travel', price: 64.2 }]" />

<import package="KScript.Document" />

<Document template="invoice" to="'invoice.pdf'">
  <Invoice number="INV-042" from="{'Life Lab Ltd\n12 Grid Street'}" to="Example University" due="20 December 2026" items="$items" currency="GBP" tax="20" notes="Please pay within 30 days." />
</Document>
$items = [{ description: 'Consulting', quantity: 3, price: 450 }, { description: 'Travel', price: 64.2 }]

import KScript.Document

Document(template: invoice, to: 'invoice.pdf') {
  Invoice(number: 'INV-042', from: 'Life Lab Ltd\n12 Grid Street', to: 'Example University', due: '20 December 2026', items: $items, currency: 'GBP', tax: 20, notes: 'Please pay within 30 days.')
}

currency:는 GBP, USD, EUR 또는 JPY와 같은 코드이거나 임의의 기호입니다. tax:는 백분율이고, tax_name:는 이름입니다(기본 VAT). paid:는 이미 지불된 금액이며, 이 금액이 있으면 잔액이 남습니다.

페이지와 스타일

이 항목들은 Document에 적용되며 템플릿에서 설정한 값을 바꿔요.

속성 기능
paper a4 (기본값), a3, a5, b5, letter 또는 legal, 또는 '15cm x 20cm'처럼 따옴표로 묶은 크기를 사용할 수 있어요. landscape: true은 이를 켜요.
margin 한 가지 크기('2.5cm'), 또는 '2cm 3cm'(위·아래, 좌·우), 또는 CSS처럼 네 가지 크기. 크기는 mm, cm, in 또는 pt일 수 있으며, 따옴표로 감싸요.
font, heading_font serif (Times), sans (Helvetica) 또는 mono (Courier).
size, line_height 텍스트 크기(포인트 단위, 11)와 이에 대한 배수로 표시한 줄 간격(1.4)입니다.
align justify, left, center 또는 right예요.
accent 제목과 표지 페이지의 색상을 따옴표로 묶어 표시합니다. 예: '#1f4e79' 또는 'navy' 같은 이름.
numbered false은(는) 번호가 없는 섹션을 남겨 둬요.
title_page, chapters true 는 제목을 별도의 페이지에 두고, 최상위 섹션마다 새 페이지에서 시작하도록 합니다.
citations numeric 또는 author-year.
header, footer 'left | centre | right', with [page], [pages], [title], [author] and [date]. footer: "| Page [page] of [pages] |" centres a page count. footer: "" has none.
rules 기본 테이블 줄: booktabs, grid 또는 none입니다.
language 텍스트의 언어(예: 'en-GB')로, Word의 맞춤법 검사와 HTML에 사용됩니다.

글꼴과 문자

PDF는 모든 PDF 리더에 기본으로 들어 있는 글꼴(Times, Helvetica, Courier, Symbol)을 사용하므로 글꼴을 포함하지 않아 파일 크기가 작게 유지돼요. 이 글꼴들은 서유럽 언어, 기본 그리스 문자, 수학 기호를 지원해요. 중국어, 이모지, 액센트가 있는 그리스 문자(ά)처럼 이 범위를 벗어난 문자는 PDF에서 ?로 표시되지만, Word, HTML, Markdown, LaTeX 파일에서는 그대로 유지돼요.

명령

명령어 기능
@latex_escape(text) LaTeX 파일에 안전하게 넣을 수 있도록 처리된 텍스트입니다: \ { } $ & % # _ ~ ^은 이스케이프됩니다.
@document_templates() 템플릿과 각 템플릿의 용도예요.