The init command
The init
command will try to initialize your book to build your book successfully by default. It is hence including all of the options from build
command.
For instance, Initialize a book to the directory my-book
:
1
shiroa init my-book/
2
shiroa build my-book/
1
shiroa init my-book/
2
shiroa build my-book/
Initialize a book with specific typst workspace directory:
1
shiroa init -w . my-book/
2
shiroa build -w . my-book/
1
shiroa init -w . my-book/
2
shiroa build -w . my-book/
Initialize a book with specific dest-dir
:
1
shiroa init --dest-dir ../dist my-book/
2
shiroa build my-book/ # memoryized dest-dir
1
shiroa init --dest-dir ../dist my-book/
2
shiroa build my-book/ # memoryized dest-dir
Things to note
The harder way, by creating the book without init
command, your book.typ
should at least provides a book-meta
, as Get Started shown.
1
#import "@preview/shiroa:0.2.2": *
2
#show: book
3
4
#book-meta(
5
title: "My Book"
6
summary: [
7
= My Book
8
]
9
)
1
#import "@preview/shiroa:0.2.2": *
2
#show: book
3
4
#book-meta(
5
title: "My Book"
6
summary: [
7
= My Book
8
]
9
)
Your template.typ
must import and respect the get-page-width
and target
variable from @preview/shiroa:0.2.2
to this time. The two variables will be used by the tool for rendering responsive layout and multiple targets.
1
#import "@preview/shiroa:0.2.2": get-page-width, target, is-web-target, is-pdf-target
2
3
// Metadata
4
#let page-width = get-page-width()
5
#let is-html-target = is-html-target() // target.starts-with("html")
6
#let is-pdf-target = is-pdf-target() // target.starts-with("pdf")
7
#let is-web-target = is-web-target() // target.starts-with("web") or target.starts-with("html")
8
9
#let project(body) = {
10
// set web/pdf page properties
11
set page(
12
width: page-width,
13
// for a website, we don't need pagination.
14
height: auto,
15
)
16
17
// remove margins for web target
18
set page(margin: (
19
// reserved beautiful top margin
20
top: 20pt,
21
// Typst is setting the page's bottom to the baseline of the last line of text. So bad :(.
22
bottom: 0.5em,
23
// remove rest margins.
24
rest: 0pt,
25
)) if is-web-target;
26
27
body
28
}
1
#import "@preview/shiroa:0.2.2": get-page-width, target, is-web-target, is-pdf-target
2
3
// Metadata
4
#let page-width = get-page-width()
5
#let is-html-target = is-html-target() // target.starts-with("html")
6
#let is-pdf-target = is-pdf-target() // target.starts-with("pdf")
7
#let is-web-target = is-web-target() // target.starts-with("web") or target.starts-with("html")
8
9
#let project(body) = {
10
// set web/pdf page properties
11
set page(
12
width: page-width,
13
// for a website, we don't need pagination.
14
height: auto,
15
)
16
17
// remove margins for web target
18
set page(margin: (
19
// reserved beautiful top margin
20
top: 20pt,
21
// Typst is setting the page's bottom to the baseline of the last line of text. So bad :(.
22
bottom: 0.5em,
23
// remove rest margins.
24
rest: 0pt,
25
)) if is-web-target;
26
27
body
28
}