You can export your documents to various formats using the export
feature.
Export from Query Result
Hello World Example (VSCode Tasks)
You can export the result of a query as text using the export
command.
Given a code:
1
#println("Hello World!")
2
#println("Hello World! Again...")
1
#println("Hello World!")
2
#println("Hello World! Again...")
LSP should export the result of the query as text with the following content:
1
Hello World!
2
Hello World! Again...
1
Hello World!
2
Hello World! Again...
This requires the following configuration in your tasks.json
file:
1
{
2
"version": "2.0.0",
3
"tasks": [
4
{
5
"label": "Query as Text",
6
"type": "typst",
7
"command": "export",
8
"export": {
9
"format": "query",
10
"query.format": "txt",
11
"query.outputExtension": "out",
12
"query.field": "value",
13
"query.selector": "<print-effect>",
14
"query.one": true
15
}
16
},
17
]
18
}
1
{
2
"version": "2.0.0",
3
"tasks": [
4
{
5
"label": "Query as Text",
6
"type": "typst",
7
"command": "export",
8
"export": {
9
"format": "query",
10
"query.format": "txt",
11
"query.outputExtension": "out",
12
"query.field": "value",
13
"query.selector": "<print-effect>",
14
"query.one": true
15
}
16
},
17
]
18
}
See the Sample Workspace: print-state for more details.
Pdfpc Example (VSCode Tasks)
A more practical example is exporting the result of a query as a pdfpc file. You can use the following configuration in your tasks.json
file to export the result of a query as a pdfpc file, which is adapted by Touying Slides.
1
{
2
"label": "Query as Pdfpc",
3
"type": "typst",
4
"command": "export",
5
"export": {
6
"format": "query",
7
"query.format": "json",
8
"query.outputExtension": "pdfpc",
9
"query.selector": "<pdfpc-file>",
10
"query.field": "value",
11
"query.one": true
12
}
13
}
1
{
2
"label": "Query as Pdfpc",
3
"type": "typst",
4
"command": "export",
5
"export": {
6
"format": "query",
7
"query.format": "json",
8
"query.outputExtension": "pdfpc",
9
"query.selector": "<pdfpc-file>",
10
"query.field": "value",
11
"query.one": true
12
}
13
}
To simplify configuration,
1
{
2
"label": "Query as Pdfpc",
3
"type": "typst",
4
"command": "export",
5
"export": {
6
"format": "pdfpc"
7
}
8
}
1
{
2
"label": "Query as Pdfpc",
3
"type": "typst",
4
"command": "export",
5
"export": {
6
"format": "pdfpc"
7
}
8
}
VSCode: Task Configuration
You can configure tasks in your tasks.json
file to "persist" the arguments for exporting documents.
Example:
1
{
2
"version": "2.0.0",
3
"tasks": [
4
{
5
"label": "Export as Html",
6
"type": "typst",
7
"command": "export",
8
"export": {
9
"format": "html"
10
}
11
},
12
{
13
"label": "Export as Markdown",
14
"type": "typst",
15
"command": "export",
16
"export": {
17
"format": "markdown"
18
}
19
},
20
{
21
"label": "Export as Plain Text",
22
"type": "typst",
23
"command": "export",
24
"export": {
25
"format": "html"
26
}
27
},
28
{
29
"label": "Export as SVG",
30
"type": "typst",
31
"command": "export",
32
"export": {
33
"format": "svg",
34
"merged": true
35
}
36
},
37
{
38
"label": "Export as PNG",
39
"type": "typst",
40
"command": "export",
41
"export": {
42
"format": "png",
43
// Default fill is white, but you can set it to transparent.
44
"fill": "#00000000",
45
"merged": true
46
}
47
},
48
{
49
"label": "Query as Pdfpc",
50
"type": "typst",
51
"command": "export",
52
"export": {
53
"format": "pdfpc"
54
}
55
},
56
{
57
"label": "Export as PNG and SVG",
58
"type": "typst",
59
"command": "export",
60
"export": {
61
// You can export multiple formats at once.
62
"format": ["png", "svg"],
63
// To make a visual effect, we set an obvious low resolution.
64
// For a nice result, you should set a higher resolution like 288.
65
"png.ppi": 24,
66
"merged": true,
67
// To make a visual effect, we set an obvious huge gap.
68
// For a nice result, you should set a smaller gap like 10pt.
69
"merged.gap": "100pt"
70
}
71
}
72
]
73
}
1
{
2
"version": "2.0.0",
3
"tasks": [
4
{
5
"label": "Export as Html",
6
"type": "typst",
7
"command": "export",
8
"export": {
9
"format": "html"
10
}
11
},
12
{
13
"label": "Export as Markdown",
14
"type": "typst",
15
"command": "export",
16
"export": {
17
"format": "markdown"
18
}
19
},
20
{
21
"label": "Export as Plain Text",
22
"type": "typst",
23
"command": "export",
24
"export": {
25
"format": "html"
26
}
27
},
28
{
29
"label": "Export as SVG",
30
"type": "typst",
31
"command": "export",
32
"export": {
33
"format": "svg",
34
"merged": true
35
}
36
},
37
{
38
"label": "Export as PNG",
39
"type": "typst",
40
"command": "export",
41
"export": {
42
"format": "png",
43
// Default fill is white, but you can set it to transparent.
44
"fill": "#00000000",
45
"merged": true
46
}
47
},
48
{
49
"label": "Query as Pdfpc",
50
"type": "typst",
51
"command": "export",
52
"export": {
53
"format": "pdfpc"
54
}
55
},
56
{
57
"label": "Export as PNG and SVG",
58
"type": "typst",
59
"command": "export",
60
"export": {
61
// You can export multiple formats at once.
62
"format": ["png", "svg"],
63
// To make a visual effect, we set an obvious low resolution.
64
// For a nice result, you should set a higher resolution like 288.
65
"png.ppi": 24,
66
"merged": true,
67
// To make a visual effect, we set an obvious huge gap.
68
// For a nice result, you should set a smaller gap like 10pt.
69
"merged.gap": "100pt"
70
}
71
}
72
]
73
}
todo: documenting export options.
1
[
2
{
3
"type": "typst",
4
"required": [
5
"command"
6
],
7
"properties": {
8
"command": {
9
"type": "string",
10
"default": "export",
11
"description": "The command to run.",
12
"enum": [
13
"export"
14
],
15
"enumDescriptions": [
16
"Export the document to specific format."
17
]
18
},
19
"export": {
20
"type": "object",
21
"description": "Arguments for `export` command.",
22
"properties": {
23
"format": {
24
"description": "The format(s) to export the document to. Defaults to `pdf`.",
25
"oneOf": [
26
{
27
"type": "string",
28
"description": "The format to export the document to.",
29
"enum": [
30
"pdf",
31
"png",
32
"svg",
33
"html",
34
"markdown",
35
"text",
36
"query",
37
"pdfpc"
38
],
39
"enumDescriptions": [
40
"PDF",
41
"PNG",
42
"SVG",
43
"HTML",
44
"Markdown",
45
"Plain Text",
46
"Query Result",
47
"Pdfpc (From Query)"
48
],
49
"default": "pdf"
50
},
51
{
52
"type": "array",
53
"description": "The formats to export the document to.",
54
"items": {
55
"type": "string",
56
"description": "The format to export the document to. Defaults to `pdf`.",
57
"enum": [
58
"pdf",
59
"png",
60
"svg",
61
"html",
62
"markdown",
63
"text",
64
"query",
65
"pdfpc"
66
],
67
"enumDescriptions": [
68
"PDF",
69
"PNG",
70
"SVG",
71
"HTML",
72
"Markdown",
73
"Plain Text",
74
"Query Result",
75
"Pdfpc (From Query)"
76
],
77
"default": "pdf"
78
}
79
}
80
]
81
},
82
"inputPath": {
83
"title": "Input path",
84
"description": "The path pattern to the entry file (main) for compilation, you can use `$focused`, `$root`, `$dir`, `$name` to do magic configuration, e.g. `$dir/$name` (default) and `$root/target/$dir/$name`. A special value `$focused` is used to point to the currently focused file in the editor.",
85
"type": "string",
86
"default": "$focused"
87
},
88
"metadata": {
89
"type": "boolean",
90
"description": "Whether to generate metadata containing export arguments."
91
},
92
"pdf.creationTimestamp": {
93
"type": [
94
"string"
95
],
96
"description": "The unix timestamp of the PDF creation. If not specified, the current time is used."
97
},
98
"png.ppi": {
99
"type": "number",
100
"description": "The PPI (pixels per inch) to use for PNG export",
101
"default": 144
102
},
103
"fill": {
104
"type": "string",
105
"description": "The fill color. Affected formats: `png`",
106
"examples": [
107
"white",
108
"#ffffff",
109
"#00000000"
110
]
111
},
112
"png.fill": {
113
"type": "string",
114
"description": "The fill color. Affected formats: `png`",
115
"examples": [
116
"white",
117
"#ffffff",
118
"#00000000"
119
],
120
"default": "white"
121
},
122
"merged": {
123
"type": "boolean",
124
"description": "Merge the pages into a single image. Affected formats: `png`, `svg`"
125
},
126
"svg.merged": {
127
"type": "boolean",
128
"description": "Merge the pages into a single SVG. Affected formats: `svg`"
129
},
130
"png.merged": {
131
"type": "boolean",
132
"description": "Merge the pages into a single PNG. Affected formats: `png`"
133
},
134
"merged.gap": {
135
"type": "string",
136
"description": "The gap between the pages when merging **with absolute typst unit**. Affected formats: `png`, `svg`",
137
"default": "0pt"
138
},
139
"svg.merged.gap": {
140
"type": "string",
141
"description": "The gap between the pages when merging **with absolute typst unit**. Affected formats: `svg`",
142
"default": "0pt"
143
},
144
"png.merged.gap": {
145
"type": "string",
146
"description": "The gap between the pages when merging **with absolute typst unit**. Affected formats: `png`",
147
"default": "0pt"
148
},
149
"query.format": {
150
"type": "string",
151
"description": "The format of the query output. Defaults to `json`.",
152
"default": "json",
153
"enum": [
154
"json",
155
"yaml",
156
"txt"
157
],
158
"enumDescriptions": [
159
"JSON",
160
"YAML",
161
"Plain Text if the result is a string, otherwise raises an error. You may specific the field to use for the query with `query.field` and assert that there is only one result with `query.one`."
162
]
163
},
164
"query.outputExtension": {
165
"type": "string",
166
"description": "The extension of the query output. Inferring from `query.format` if not specified."
167
},
168
"query.strict": {
169
"type": "boolean",
170
"description": "Whether to strictly check the query format. Defaults to `true`."
171
},
172
"query.pretty": {
173
"type": "boolean",
174
"description": "Whether to pretty print the query output. Defaults to `true`."
175
},
176
"query.selector": {
177
"type": "string",
178
"description": "The selector to use for the query. Must specified if `format`."
179
},
180
"query.field": {
181
"type": "string",
182
"description": "The field to use for the query."
183
},
184
"query.one": {
185
"type": "boolean",
186
"description": "Whether to only return one result. Defaults to `false`."
187
}
188
}
189
}
190
}
191
}
192
]
1
[
2
{
3
"type": "typst",
4
"required": [
5
"command"
6
],
7
"properties": {
8
"command": {
9
"type": "string",
10
"default": "export",
11
"description": "The command to run.",
12
"enum": [
13
"export"
14
],
15
"enumDescriptions": [
16
"Export the document to specific format."
17
]
18
},
19
"export": {
20
"type": "object",
21
"description": "Arguments for `export` command.",
22
"properties": {
23
"format": {
24
"description": "The format(s) to export the document to. Defaults to `pdf`.",
25
"oneOf": [
26
{
27
"type": "string",
28
"description": "The format to export the document to.",
29
"enum": [
30
"pdf",
31
"png",
32
"svg",
33
"html",
34
"markdown",
35
"text",
36
"query",
37
"pdfpc"
38
],
39
"enumDescriptions": [
40
"PDF",
41
"PNG",
42
"SVG",
43
"HTML",
44
"Markdown",
45
"Plain Text",
46
"Query Result",
47
"Pdfpc (From Query)"
48
],
49
"default": "pdf"
50
},
51
{
52
"type": "array",
53
"description": "The formats to export the document to.",
54
"items": {
55
"type": "string",
56
"description": "The format to export the document to. Defaults to `pdf`.",
57
"enum": [
58
"pdf",
59
"png",
60
"svg",
61
"html",
62
"markdown",
63
"text",
64
"query",
65
"pdfpc"
66
],
67
"enumDescriptions": [
68
"PDF",
69
"PNG",
70
"SVG",
71
"HTML",
72
"Markdown",
73
"Plain Text",
74
"Query Result",
75
"Pdfpc (From Query)"
76
],
77
"default": "pdf"
78
}
79
}
80
]
81
},
82
"inputPath": {
83
"title": "Input path",
84
"description": "The path pattern to the entry file (main) for compilation, you can use `$focused`, `$root`, `$dir`, `$name` to do magic configuration, e.g. `$dir/$name` (default) and `$root/target/$dir/$name`. A special value `$focused` is used to point to the currently focused file in the editor.",
85
"type": "string",
86
"default": "$focused"
87
},
88
"metadata": {
89
"type": "boolean",
90
"description": "Whether to generate metadata containing export arguments."
91
},
92
"pdf.creationTimestamp": {
93
"type": [
94
"string"
95
],
96
"description": "The unix timestamp of the PDF creation. If not specified, the current time is used."
97
},
98
"png.ppi": {
99
"type": "number",
100
"description": "The PPI (pixels per inch) to use for PNG export",
101
"default": 144
102
},
103
"fill": {
104
"type": "string",
105
"description": "The fill color. Affected formats: `png`",
106
"examples": [
107
"white",
108
"#ffffff",
109
"#00000000"
110
]
111
},
112
"png.fill": {
113
"type": "string",
114
"description": "The fill color. Affected formats: `png`",
115
"examples": [
116
"white",
117
"#ffffff",
118
"#00000000"
119
],
120
"default": "white"
121
},
122
"merged": {
123
"type": "boolean",
124
"description": "Merge the pages into a single image. Affected formats: `png`, `svg`"
125
},
126
"svg.merged": {
127
"type": "boolean",
128
"description": "Merge the pages into a single SVG. Affected formats: `svg`"
129
},
130
"png.merged": {
131
"type": "boolean",
132
"description": "Merge the pages into a single PNG. Affected formats: `png`"
133
},
134
"merged.gap": {
135
"type": "string",
136
"description": "The gap between the pages when merging **with absolute typst unit**. Affected formats: `png`, `svg`",
137
"default": "0pt"
138
},
139
"svg.merged.gap": {
140
"type": "string",
141
"description": "The gap between the pages when merging **with absolute typst unit**. Affected formats: `svg`",
142
"default": "0pt"
143
},
144
"png.merged.gap": {
145
"type": "string",
146
"description": "The gap between the pages when merging **with absolute typst unit**. Affected formats: `png`",
147
"default": "0pt"
148
},
149
"query.format": {
150
"type": "string",
151
"description": "The format of the query output. Defaults to `json`.",
152
"default": "json",
153
"enum": [
154
"json",
155
"yaml",
156
"txt"
157
],
158
"enumDescriptions": [
159
"JSON",
160
"YAML",
161
"Plain Text if the result is a string, otherwise raises an error. You may specific the field to use for the query with `query.field` and assert that there is only one result with `query.one`."
162
]
163
},
164
"query.outputExtension": {
165
"type": "string",
166
"description": "The extension of the query output. Inferring from `query.format` if not specified."
167
},
168
"query.strict": {
169
"type": "boolean",
170
"description": "Whether to strictly check the query format. Defaults to `true`."
171
},
172
"query.pretty": {
173
"type": "boolean",
174
"description": "Whether to pretty print the query output. Defaults to `true`."
175
},
176
"query.selector": {
177
"type": "string",
178
"description": "The selector to use for the query. Must specified if `format`."
179
},
180
"query.field": {
181
"type": "string",
182
"description": "The field to use for the query."
183
},
184
"query.one": {
185
"type": "boolean",
186
"description": "Whether to only return one result. Defaults to `false`."
187
}
188
}
189
}
190
}
191
}
192
]
After configuring the tasks, you can run them using the command palette.
- Press
Ctrl+Shift+P
to open the command palette. - Type
Run Task
and select the task you want to run. - Select the task you want to run.
Neovim: Export Commands
You can call the following export commands.
tinymist.exportSvg
tinymist.exportPng
tinymist.exportPdf
tinymist.exportHtml
tinymist.exportMarkdown
tinymist.exportText
tinymist.exportQuery
The first argument is the path to the file you want to export and the second argument is an object containing additional options.