CLI Init Command
The init
init
command will try to initialize your book to build your book successfully by default. This also means that all of the options from build
build
command are available for init
init
command.
For instance, Initialize a book to the directory my-book
my-book
:
shiroa init my-book/
shiroa build my-book/
shiroa init my-book/
shiroa build my-book/
shiroa init my-book/
shiroa build my-book/
shiroa init my-book/
shiroa build my-book/
Initialize a book with specific typst workspace directory:
shiroa init -w . my-book/
shiroa build -w . my-book/
shiroa init -w . my-book/
shiroa build -w . my-book/
shiroa init -w . my-book/
shiroa build -w . my-book/
shiroa init -w . my-book/
shiroa build -w . my-book/
Initialize a book with specific dest-dir
dest-dir
:
shiroa init --dest-dir ../dist my-book/
shiroa build my-book/ # memoryized dest-dir
shiroa init --dest-dir ../dist my-book/
shiroa build my-book/ # memoryized dest-dir
shiroa init --dest-dir ../dist my-book/
shiroa build my-book/ # memoryized dest-dir
shiroa init --dest-dir ../dist my-book/
shiroa build my-book/ # memoryized dest-dir
This section describes what are required by shiroa to build a book successfully.
- A
book.typ
book.typ
file in the root that collects all metadata and chapter files of the book. - A
template.typ
template.typ
file used by chapter files to render the page. - A sample
chapter1.typ
chapter1.typ
file shows how to use thetemplate.typ
template.typ
.
shiroa will read book.typ
book.typ
file first to find metadata and all chapter files, and render them accordingly.
The sample files are from tests/minimal
tests/minimal
directory.
Note: The sample is minimal and lacks of many show rules and theme settings to make good output. To learn more, please check Typst Supports
Typst Supports
.
your book.typ
book.typ
should at least provide a book-meta
book-meta
.
#import "@preview/shiroa:0.2.3": *
#show: book
#book-meta(
title: "My Book",
summary: [
= My Book
- #chapter("chapter1.typ", section: "1")[Chapter 1]
],
)
#import "@preview/shiroa:0.2.3": *
#show: book
#book-meta(
title: "My Book",
summary: [
= My Book
- #chapter("chapter1.typ", section: "1")[Chapter 1]
],
)
#import "@preview/shiroa:0.2.3": *
#show: book
#book-meta(
title: "My Book",
summary: [
= My Book
- #chapter("chapter1.typ", section: "1")[Chapter 1]
],
)
#import "@preview/shiroa:0.2.3": *
#show: book
#book-meta(
title: "My Book",
summary: [
= My Book
- #chapter("chapter1.typ", section: "1")[Chapter 1]
],
)
Your template.typ
template.typ
must import and respect the get-page-width
get-page-width
and target
target
variable from @preview/shiroa:0.2.3
@preview/shiroa:0.2.3
The two variables will be used by the tool for rendering responsive layout and multiple targets.
#import "@preview/shiroa:0.2.3": get-page-width, is-html-target, is-pdf-target, is-web-target, target, templates
#import templates: *
// Metadata
#let page-width = get-page-width()
#let is-html-target = is-html-target() // target.starts-with("html")
#let is-pdf-target = is-pdf-target() // target.starts-with("pdf")
#let is-web-target = is-web-target() // target.starts-with("web")
#let project(body) = {
// set web/pdf page properties
set page(
width: page-width,
// for a website, we don't need pagination.
height: auto,
) if is-pdf-target or is-web-target
// remove margins for web target
set page(margin: (
// reserved beautiful top margin
top: 20pt,
// Typst is setting the page's bottom to the baseline of the last line of text. So bad :(.
bottom: 0.5em,
// remove rest margins.
rest: 0pt,
)) if is-web-target
show: template-rules.with(
book-meta: include "book.typ",
plain-body: body,
)
body
}
#import "@preview/shiroa:0.2.3": get-page-width, is-html-target, is-pdf-target, is-web-target, target, templates
#import templates: *
// Metadata
#let page-width = get-page-width()
#let is-html-target = is-html-target() // target.starts-with("html")
#let is-pdf-target = is-pdf-target() // target.starts-with("pdf")
#let is-web-target = is-web-target() // target.starts-with("web")
#let project(body) = {
// set web/pdf page properties
set page(
width: page-width,
// for a website, we don't need pagination.
height: auto,
) if is-pdf-target or is-web-target
// remove margins for web target
set page(margin: (
// reserved beautiful top margin
top: 20pt,
// Typst is setting the page's bottom to the baseline of the last line of text. So bad :(.
bottom: 0.5em,
// remove rest margins.
rest: 0pt,
)) if is-web-target
show: template-rules.with(
book-meta: include "book.typ",
plain-body: body,
)
body
}
#import "@preview/shiroa:0.2.3": get-page-width, is-html-target, is-pdf-target, is-web-target, target, templates
#import templates: *
// Metadata
#let page-width = get-page-width()
#let is-html-target = is-html-target() // target.starts-with("html")
#let is-pdf-target = is-pdf-target() // target.starts-with("pdf")
#let is-web-target = is-web-target() // target.starts-with("web")
#let project(body) = {
// set web/pdf page properties
set page(
width: page-width,
// for a website, we don't need pagination.
height: auto,
) if is-pdf-target or is-web-target
// remove margins for web target
set page(margin: (
// reserved beautiful top margin
top: 20pt,
// Typst is setting the page's bottom to the baseline of the last line of text. So bad :(.
bottom: 0.5em,
// remove rest margins.
rest: 0pt,
)) if is-web-target
show: template-rules.with(
book-meta: include "book.typ",
plain-body: body,
)
body
}
#import "@preview/shiroa:0.2.3": get-page-width, is-html-target, is-pdf-target, is-web-target, target, templates
#import templates: *
// Metadata
#let page-width = get-page-width()
#let is-html-target = is-html-target() // target.starts-with("html")
#let is-pdf-target = is-pdf-target() // target.starts-with("pdf")
#let is-web-target = is-web-target() // target.starts-with("web")
#let project(body) = {
// set web/pdf page properties
set page(
width: page-width,
// for a website, we don't need pagination.
height: auto,
) if is-pdf-target or is-web-target
// remove margins for web target
set page(margin: (
// reserved beautiful top margin
top: 20pt,
// Typst is setting the page's bottom to the baseline of the last line of text. So bad :(.
bottom: 0.5em,
// remove rest margins.
rest: 0pt,
)) if is-web-target
show: template-rules.with(
book-meta: include "book.typ",
plain-body: body,
)
body
}
Your chapter1.typ
chapter1.typ
should import and use the template.typ
template.typ
, as follow:
#import "template.typ": *
#show: project
= Chapter 1
This is the first chapter of the book.
#import "template.typ": *
#show: project
= Chapter 1
This is the first chapter of the book.
#import "template.typ": *
#show: project
= Chapter 1
This is the first chapter of the book.
#import "template.typ": *
#show: project
= Chapter 1
This is the first chapter of the book.