Skip to content

Commit

Permalink
Expand summary and types
Browse files Browse the repository at this point in the history
  • Loading branch information
sitandr committed Nov 6, 2023
1 parent c2d5e1f commit 374d888
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 9 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 10 additions & 5 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
- [Scripting](./basics/scripting/README.md)
- [Basics](./basics/scripting/basics.md)
- [Braces, brackets and default](./basics/scripting/braces.md)
- [Types](./basics/scripting/types.md)
- [Types, part I](./basics/scripting/types.md)
- [Types, part II](./basics/scripting/types_2.md)
- [States, Query, Locate](./basics/states/README.md)
- [Counters](./basics/states/counters.md)
- [States]()
- [Locate]()
- [Measure]()
- [Metada]()
- [Math]()
- [General]()
- [Location and sizes]()
Expand All @@ -30,23 +32,26 @@
- [Bibliography setup]()
- [Setting chapter headers]()
- [Page setup]()
- [Code formatting]()
- [Hyphenation]()
- [Math]()
- [Numbering]()
- [Setting limits]()
- [Operators]()
- [Symbols]() <!--TODO: emptyset-->
- [Text&Content]()
- [Use with external tools]()
- [Typst Packages](./packages/README.md)
- [Overview]()
- [Drawing]()
- [Graphs]()
- [Custom boxes]() <!--TODO: for theorems look into math-->
- [Math]()
- [Presentations]()
- [Graphing]()
- [Tables]()
- [Math]()
- [Themes]()
- [Algorithms]()
- [Themes]()
- [Misc]()
- [Typstonomicon, or The Code You Should Not Write]()
- [Try&Catch](./typstonomicon/try_catch.md)
- [Extracting plain text](./typstonomicon/extract_plain_text.md)
- [Extracting plain text](./typstonomicon/extract_plain_text.md)
4 changes: 2 additions & 2 deletions src/basics/scripting/braces.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We may use same for functions bodies:
#f[World] // also don't forget we can use it to pass content!
```

**Important:** It is very hard to convert _content_ to _plain text_, as _content_ may contain *anything*!
**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.

## Braces
However, we often want to use code inside functions.
Expand All @@ -34,7 +34,7 @@ That's when we use `{}`:
} else {
name
}
// finish sentence
"!"
}
Expand Down
117 changes: 115 additions & 2 deletions src/basics/scripting/types.md
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")
```
5 changes: 5 additions & 0 deletions src/basics/scripting/types_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Types, part II

## Arrays (`array`)

## Dictionaries (`dict`)

0 comments on commit 374d888

Please sign in to comment.