feat: initial commit

This commit is contained in:
johannes committed 2026-07-26 11:42:17 +02:00
commit b802ff49ab
454 files changed
+52429

No files matched your search

@@ -0,0 +1,35 @@
# Artifact
# pdf.artifact
Marks content as a PDF artifact.
Artifacts are parts of the document that are not meant to be read by Assistive Technology (AT), such as screen readers. Typical examples include purely decorative images that do not contribute to the meaning of the document, watermarks, or repeated content such as page numbers.
Typst will automatically mark certain content, such as page headers, footers, backgrounds, and foregrounds, as artifacts. Likewise, paths and shapes are automatically marked as artifacts, but their content is not. Repetitions of table headers and footers are also marked as artifacts.
Once something is marked as an artifact, you cannot make any of its contents accessible again. If you need to mark only part of something as an artifact, you may need to use this function multiple times.
If you are unsure what constitutes an artifact, check the [Accessibility Guide](/docs/guides/accessibility/#artifacts).
In the future, this function may be moved out of the `pdf` module, making it possible to hide content in HTML export from AT.
```typst
#pdf.artifact(
kind: str,
body
) -> content
```
## Parameters
- kind:
- description: The artifact kind. This will govern how the PDF reader treats the artifact during reflow and content extraction (e.g. copy and paste).
- type: str
- default: "other"
- body:
- description: The content that is an artifact.
- type: content
- default: None
@@ -0,0 +1,60 @@
# Attach
# pdf.attach
A file that will be attached to the output PDF.
This can be used to distribute additional files associated with the PDF within it. PDF readers will display the files in a file listing.
Some international standards use this mechanism to attach machine-readable data (e.g., ZUGFeRD/Factur-X for invoices) that mirrors the visual content of the PDF.
## Example
```typst
#pdf.attach(
"experiment.csv",
relationship: "supplement",
mime-type: "text/csv",
description: "Raw Oxygen readings from the Arctic experiment",
)
```
## Notes
- This element is ignored if exporting to a format other than PDF.
- File attachments are not currently supported for PDF/A-2, even if the attached file conforms to PDF/A-1 or PDF/A-2.
```typst
#pdf.attach(
path,
data,
relationship: none | str,
mime-type: none | str,
description: none | str
) -> content
```
## Parameters
- path:
- description: The [path](/docs/reference/syntax/#paths) of the file to be attached. Must always be specified, but is only read from if no data is provided in the following argument.
- type: str
- default: None
- data:
- description: Raw file data, optionally. If omitted, the data is read from the specified path.
- type: bytes
- default: None
- relationship:
- description: The relationship of the attached file to the document. Ignored if export doesn\'t target PDF/A-3.
- type: none | str
- default: none
- mime-type:
- description: The MIME type of the attached file.
- type: none | str
- default: none
- description:
- description: A description for the attached file.
- type: none | str
- default: none
@@ -0,0 +1,56 @@
# Data Cell
# pdf.data-cell
Explicitly defines this cell as a data cell.
Each cell in a table is either a header cell or a data cell. By default, all cells in [`table.header`](/docs/reference/model/table/#definitions-header) are header cells, and all other cells data cells.
If your header contains a cell that is not a header cell, you can use this function to mark it as a data cell.
The API of this feature is temporary. Hence, calling this function requires enabling the `a11y-extras` feature flag at the moment. In a future Typst release, this functionality may move out of the `pdf` module so that tables in other export targets can contain the same information.
```typst
#show table.cell.where(x: 0): set text(weight: "bold")
#show table.cell.where(x: 1): set text(style: "italic")
#show table.cell.where(x: 1, y: 0): set text(style: "normal")
#table(
columns: 3,
align: (left, left, center),
table.header[Objective][Key Result][Status],
table.header(
level: 2,
table.cell(colspan: 2)[Improve Customer Satisfaction],
// Status is data for this objective, not a header
pdf.data-cell[✓ On Track],
),
[], [Increase NPS to 50+], [45],
[], [Reduce churn to \<5%], [4.2%],
table.header(
level: 2,
table.cell(colspan: 2)[Grow Revenue],
pdf.data-cell[⚠ At Risk],
),
[], [Achieve \$2M ARR], [\$1.8M],
[], [Close 50 enterprise deals], [38],
)
```
```typst
#pdf.data-cell(
cell
) -> content
```
## Parameters
- cell:
- description: The table cell. This can be content or a call to [`table.cell`](/docs/reference/model/table/#definitions-cell).
- type: content
- default: None
@@ -0,0 +1,70 @@
# Header Cell
# pdf.header-cell
Explicitly defines a cell as a header cell.
Header cells help users of Assistive Technology (AT) understand and navigate complex tables. When your table is correctly marked up with header cells, AT can announce the relevant header information on-demand when entering a cell.
By default, Typst will automatically mark all cells within [`table.header`](/docs/reference/model/table/#definitions-header) as header cells. They will apply to the columns below them. You can use that function's [`level`](/docs/reference/model/table/#definitions-header-level) parameter to make header cells labelled by other header cells.
The `pdf.header-cell` function allows you to indicate that a cell is a header cell in the following additional situations:
- You have a **header column** in which each cell applies to its row. In that case, you pass `"row"` as an argument to the [`scope` parameter](/docs/reference/pdf/header-cell/#parameters-scope) to indicate that the header cell applies to the row.
- You have a cell in [`table.header`](/docs/reference/model/table/#definitions-header), for example at the very start, that labels both its row and column. In that case, you pass `"both"` as an argument to the [`scope`](/docs/reference/pdf/header-cell/#parameters-scope) parameter.
- You have a header cell in a row not containing other header cells. In that case, you can use this function to mark it as a header cell.
The API of this feature is temporary. Hence, calling this function requires enabling the `a11y-extras` feature flag at the moment. In a future Typst release, this functionality may move out of the `pdf` module so that tables in other export targets can contain the same information.
```typst
#show table.cell.where(x: 0): set text(weight: "medium")
#show table.cell.where(y: 0): set text(weight: "bold")
#table(
columns: 3,
align: (start, end, end),
table.header(
// Top-left cell: Labels both the nutrient rows
// and the serving size columns.
pdf.header-cell(scope: "both")[Nutrient],
[Per 100g],
[Per Serving],
),
// First column cells are row headers
pdf.header-cell(scope: "row")[Calories],
[250 kcal], [375 kcal],
pdf.header-cell(scope: "row")[Protein],
[8g], [12g],
pdf.header-cell(scope: "row")[Fat],
[12g], [18g],
pdf.header-cell(scope: "row")[Carbs],
[30g], [45g],
)
```
```typst
#pdf.header-cell(
level: int,
scope: str,
cell
) -> content
```
## Parameters
- level:
- description: The nesting level of this header cell.
- type: int
- default: 1
- scope:
- description: What track of the table this header cell applies to.
- type: str
- default: "column"
- cell:
- description: The table cell. This can be content or a call to [`table.cell`](/docs/reference/model/table/#definitions-cell).
- type: content
- default: None
@@ -0,0 +1,105 @@
# PDF
PDF files focus on accurately describing documents visually, but also have facilities for annotating their structure. This hybrid approach makes them a good fit for document exchange: They render exactly the same on every device, but also support extraction of a document's content and structure (at least to an extent). Unlike PNG files, PDFs are not bound to a specific resolution. Hence, you can view them at any size without incurring a loss of quality.
## Exporting as PDF
### Command Line
PDF is Typst's default export format. Running the `compile` or `watch` subcommand without specifying a format will create a PDF. When exporting to PDF, you have the following configuration options:
- Which [PDF standards](#pdf-standards) Typst should enforce conformance with by specifying `--pdf-standard` followed by one or multiple comma-separated standards. Valid standards are `1.4`, `1.5`, `1.6`, `1.7`, `2.0`, `a-1b`, `a-1a`, `a-2b`, `a-2u`, `a-2a`, `a-3b`, `a-3u`, `a-3a`, `a-4`, `a-4f`, `a-4e`, and `ua-1`. By default, Typst outputs PDF-1.7-compliant files.
- You can disable PDF tagging completely with `--no-pdf-tags`. By default, Typst will always write _Tagged PDF_ to provide a baseline level of accessibility. Using this flag, you can turn tags off. This will make your file inaccessible and prevent conformance with accessible conformance levels of PDF/A and all parts of PDF/UA.
- Which pages to export by specifying `--pages` followed by a comma-separated list of numbers or dash-separated number ranges. Ranges can be half-open. Example: `2,3,7-9,11-`.
### Web App
Click the quick download button at the top right to export a PDF with default settings. For further configuration, click "File" \> "Export as" \> "PDF" or click the downwards-facing arrow next to the quick download button and select "Export as PDF". When exporting to PDF, you have the following configuration options:
- Which PDF standards Typst should enforce conformance with. By default, Typst outputs PDF-1.7-compliant files. You can choose the PDF version freely between 1.4 and 2.0. Valid additional standards are `A-1b`, `A-1a`, `A-2b`, `A-2u`, `A-2a`, `A-3b`. `A-3u`, `A-3a`, `A-4`, `A-4f`, `A-4e`, and `UA-1`.
- Which pages to export. Valid options are "All pages", "Current page", and "Custom ranges". Custom ranges are a comma-separated list of numbers or dash-separated number ranges. Ranges can be half-open. Example: `2,3,7-9,11-`.
## PDF standards
The International Standards Organization (ISO) has published the base PDF standard and various standards that extend it to make PDFs more suitable for specific use-cases. By default, Typst exports PDF 1.7 files. Adobe Acrobat 8 and later as well as all other commonly used PDF viewers are compatible with this PDF version.
Some features of Typst may not be available depending on the PDF standard you choose. You currently cannot choose both PDF/A and PDF/UA at the same time.
### PDF versions
Typst supports five different PDF versions: 1.4, 1.5, 1.6, 1.7 (default), and 2.0. You can choose each of these versions for your document export. However, based on the features you used there may be a minimum version. Likewise, the standards you target can limit which versions you can choose (see below for more).
Here is a list on how each new version improves over PDF 1.4 for Typst documents:
- **PDF 1.5** (2003): Improved color management, text extraction, table accessibility, reflow, and emoji fonts
- **PDF 1.6** (2004): More flexible links
- **PDF 1.7** (2006): Allows [attachments](/docs/reference/pdf/attach/), improved reflow
- **PDF 2.0** (2017): Improved both metadata and tag semantics for accessibility
The software used to read your file must support your PDF version. Under normal circumstances, this poses no problem, but it can be a source of errors when working with older hardware. For general exchange, we recommend keeping the default PDF 1.7 setting or choosing PDF 2.0.
When using PDF files as [images](/docs/reference/visualize/image/) in your document, the export PDF version must equal or exceed the image file versions.
### PDF/UA
Typst supports writing PDF/UA-conformant files. PDF/UA files are designed for _Universal Access._ When you choose this PDF standard, Typst will run additional checks when exporting your document. These checks will make sure that you are following accessibility best practices. For example, it will make sure that all your images come with alternative descriptions.
Note that there are some rules in PDF/UA that are crucial for accessibility but cannot be automatically checked. Hence, when exporting a PDF/UA-1 document, make sure you did the following:
- If your document is written in a different language than English, make sure [set the text language](/docs/reference/text/text/#parameters-lang) before any content.
- Make sure to use Typst's semantic elements (like [headings](/docs/reference/model/heading/), [figures](/docs/reference/model/figure/), and [lists](/docs/reference/model/list/)) when appropriate instead of defining custom constructs. This lets Typst know (and export) the role a construct plays in the document. See [the Accessibility guide](/docs/guides/accessibility/) for more details.
- Do not exclusively use contrast, color, format, or layout to communicate an idea. Use text or alternative descriptions instead of or in addition to these elements.
- Wrap all decorative elements without a semantic meaning in [`pdf.artifact`](/docs/reference/pdf/artifact/).
- Do not use images of text. Instead, insert the text directly into your markup.
Typst currently only supports part one (PDF/UA-1) which is based on PDF 1.7 (2006). When exporting to PDF/UA-1, be aware that you will need to manually provide [alternative descriptions of mathematics](/docs/reference/math/#accessibility) in natural language.
New accessibility features were added to PDF 2.0 (2017). When set to PDF 2.0 export, Typst will leverage some of these features. PDF 2.0 and PDF/UA-1, however, are mutually incompatible. For accessible documents, we currently recommend exporting to PDF/UA-1 instead of PDF 2.0 for the additional checks and greater compatibility. The second part of PDF/UA is designed for PDF 2.0, but not yet supported by Typst.
### PDF/A
Typst optionally supports emitting PDF/A-conformant files. PDF/A files are geared towards maximum compatibility with current and future PDF tooling. They do not rely on difficult-to-implement or proprietary features and contain exhaustive metadata. This makes them suitable for long-term archival.
The PDF/A Standard has multiple versions (_parts_ in ISO terminology) and most parts have multiple profiles that indicate the file's conformance level. You can target one part and conformance level at a time. Currently, Typst supports these PDF/A output profiles:
- **PDF/A-1b:** The _basic_ conformance level of ISO 19005-1. This version of PDF/A is based on PDF 1.4 (2001) and results in self-contained, archivable PDF files. As opposed to later parts of the PDF/A standard, transparency is not allowed in PDF/A-1 files.
- **PDF/A-1a:** This is the _accessible_ conformance level that builds on the basic level PDF/A-1b. To conform to this level, your file must be an accessible _Tagged PDF_ file. Note that accessibility is improved with later parts as not all PDF accessibility features are available for PDF 1.4 files. Furthermore, all text in the file must consist of known Unicode code points.
- **PDF/A-2b:** The _basic_ conformance level of ISO 19005-2. This version of PDF/A is based on PDF 1.7 (2006) and results in self-contained, archivable PDF files.
- **PDF/A-2u:** This is the _Unicode-mappable_ conformance level that builds on the basic level A-2b. It also adds rules that all text in the document must consist of known Unicode code points. If possible, always prefer this standard over PDF/A-2b.
- **PDF/A-2a:** This is the _accessible_ conformance level that builds on the Unicode-mappable level A-2u. This conformance level also adds two requirements: Your file must be an accessible _Tagged PDF_ file. Typst automatically adds tags to help you reach this conformance level. Also pay attention to the Accessibility Sections throughout the reference and the [Accessibility Guide](/docs/guides/accessibility/) when targeting this conformance level. Finally, PDF/A-2a forbids you from using code points in the [Unicode Private Use area](https://en.wikipedia.org/wiki/Private_Use_Areas). If you want to build an accessible file, also consider additionally targeting PDF/UA-1, which enables more automatic accessibility checks.
- **PDF/A-3b:** The _basic_ conformance level of ISO 19005-3. This version of PDF/A is based on PDF 1.7 (2006) and results in archivable PDF files that can contain arbitrary other related files as [attachments](/docs/reference/pdf/attach/). The only difference between it and PDF/A-2b is the capability to attach non-PDF/A-conformant files.
- **PDF/A-3u:** This is the _Unicode-mappable_ conformance level that builds on the basic level A-3b. Just like PDF/A-2b, this requires all text to consist of known Unicode code points. These rules do not apply to attachments. If possible, always prefer this standard over PDF/A-3b.
- **PDF/A-3a:** This is the _accessible_ conformance level that builds on the Unicode-mappable level A-3u. Just like PDF/A-2a, this requires files to be accessible _Tagged PDF_ and to not use characters from the Unicode Private Use area. Just like before, these rules do not apply to attachments.
- **PDF/A-4:** The basic conformance level of ISO 19005-4. This version of PDF/A is based on PDF 2.0 (2017) and results in self-contained, archivable PDF files. PDF/A-4 has no parts relating to accessibility. Instead, the topic has been elaborated on more in the dedicated PDF/UA standard. PDF/A-4 files can conform to PDF/UA-2 (currently not supported in Typst).
- **PDF/A-4f:** The _embedded files_ conformance level that builds on the basic level A-4. Files conforming to this level can contain arbitrary other related files as [attachments](/docs/reference/pdf/attach/), just as files conforming to part 3 of ISO 19005. The only difference between it and PDF/A-4 is the capability to attach non-PDF/A-conformant files.
- **PDF/A-4e:** The _engineering_ conformance level that builds on the embedded files level A-4f. Files conforming to this level can contain 3D objects. Typst does not support 3D content, so this is functionally equivalent to PDF/A-4f from a Typst perspective.
If you want to target PDF/A but are unsure about which particular setting to use, there are some good rules of thumb. First, you must determine your **part,** that's the "version number" of the standard. Ask yourself these questions:
1. **Does pre-2006 software or equipment need to be able to read my file?** If so, choose part one (PDF/A-1).
2. **If not, does my file need attachments?** If so, you must choose part three (PDF/A-3) or the embedded files level of part four (PDF/A-4f).
3. **Does your file need to use features introduced in PDF 2.0?** Currently, use of PDF 2.0 features in Typst is limited to minor improvements in accessibility, e.g. for the [title element](/docs/reference/model/title/). If you can do without these improvements, maximize compatibility by choosing part two (when you don't need attachments) or part three (when you do need attachments). If you rely on PDF 2.0 features, use part four.
Now, you only need to choose a **conformance level** (the lowercase letter at the end).
- **If you decided on part one, two, or three,** you should typically choose the accessible conformance level of your part, indicated by a lowercase `a` at the end. If your document is inherently inaccessible, e.g. an artist's portfolio that cannot be boiled down to alternative descriptions, choose conformance level `u` instead. Only if this results in a compiler error, e.g. because you used code points from the Unicode Private Use Area, use the basic level `b`.
- **If you have chosen part four,** you should choose the basic conformance level (PDF/A-4) except when needing to embed files.
When choosing between exporting PDF/A and regular PDF, keep in mind that PDF/A files contain additional metadata, and that some readers will prevent the user from modifying a PDF/A file.
## PDF-specific functionality
Typst exposes PDF-specific functionality in the global `pdf` module. See below for the definitions it contains.
This module contains some functions without a final API. They are designed to enhance accessibility for documents with complex tables. This includes [`table-summary`](/docs/reference/pdf/table-summary/), [`header-cell`](/docs/reference/pdf/header-cell/), and [`data-cell`](/docs/reference/pdf/data-cell/). All of these functions will be removed in a future Typst release, either through integration into table functions or through full removal. You can enable these functions by passing `--features a11y-extras` or setting the `TYPST_FEATURES` environment variable to `a11y-extras`. In the web app, these features are not available at this time.
## Definitions
| Name | Description |
| --- | --- |
| [`artifact`](/reference/pdf/artifact/) | Marks content as a PDF artifact. |
| [`attach`](/reference/pdf/attach/) | A file that will be attached to the output PDF. |
| [`data-cell`](/reference/pdf/data-cell/) | Explicitly defines this cell as a data cell. |
| [`header-cell`](/reference/pdf/header-cell/) | Explicitly defines a cell as a header cell. |
| [`table-summary`](/reference/pdf/table-summary/) | A summary of the purpose and structure of a complex table. |
@@ -0,0 +1,54 @@
# Table Summary
# pdf.table-summary
A summary of the purpose and structure of a complex table.
This will be available for Assistive Technology (AT), such as screen readers, when exporting to PDF, but not for sighted readers of your file.
This field is intended for instructions that help the user navigate the table using AT. It is not an alternative description, so do not duplicate the contents of the table within. Likewise, do not use this for the core takeaway of the table. Instead, include that in the text around the table or, even better, in a [figure caption](/docs/reference/model/figure/#definitions-caption).
If in doubt whether your table is complex enough to warrant a summary, err on the side of not including one. If you are certain that your table is complex enough, consider whether a sighted user might find it challenging. They might benefit from the instructions you put here, so consider printing them visibly in the document instead.
The API of this feature is temporary. Hence, calling this function requires enabling the `a11y-extras` feature flag at the moment. Even if this functionality should be available without a feature flag in the future, the summary will remain exclusive to PDF export.
```typst
#figure(
pdf.table-summary(
// The summary just provides orientation and structural
// information for AT users.
summary: "The first two columns list the names of each participant. The last column contains cells spanning multiple rows for their assigned group.",
table(
columns: 3,
table.header[First Name][Given Name][Group],
[Mike], [Davis], table.cell(rowspan: 3)[Sales],
[Anna], [Smith],
[John], [Johnson],
[Sara], [Wilkins], table.cell(rowspan: 2)[Operations],
[Tom], [Brown],
),
),
// This is the key takeaway of the table, so we put it in the caption.
caption: [The Sales org now has a new member],
)
```
```typst
#pdf.table-summary(
summary: str,
table
) -> content
```
## Parameters
- summary:
- description:
- type: str
- default: None
- table:
- description: The table.
- type: content
- default: None