typst 0.14.2.2 → 0.14.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +78 -21
- data/README.typ +83 -21
- data/ext/typst/Cargo.toml +1 -1
- data/lib/typst.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bdc56381647f2be411648ebbf5525576c5c6a259257cafd29de225dbd50da25c
|
|
4
|
+
data.tar.gz: 414023a808e3081a46e5e3ca64aa44920aedc41bbeca7c7004557e2a76b682f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf751aa8cfe5c0cb9f7433728f61ef1882af9fdea3b0aa031fa87e906a6be1880b1832a74597871911751fc912fb93f2f8946d4b8fd022c175828865d428938c
|
|
7
|
+
data.tar.gz: 62d507c32cdd32be9cf125350953a57971968e5aff1b43604d506e640901a327b940ab51c5becb6e4890ce1c8f656c4adb0a8bae19e1b3b217a6d82c8cddfb80
|
data/README.md
CHANGED
|
@@ -16,53 +16,82 @@ require "typst"
|
|
|
16
16
|
|
|
17
17
|
# Compile a typst file and write the output to a PDF file
|
|
18
18
|
Typst("readme.typ").compile(:pdf).write("readme.pdf")
|
|
19
|
+
```
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
### Use a typst file `readme.typ`
|
|
22
|
+
```ruby
|
|
21
23
|
t = Typst("readme.typ")
|
|
24
|
+
```
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
### Use a typst string
|
|
27
|
+
```ruby
|
|
24
28
|
t = Typst(body: %{hello world})
|
|
29
|
+
```
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
### Use a typst file in a zip file
|
|
32
|
+
```ruby
|
|
27
33
|
t = Typst(zip: "test/main.typ.zip")
|
|
34
|
+
```
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
### Compile to PDF
|
|
37
|
+
```ruby
|
|
30
38
|
doc = t.compile(:pdf)
|
|
39
|
+
```
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
### Compile to PDF selecting the typst supported PdfStandard
|
|
42
|
+
```ruby
|
|
33
43
|
doc = t.compile(:pdf, pdf_standards: ["2.0"])
|
|
44
|
+
```
|
|
34
45
|
|
|
35
|
-
|
|
46
|
+
### Compile to SVG
|
|
47
|
+
```ruby
|
|
36
48
|
doc = t.compile(:svg)
|
|
49
|
+
```
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
### Compile to PNG
|
|
52
|
+
```ruby
|
|
39
53
|
doc = t.compile(:png)
|
|
54
|
+
```
|
|
40
55
|
|
|
41
|
-
|
|
56
|
+
### Compile to PNG and set PPI
|
|
57
|
+
```ruby
|
|
42
58
|
doc = t.compile(:png, ppi: 72)
|
|
59
|
+
```
|
|
43
60
|
|
|
44
|
-
|
|
61
|
+
### Compile to HTML (using Typst expirmental HTML)
|
|
62
|
+
```ruby
|
|
45
63
|
doc = t.compile(:html_experimental)
|
|
64
|
+
```
|
|
46
65
|
|
|
47
|
-
|
|
66
|
+
### Or return content as an array of bytes
|
|
67
|
+
```ruby
|
|
48
68
|
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
|
49
69
|
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
|
70
|
+
```
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
### Write the output to a file
|
|
73
|
+
Note: for multi-page documents using formats other than PDF and HTML, pages write to multiple files, e.g. `readme_0.png`, `readme_1.png`
|
|
74
|
+
```ruby
|
|
53
75
|
doc.write("filename.pdf")
|
|
76
|
+
```
|
|
54
77
|
|
|
55
|
-
|
|
78
|
+
### Return PDF, SVG, PNG or HTML content as an array of pages
|
|
79
|
+
```ruby
|
|
56
80
|
Typst("readme.typ").compile(:pdf).pages
|
|
57
81
|
# => ["%PDF-1.7\n%\x80\x80\x80\x80\n\n1 0 obj\n<<\n /Type /Pages\n /Count 3\n /Kids [160 0 R 162 ...
|
|
82
|
+
|
|
58
83
|
Typst("readme.typ").compile(:svg).pages
|
|
59
84
|
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ...
|
|
85
|
+
|
|
60
86
|
Typst("readme.typ").compile(:png).pages
|
|
61
87
|
# => ["\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x04\xA7\x00\x00\x06\x94\b\ ...
|
|
88
|
+
|
|
62
89
|
Typst("readme.typ").compile(:html_experimental).pages
|
|
63
90
|
# => ["<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" ...
|
|
91
|
+
```
|
|
64
92
|
|
|
65
|
-
|
|
93
|
+
### Pass values into typst using sys_inputs
|
|
94
|
+
```ruby
|
|
66
95
|
sys_inputs_example = %{
|
|
67
96
|
#let persons = json(bytes(sys.inputs.persons))
|
|
68
97
|
|
|
@@ -73,15 +102,18 @@ sys_inputs_example = %{
|
|
|
73
102
|
people = [{"name" => "John", "age" => 35}, {"name" => "Xoliswa", "age" => 45}]
|
|
74
103
|
data = { "persons" => people.to_json }
|
|
75
104
|
Typst(body: sys_inputs_example, sys_inputs: data).compile(:pdf).write("sys_inputs_example.pdf")
|
|
105
|
+
```
|
|
76
106
|
|
|
77
|
-
|
|
78
|
-
|
|
107
|
+
### Apply inputs to typst to product multiple PDFs
|
|
108
|
+
```ruby
|
|
79
109
|
t = Typst(body: sys_inputs_example)
|
|
80
110
|
people.each do |person|
|
|
81
111
|
t.with_inputs({ "persons" => [person].to_json }).compile(:pdf).write("#{person['name']}.pdf")
|
|
82
112
|
end
|
|
113
|
+
```
|
|
83
114
|
|
|
84
|
-
|
|
115
|
+
### A more complex example of compiling from string using other dependency typst template, svg and font resources all in memory
|
|
116
|
+
```ruby
|
|
85
117
|
main = %{
|
|
86
118
|
#import "template.typ": *
|
|
87
119
|
|
|
@@ -103,10 +135,33 @@ icon = File.read("icon.svg")
|
|
|
103
135
|
font_bytes = File.read("Example.ttf")
|
|
104
136
|
|
|
105
137
|
Typst(body: main, dependencies: { "template.typ" => template, "icon.svg" => icon }, fonts: { "Example.ttf" => font_bytes }).compile(:pdf)
|
|
138
|
+
```
|
|
106
139
|
|
|
107
|
-
|
|
140
|
+
### From a zip with a named main typst file
|
|
141
|
+
```ruby
|
|
108
142
|
Typst(zip: "test/main.typ.zip", main_file: "hello.typ").compile(:pdf)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Use a package from the [Typst Universe](https://typst.app/universe)
|
|
146
|
+
Your package_example.typ file...
|
|
147
|
+
```typst
|
|
148
|
+
#import "@preview/wordometer:0.1.5": word-count, total-words
|
|
149
|
+
#show: word-count
|
|
109
150
|
|
|
151
|
+
In this document, there are #total-words words all up.
|
|
152
|
+
|
|
153
|
+
#word-count(total => [
|
|
154
|
+
The number of words in this block is #total.words
|
|
155
|
+
and there are #total.characters letters.
|
|
156
|
+
])
|
|
157
|
+
```
|
|
158
|
+
...compiles just like anything else
|
|
159
|
+
```ruby
|
|
160
|
+
Typst("package_example.typ").compile(:pdf).write("package_example.pdf")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Query a typst document
|
|
164
|
+
```ruby
|
|
110
165
|
Typst("readme.typ").query("heading").result
|
|
111
166
|
# =>
|
|
112
167
|
# [{"func" => "heading",
|
|
@@ -122,13 +177,15 @@ Typst("readme.typ").query("heading", format: "yaml").result(raw: true)
|
|
|
122
177
|
|
|
123
178
|
# Query results as JSON string
|
|
124
179
|
Typst("test/test.typ").query("heading").to_s
|
|
125
|
-
=> "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
180
|
+
# => "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
126
181
|
|
|
127
182
|
# Query results as YAML string
|
|
128
183
|
Typst("test/test.typ").query("heading", format: "yaml").to_s
|
|
129
|
-
=> "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
184
|
+
# => "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
185
|
+
```
|
|
130
186
|
|
|
131
|
-
|
|
187
|
+
### clear the compilation cache
|
|
188
|
+
```ruby
|
|
132
189
|
# Evict all entries whose age is larger than or equal to `max_age`
|
|
133
190
|
max_age = 10
|
|
134
191
|
Typst::clear_cache(max_age)
|
data/README.typ
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#set document(title: [typst.rb README])
|
|
2
2
|
#show link: underline
|
|
3
3
|
#show link: set text(blue)
|
|
4
|
+
#show raw.where(block: true): block.with(
|
|
5
|
+
fill: luma(240),
|
|
6
|
+
inset: 10pt,
|
|
7
|
+
radius: 4pt,
|
|
8
|
+
)
|
|
4
9
|
|
|
5
10
|
= typst-rb
|
|
6
11
|
|
|
@@ -19,53 +24,82 @@ require "typst"
|
|
|
19
24
|
|
|
20
25
|
# Compile a typst file and write the output to a PDF file
|
|
21
26
|
Typst("readme.typ").compile(:pdf).write("readme.pdf")
|
|
27
|
+
```
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
=== Use a typst file `readme.typ`
|
|
30
|
+
```ruby
|
|
24
31
|
t = Typst("readme.typ")
|
|
32
|
+
```
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
=== Use a typst string
|
|
35
|
+
```ruby
|
|
27
36
|
t = Typst(body: %{hello world})
|
|
37
|
+
```
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
=== Use a typst file in a zip file
|
|
40
|
+
```ruby
|
|
30
41
|
t = Typst(zip: "test/main.typ.zip")
|
|
42
|
+
```
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
=== Compile to PDF
|
|
45
|
+
```ruby
|
|
33
46
|
doc = t.compile(:pdf)
|
|
47
|
+
```
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
=== Compile to PDF selecting the typst supported PdfStandard
|
|
50
|
+
```ruby
|
|
36
51
|
doc = t.compile(:pdf, pdf_standards: ["2.0"])
|
|
52
|
+
```
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
=== Compile to SVG
|
|
55
|
+
```ruby
|
|
39
56
|
doc = t.compile(:svg)
|
|
57
|
+
```
|
|
40
58
|
|
|
41
|
-
|
|
59
|
+
=== Compile to PNG
|
|
60
|
+
```ruby
|
|
42
61
|
doc = t.compile(:png)
|
|
62
|
+
```
|
|
43
63
|
|
|
44
|
-
|
|
64
|
+
=== Compile to PNG and set PPI
|
|
65
|
+
```ruby
|
|
45
66
|
doc = t.compile(:png, ppi: 72)
|
|
67
|
+
```
|
|
46
68
|
|
|
47
|
-
|
|
69
|
+
=== Compile to HTML (using Typst expirmental HTML)
|
|
70
|
+
```ruby
|
|
48
71
|
doc = t.compile(:html_experimental)
|
|
72
|
+
```
|
|
49
73
|
|
|
50
|
-
|
|
74
|
+
=== Or return content as an array of bytes
|
|
75
|
+
```ruby
|
|
51
76
|
pdf_bytes = Typst("readme.typ").compile(:pdf).bytes
|
|
52
77
|
# => [37, 80, 68, 70, 45, 49, 46, 55, 10, 37, 128 ...]
|
|
78
|
+
```
|
|
53
79
|
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
=== Write the output to a file
|
|
81
|
+
Note: for multi-page documents using formats other than PDF and HTML, pages write to multiple files, e.g. `readme_0.png`, `readme_1.png`
|
|
82
|
+
```ruby
|
|
56
83
|
doc.write("filename.pdf")
|
|
84
|
+
```
|
|
57
85
|
|
|
58
|
-
|
|
86
|
+
=== Return PDF, SVG, PNG or HTML content as an array of pages
|
|
87
|
+
```ruby
|
|
59
88
|
Typst("readme.typ").compile(:pdf).pages
|
|
60
89
|
# => ["%PDF-1.7\n%\x80\x80\x80\x80\n\n1 0 obj\n<<\n /Type /Pages\n /Count 3\n /Kids [160 0 R 162 ...
|
|
90
|
+
|
|
61
91
|
Typst("readme.typ").compile(:svg).pages
|
|
62
92
|
# => ["<svg class=\"typst-doc\" viewBox=\"0 0 595.2764999999999 841.89105\" ...
|
|
93
|
+
|
|
63
94
|
Typst("readme.typ").compile(:png).pages
|
|
64
95
|
# => ["\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x04\xA7\x00\x00\x06\x94\b\ ...
|
|
96
|
+
|
|
65
97
|
Typst("readme.typ").compile(:html_experimental).pages
|
|
66
98
|
# => ["<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" ...
|
|
99
|
+
```
|
|
67
100
|
|
|
68
|
-
|
|
101
|
+
=== Pass values into typst using sys_inputs
|
|
102
|
+
```ruby
|
|
69
103
|
sys_inputs_example = %{
|
|
70
104
|
#let persons = json(bytes(sys.inputs.persons))
|
|
71
105
|
|
|
@@ -76,15 +110,18 @@ sys_inputs_example = %{
|
|
|
76
110
|
people = [{"name" => "John", "age" => 35}, {"name" => "Xoliswa", "age" => 45}]
|
|
77
111
|
data = { "persons" => people.to_json }
|
|
78
112
|
Typst(body: sys_inputs_example, sys_inputs: data).compile(:pdf).write("sys_inputs_example.pdf")
|
|
113
|
+
```
|
|
79
114
|
|
|
80
|
-
|
|
81
|
-
|
|
115
|
+
=== Apply inputs to typst to product multiple PDFs
|
|
116
|
+
```ruby
|
|
82
117
|
t = Typst(body: sys_inputs_example)
|
|
83
118
|
people.each do |person|
|
|
84
119
|
t.with_inputs({ "persons" => [person].to_json }).compile(:pdf).write("#{person['name']}.pdf")
|
|
85
120
|
end
|
|
121
|
+
```
|
|
86
122
|
|
|
87
|
-
|
|
123
|
+
=== A more complex example of compiling from string using other dependency typst template, svg and font resources all in memory
|
|
124
|
+
```ruby
|
|
88
125
|
main = %{
|
|
89
126
|
#import "template.typ": *
|
|
90
127
|
|
|
@@ -106,10 +143,33 @@ icon = File.read("icon.svg")
|
|
|
106
143
|
font_bytes = File.read("Example.ttf")
|
|
107
144
|
|
|
108
145
|
Typst(body: main, dependencies: { "template.typ" => template, "icon.svg" => icon }, fonts: { "Example.ttf" => font_bytes }).compile(:pdf)
|
|
146
|
+
```
|
|
109
147
|
|
|
110
|
-
|
|
148
|
+
=== From a zip with a named main typst file
|
|
149
|
+
```ruby
|
|
111
150
|
Typst(zip: "test/main.typ.zip", main_file: "hello.typ").compile(:pdf)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
=== Use a package from the #link("https://typst.app/universe")[Typst Universe]
|
|
154
|
+
Your package_example.typ file...
|
|
155
|
+
```typst
|
|
156
|
+
#import "@preview/wordometer:0.1.5": word-count, total-words
|
|
157
|
+
#show: word-count
|
|
112
158
|
|
|
159
|
+
In this document, there are #total-words words all up.
|
|
160
|
+
|
|
161
|
+
#word-count(total => [
|
|
162
|
+
The number of words in this block is #total.words
|
|
163
|
+
and there are #total.characters letters.
|
|
164
|
+
])
|
|
165
|
+
```
|
|
166
|
+
...compiles just like anything else
|
|
167
|
+
```ruby
|
|
168
|
+
Typst("package_example.typ").compile(:pdf).write("package_example.pdf")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
=== Query a typst document
|
|
172
|
+
```ruby
|
|
113
173
|
Typst("readme.typ").query("heading").result
|
|
114
174
|
# =>
|
|
115
175
|
# [{"func" => "heading",
|
|
@@ -125,13 +185,15 @@ Typst("readme.typ").query("heading", format: "yaml").result(raw: true)
|
|
|
125
185
|
|
|
126
186
|
# Query results as JSON string
|
|
127
187
|
Typst("test/test.typ").query("heading").to_s
|
|
128
|
-
=> "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
188
|
+
# => "[\n {\n \"func\": \"heading\",\n \"level\": 1,\n \"depth\": 1,\n \"offset\": 0,\n ...
|
|
129
189
|
|
|
130
190
|
# Query results as YAML string
|
|
131
191
|
Typst("test/test.typ").query("heading", format: "yaml").to_s
|
|
132
|
-
=> "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
192
|
+
# => "- func: heading\n level: 1\n depth: 1\n offset: 0\n numbering: null\n supplement:\n ...
|
|
193
|
+
```
|
|
133
194
|
|
|
134
|
-
|
|
195
|
+
=== clear the compilation cache
|
|
196
|
+
```ruby
|
|
135
197
|
# Evict all entries whose age is larger than or equal to `max_age`
|
|
136
198
|
max_age = 10
|
|
137
199
|
Typst::clear_cache(max_age)
|
data/ext/typst/Cargo.toml
CHANGED
|
@@ -49,4 +49,4 @@ walkdir = "2.4.0"
|
|
|
49
49
|
|
|
50
50
|
# enable rb-sys feature to test against Ruby head. This is only needed if you
|
|
51
51
|
# want to work with the unreleased, in-development, next version of Ruby
|
|
52
|
-
rb-sys = { version = "0.9.
|
|
52
|
+
rb-sys = { version = "0.9.124", default-features = false, features = ["stable-api-compiled-fallback"] }
|
data/lib/typst.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Typst
|
|
|
8
8
|
def self.register_format(**format)
|
|
9
9
|
@@formats.merge!(format)
|
|
10
10
|
end
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
def self.formats
|
|
13
13
|
@@formats
|
|
14
14
|
end
|
|
@@ -27,14 +27,14 @@ module Typst
|
|
|
27
27
|
|
|
28
28
|
dependencies.each do |dep_name, dep_source|
|
|
29
29
|
tmp_dep_file = Pathname.new(tmp_dir).join(dep_name)
|
|
30
|
-
File.
|
|
30
|
+
File.binwrite(tmp_dep_file, dep_source)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
relative_font_path = Pathname.new(tmp_dir).join("fonts")
|
|
34
34
|
relative_font_path.mkpath
|
|
35
35
|
fonts.each do |font_name, font_bytes|
|
|
36
36
|
tmp_font_file = relative_font_path.join(font_name)
|
|
37
|
-
File.
|
|
37
|
+
File.binwrite(tmp_font_file, font_bytes)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
options[:file] = tmp_main_file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typst
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.14.2.
|
|
4
|
+
version: 0.14.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Flinn
|
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
158
158
|
- !ruby/object:Gem::Version
|
|
159
159
|
version: '0'
|
|
160
160
|
requirements: []
|
|
161
|
-
rubygems_version: 4.0.
|
|
161
|
+
rubygems_version: 4.0.4
|
|
162
162
|
specification_version: 4
|
|
163
163
|
summary: Ruby binding to typst, a new markup-based typesetting system that is powerful
|
|
164
164
|
and easy to learn.
|