CLI Init Command
The initinit command will try to initialize your book to build your book successfully by default. This also means that all of the options from buildbuild command are available for initinit command.
For instance, Initialize a book to the directory my-bookmy-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/
Initialize a book with specific dest-dirdest-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.typbook.typfile in the root that collects all metadata and chapter files of the book. - A
template.typtemplate.typfile used by chapter files to render the page. - A sample
chapter1.typchapter1.typfile shows how to use thetemplate.typtemplate.typ.
shiroa will read book.typbook.typ file first to find metadata and all chapter files, and render them accordingly.
The sample files are from tests/minimaltests/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 SupportsTypst Supports.
your book.typbook.typ should at least provide a book-metabook-meta.
#import "@preview/shiroa:0.3.1": *#show: book#book-meta( title: "My Book", summary: [ = My Book - #chapter("chapter1.typ", section: "1")[Chapter 1] ],)
#import "@preview/shiroa:0.3.1": *#show: book#book-meta( title: "My Book", summary: [ = My Book - #chapter("chapter1.typ", section: "1")[Chapter 1] ],)
Your template.typtemplate.typ must import and respect the get-page-widthget-page-width and targettarget variable from @preview/shiroa:0.3.1@preview/shiroa:0.3.1 The two variables will be used by the tool for rendering responsive layout and multiple targets.
#import "@preview/shiroa:0.3.1": get-page-width, is-html-target, is-pdf-target, is-web-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.3.1": get-page-width, is-html-target, is-pdf-target, is-web-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.typchapter1.typ should import and use the template.typtemplate.typ, as follow:
#import "template.typ": *#show: project= Chapter 1This is the first chapter of the book.
#import "template.typ": *#show: project= Chapter 1This is the first chapter of the book.