-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,19 @@ Currently powered by https://github.com/sitandr/mdbook-typst-highlight. | |
If you have a snippet you want to have in a book, feel free to create an issue. | ||
|
||
Any PR-s are very welcome! | ||
|
||
Currently needed (any work encouraged): | ||
|
||
- Editing (expanding examples, fixing bad language issues) | ||
- Package overviews (see current empty themes) | ||
- Selecting any really useful code examples from Discord and Github | ||
|
||
If you think you can do some large work, please DM me in Discord (@sitandr) or mail ([email protected]) to avoid duplication. | ||
|
||
## Cleaning cached Typst files | ||
|
||
```bash | ||
git clean -d -X -i | ||
``` | ||
|
||
Make sure to avoid deleting something useful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,116 @@ | ||
# Types | ||
# Types, part I | ||
|
||
Each value in Typst has a type. You don't have to specify it, but it is important | ||
Each value in Typst has a type. You don't have to specify it, but it is important. | ||
|
||
## Content (`content`) | ||
|
||
> [Link to Reference](https://typst.app/docs/reference/foundations/content/). | ||
We have already seen it. A type that represents what is displayed in document. | ||
|
||
``` | ||
#let c = [It is _content_!] | ||
// Check type of c | ||
#(type(c) == content) | ||
#c | ||
// repr gives an "inner representation" of value | ||
#repr(c) | ||
``` | ||
|
||
**Important:** It is very hard to convert _content_ to _plain text_, as _content_ may contain *anything*! Sp be careful when passing and storing content in variables. | ||
|
||
## String (`str`) | ||
|
||
> [Link to Reference](https://typst.app/docs/reference/foundations/str/). | ||
String contains only plain text and no formatting. Just some chars. That allows us to work with chars: | ||
|
||
``` | ||
#let s = "Some large string. There could be escape sentences: \n, | ||
line breaks, and even unicode codes: \u{1251}" | ||
#s \ | ||
#type(s) \ | ||
`repr`: #repr(s) | ||
#let s = "another small string" | ||
#s.replace("a", sym.alpha) \ | ||
#s.split(" ") // split by space | ||
``` | ||
|
||
## Boolean (`bool`) | ||
|
||
> [Link to Reference](https://typst.app/docs/reference/foundations/bool/). | ||
true/false. Used in `if` and many others | ||
|
||
``` | ||
#let b = false | ||
#b \ | ||
#repr(b) \ | ||
#(true and not true or true) = #((true and (not true)) or true) \ | ||
#if (4 > 3) { | ||
"4 is more than 3" | ||
} | ||
``` | ||
|
||
## Integer (`int`) | ||
|
||
> [Link to Reference](https://typst.app/docs/reference/foundations/int/). | ||
A whole number. | ||
|
||
The number can also be specified as hexadecimal, octal, or binary by starting it with a zero followed by either x, o, or b. | ||
|
||
You can convert a value to an integer with this type's constructor. | ||
|
||
``` | ||
#let n = 5 | ||
#n \ | ||
#(n += 1) \ | ||
#n \ | ||
#calc.pow(2, n) | ||
#(1 + 2) \ | ||
#(2 - 5) \ | ||
#(3 + 4 < 8) | ||
#0xff \ | ||
#0o10 \ | ||
#0b1001 | ||
#int(false) \ | ||
#int(true) \ | ||
#int(2.7) \ | ||
#(int("27") + int("4")) | ||
#type(n)\ | ||
#repr(n) | ||
``` | ||
|
||
## Float (`float`) | ||
> [Link to Reference](https://typst.app/docs/reference/foundations/float/). | ||
Works the same way as integer, but can store floating point numbers. | ||
However, precision may be lost. | ||
|
||
``` | ||
#let n = 5.0 | ||
// You can mix floats and integers, | ||
// they will be implicitly converted | ||
#(n += 1) \ | ||
#calc.pow(2, n) \ | ||
#(0.2 + 0.1) \ | ||
#type(n) | ||
#3.14 \ | ||
#1e4 \ | ||
#(10 / 4) | ||
#float(40%) \ | ||
#float("2.7") \ | ||
#float("1e5") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Types, part II | ||
|
||
## Arrays (`array`) | ||
|
||
## Dictionaries (`dict`) |