shiroa

Typst Support - Rendering Targets and Inputs

Shiroa passes compilation state through sys.inputssys.inputs. Use the exported values and predicates instead of reading the inputs repeatedly in each template.

x-targetx-target

#import "@preview/shiroa:0.4.0": x-target
#assert(type(x-target) == str)
#import "@preview/shiroa:0.4.0": x-target
#assert(type(x-target) == str)

The logical output target. Common values are:

  • pdfpdf: A paged PDF or editor preview.
  • web-lightweb-light, web-ayuweb-ayu, and other web-*web-* variants: A paged document rendered for the browser.
  • htmlhtml: A native Typst HTML page.
  • html-wrapperhtml-wrapper: An HTML page that loads a separately rendered paged document.

targettarget is a deprecated alias. New templates should use x-targetx-target.

Target predicates

  • is-html-target()is-html-target() accepts both htmlhtml and html-wrapperhtml-wrapper.
  • is-html-target(exclude-wrapper: true)is-html-target(exclude-wrapper: true) accepts native HTML but excludes the dynamic paged wrapper.
  • is-web-target()is-web-target() accepts webweb and web-*web-* variants.
  • is-pdf-target()is-pdf-target() accepts pdfpdf and pdf-*pdf-* variants.
#import "@preview/shiroa:0.4.0": (
is-html-target,
is-pdf-target,
is-web-target,
)
#if is-html-target(exclude-wrapper: true) [Native HTML]
#if is-web-target() [Paged web content]
#if is-pdf-target() [PDF or editor preview]
#import "@preview/shiroa:0.4.0": (
is-html-target,
is-pdf-target,
is-web-target,
)
#if is-html-target(exclude-wrapper: true) [Native HTML]
#if is-web-target() [Paged web content]
#if is-pdf-target() [PDF or editor preview]

page-widthpage-width and get-page-widthget-page-width

#import "@preview/shiroa:0.4.0": get-page-width, page-width
#assert(get-page-width() == page-width)
#import "@preview/shiroa:0.4.0": get-page-width, page-width
#assert(get-page-width() == page-width)

The width selected by Shiroa for the current responsive layout. The function form is preferred in page templates.

#import "@preview/shiroa:0.4.0": get-page-width, is-web-target
#set page(
width: get-page-width(),
height: auto,
) if is-web-target()
#import "@preview/shiroa:0.4.0": get-page-width, is-web-target
#set page(
width: get-page-width(),
height: auto,
) if is-web-target()

x-url-basex-url-base

#import "@preview/shiroa:0.4.0": x-url-base
#assert(x-url-base.starts-with("/") and x-url-base.ends-with("/"))
#import "@preview/shiroa:0.4.0": x-url-base
#assert(x-url-base.starts-with("/") and x-url-base.ends-with("/"))

The normalized deployment prefix. It always starts and ends with //. Prefix site-local links and assets with it when the book can be hosted below a path such as /project//project/.

x-currentx-current

#import "@preview/shiroa:0.4.0": x-current
#assert(x-current == none or type(x-current) == str)
#import "@preview/shiroa:0.4.0": x-current
#assert(x-current == none or type(x-current) == str)

The current source path, or nonenone outside a Shiroa page compilation. Themes use it to highlight the active chapter and expand {path}{path} in edit links.

shiroa-sys-targetshiroa-sys-target

#import "@preview/shiroa:0.4.0": shiroa-sys-target
#assert(type(shiroa-sys-target) == function)
#import "@preview/shiroa:0.4.0": shiroa-sys-target
#assert(type(shiroa-sys-target) == function)

Returns "html""html" when Typst is compiling with the native HTML target and "paged""paged" otherwise. This is different from x-targetx-target: it answers which Typst engine target is active, while x-targetx-target describes Shiroa’s logical role for that compilation.

book-sysbook-sys (advanced)

#import "@preview/shiroa:0.4.0": book-sys
#assert("target" in book-sys)
#assert("page-width" in book-sys)
#assert("sys-is-html-target" in book-sys)
#import "@preview/shiroa:0.4.0": book-sys
#assert("target" in book-sys)
#assert("page-width" in book-sys)
#assert("sys-is-html-target" in book-sys)

A snapshot containing the target values and predicates above. Prefer the individual functions in new templates; the dictionary is useful when passing all target state through another API.