Skip to content

Commit 585ce55

Browse files
Add Typst preview packages for offline builds
Bundle fontawesome, octique, showybox, and theorion packages from Typst preview repository. These are copied to .quarto cache at render time, enabling offline builds without network access to typst.app.
1 parent 367cbe2 commit 585ce55

33 files changed

Lines changed: 14052 additions & 0 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 duskmoon314 (Campbell He)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# typst-fontawesome
2+
3+
A Typst library for Font Awesome icons through the desktop fonts.
4+
5+
p.s. The library is based on the Font Awesome 6 desktop fonts (v6.6.0)
6+
7+
## Usage
8+
9+
### Install the fonts
10+
11+
You can download the fonts from the official website: https://fontawesome.com/download
12+
13+
After downloading the zip file, you can install the fonts depending on your OS.
14+
15+
#### Typst web app
16+
17+
You can simply upload the `otf` files to the web app and use them with this package.
18+
19+
#### Mac
20+
21+
You can double click the `otf` files to install them.
22+
23+
#### Windows
24+
25+
You can right-click the `otf` files and select `Install`.
26+
27+
#### Some notes
28+
29+
This library is tested with the otf files of the Font Awesome Free set. TrueType fonts may not work as expected. (Though I am not sure whether Font Awesome provides TrueType fonts, some issue is reported with TrueType fonts.)
30+
31+
### Import the library
32+
33+
#### Using the typst packages
34+
35+
You can install the library using the typst packages:
36+
37+
`#import "@preview/fontawesome:0.5.0": *`
38+
39+
#### Manually install
40+
41+
Copy all files start with `lib` to your project and import the library:
42+
43+
`#import "lib.typ": *`
44+
45+
There are three files:
46+
47+
- `lib.typ`: The main entrypoint of the library.
48+
- `lib-impl.typ`: The implementation of `fa-icon`.
49+
- `lib-gen.typ`: The generated icon map and functions.
50+
51+
I recommend renaming these files to avoid conflicts with other libraries.
52+
53+
### Use the icons
54+
55+
You can use the `fa-icon` function to create an icon with its name:
56+
57+
`#fa-icon("chess-queen")`
58+
59+
Or you can use the `fa-` prefix to create an icon with its name:
60+
61+
`#fa-chess-queen()` (This is equivalent to `#fa-icon().with("chess-queen")`)
62+
63+
You can also set `solid` to `true` to use the solid version of the icon:
64+
65+
`#fa-icon("chess-queen", solid: true)`
66+
67+
Some icons only have the solid version in the Free set, so you need to set `solid` to `true` to use them if you are using the Free set.
68+
Otherwise, you may not get the expected glyph.
69+
70+
#### Full list of icons
71+
72+
You can find all icons on the [official website](https://fontawesome.com/search)
73+
74+
#### Different sets
75+
76+
By default, the library supports `Free`, `Brands`, `Pro`, `Duotone` and `Sharp` sets.
77+
(See [Enable Pro sets](#enable-pro-sets) for enabling Pro sets.)
78+
79+
But only `Free` and `Brands` are tested by me.
80+
That is, three font files are used to test:
81+
82+
- Font Awesome 6 Free (Also named as _Font Awesome 6 Free Regular_)
83+
- Font Awesome 6 Free Solid
84+
- Font Awesome 6 Brands
85+
86+
Due to some limitations of typst 0.12.0, the regular and solid versions are treated as different fonts.
87+
In this library, `solid` is used to switch between the regular and solid versions.
88+
89+
To use other sets or specify one set, you can pass the `font` parameter to the inner `text` function: \
90+
`fa-icon("github", font: "Font Awesome 6 Pro Solid")`
91+
92+
If you have Font Awesome Pro, please help me test the library with the Pro set.
93+
Any feedback is appreciated.
94+
95+
##### Enable Pro sets
96+
97+
Typst 0.12.0 raise a warning when the font is not found.
98+
To use the Pro set, `#fa-use-pro()` should be called before any `fa-*` functions.
99+
100+
```typst
101+
#fa-use-pro() // Enable Pro sets
102+
103+
#fa-icon("chess-queen-piece") // Use icons from Pro sets
104+
```
105+
106+
#### Customization
107+
108+
The `fa-icon` function passes args to `text`, so you can customize the icon by passing parameters to it:
109+
110+
`#fa-icon("chess-queen", fill: blue)`
111+
112+
#### Stacking icons
113+
114+
The `fa-stack` function can be used to create stacked icons:
115+
116+
`#fa-stack(fa-icon-args: (solid: true), "square", ("chess-queen", (fill: white, size: 5.5pt)))`
117+
118+
Declaration is `fa-stack(box-args: (:), grid-args: (:), fa-icon-args: (:), ..icons)`
119+
120+
- The order of the icons is from the bottom to the top.
121+
- `fa-icon-args` is used to set the default args for all icons.
122+
- You can also control the internal `box` and `grid` by passing the `box-args` and `grid-args` to the `fa-stack` function.
123+
- Currently, four types of icons are supported. The first three types leverage the `fa-icon` function, and the last type is just a content you want to put in the stack.
124+
- `str`, e.g., `"square"`
125+
- `array`, e.g., `("chess-queen", (fill: white, size: 5.5pt))`
126+
- `arguments`, e.g. `arguments("chess-queen", solid: true, fill: white)`
127+
- `content`, e.g. `fa-chess-queen(solid: true, fill: white)`
128+
129+
#### Known Issues
130+
131+
- [typst#2578](https://github.com/typst/typst/issues/2578) [typst-fontawesome#2](https://github.com/duskmoon314/typst-fontawesome/issues/2)
132+
133+
This is a known issue that the ligatures may not work in headings, list items, grid items, and other elements. You can use the Unicode from the [official website](https://fontawesome.com) to avoid this issue when using Pro sets.
134+
135+
For most icons, Unicode is used implicitly. So I assume we usually don't need to worry about this.
136+
137+
Any help on this issue is appreciated.
138+
139+
## Example
140+
141+
See the [`example.typ`](https://typst.app/project/rQwGUWt5p33vrsb_uNPR9F) file for a complete example.
142+
143+
## Contribution
144+
145+
Feel free to open an issue or a pull request if you find any problems or have any suggestions.
146+
147+
### Python helper
148+
149+
The `helper.py` script is used to get metadata via the GraphQL API and generate typst code. I aim only to use standard python libraries, so running it on any platform with python installed should be easy.
150+
151+
### Repo structure
152+
153+
- `helper.py`: The helper script to get metadata and generate typst code.
154+
- `lib.typ`: The main entrypoint of the library.
155+
- `lib-impl.typ`: The implementation of `fa-icon`.
156+
- `lib-gen.typ`: The generated functions of icons.
157+
- `example.typ`: An example file to show how to use the library.
158+
- `gallery.typ`: The generated gallery of icons. It is used in the example file.
159+
160+
## License
161+
162+
This library is licensed under the MIT license. Feel free to use it in your project.

0 commit comments

Comments
 (0)