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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e902865d606a53619b4af115102284997f623a128bc06405f5300c4c2b4c687
4
- data.tar.gz: a33d506d802a470779eb60c2d075a0c6cf9babf50756b8633d87e297d05cc1fd
3
+ metadata.gz: bdc56381647f2be411648ebbf5525576c5c6a259257cafd29de225dbd50da25c
4
+ data.tar.gz: 414023a808e3081a46e5e3ca64aa44920aedc41bbeca7c7004557e2a76b682f9
5
5
  SHA512:
6
- metadata.gz: baa7a4a6b87a9ba92b821f061e53dd4a45f014a45d672c68dd9cc6c08c4b1fd90a60c548c5d87a4fa41f1d5c024c5f916691fb122aafa5705259dbdfcc8ee7c2
7
- data.tar.gz: c208d4cf87db4672ba0e9bfc40f63b1b8152dadb5e42c42f270d57172318a7194189c5c208f2a91b44c3933ec6f15bc84ebf465edcedb7cf8b35f4e33158bec4
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
- # Use a typst file `readme.typ`
21
+ ### Use a typst file `readme.typ`
22
+ ```ruby
21
23
  t = Typst("readme.typ")
24
+ ```
22
25
 
23
- # Use a typst string
26
+ ### Use a typst string
27
+ ```ruby
24
28
  t = Typst(body: %{hello world})
29
+ ```
25
30
 
26
- # Use a typst file in a zip file
31
+ ### Use a typst file in a zip file
32
+ ```ruby
27
33
  t = Typst(zip: "test/main.typ.zip")
34
+ ```
28
35
 
29
- # Compile to PDF
36
+ ### Compile to PDF
37
+ ```ruby
30
38
  doc = t.compile(:pdf)
39
+ ```
31
40
 
32
- # Compile to PDF selecting the typst supported PdfStandard
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
- # Compile to SVG
46
+ ### Compile to SVG
47
+ ```ruby
36
48
  doc = t.compile(:svg)
49
+ ```
37
50
 
38
- # Compile to PNG
51
+ ### Compile to PNG
52
+ ```ruby
39
53
  doc = t.compile(:png)
54
+ ```
40
55
 
41
- # Compile to PNG and set PPI
56
+ ### Compile to PNG and set PPI
57
+ ```ruby
42
58
  doc = t.compile(:png, ppi: 72)
59
+ ```
43
60
 
44
- # Compile to HTML (using Typst expirmental HTML)
61
+ ### Compile to HTML (using Typst expirmental HTML)
62
+ ```ruby
45
63
  doc = t.compile(:html_experimental)
64
+ ```
46
65
 
47
- # Or return content as an array of bytes
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
- # Write the output to a file
52
- # 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`
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
- # Return PDF, SVG, PNG or HTML content as an array of pages
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
- # Pass values into typst using sys_inputs
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
- # Apply inputs to typst to product multiple PDFs
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
- # A more complex example of compiling from string
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
- # From a zip with a named main typst file
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
- # clear the compilation cache
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
- # Use a typst file `readme.typ`
29
+ === Use a typst file `readme.typ`
30
+ ```ruby
24
31
  t = Typst("readme.typ")
32
+ ```
25
33
 
26
- # Use a typst string
34
+ === Use a typst string
35
+ ```ruby
27
36
  t = Typst(body: %{hello world})
37
+ ```
28
38
 
29
- # Use a typst file in a zip file
39
+ === Use a typst file in a zip file
40
+ ```ruby
30
41
  t = Typst(zip: "test/main.typ.zip")
42
+ ```
31
43
 
32
- # Compile to PDF
44
+ === Compile to PDF
45
+ ```ruby
33
46
  doc = t.compile(:pdf)
47
+ ```
34
48
 
35
- # Compile to PDF selecting the typst supported PdfStandard
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
- # Compile to SVG
54
+ === Compile to SVG
55
+ ```ruby
39
56
  doc = t.compile(:svg)
57
+ ```
40
58
 
41
- # Compile to PNG
59
+ === Compile to PNG
60
+ ```ruby
42
61
  doc = t.compile(:png)
62
+ ```
43
63
 
44
- # Compile to PNG and set PPI
64
+ === Compile to PNG and set PPI
65
+ ```ruby
45
66
  doc = t.compile(:png, ppi: 72)
67
+ ```
46
68
 
47
- # Compile to HTML (using Typst expirmental HTML)
69
+ === Compile to HTML (using Typst expirmental HTML)
70
+ ```ruby
48
71
  doc = t.compile(:html_experimental)
72
+ ```
49
73
 
50
- # Or return content as an array of bytes
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
- # Write the output to a file
55
- # 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`
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
- # Return PDF, SVG, PNG or HTML content as an array of pages
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
- # Pass values into typst using sys_inputs
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
- # Apply inputs to typst to product multiple PDFs
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
- # A more complex example of compiling from string
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
- # From a zip with a named main typst file
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
- # clear the compilation cache
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.123", default-features = false, features = ["stable-api-compiled-fallback"] }
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.write(tmp_dep_file, dep_source)
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.write(tmp_font_file, font_bytes)
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.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.3
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.