1. Introduction
  2. Guidance
  3. 1. Get started
  4. 2. Bundles
    1. 2.1. All-in-One Library for Browsers
    2. 2.2. All-in-One Library for Node.js
  5. 3. Compilers
    1. 3.1. (Pre-)Compiler in CLI
    2. 3.2. Compiler in Rust
    3. 3.3. Compiler in Node.js
    4. 3.4. Compiler in Wasm (Web)
  6. 4. Renderers
    1. 4.1. Renderer in Rust
    2. 4.2. Renderer in Node.js
    3. 4.3. Renderer in Wasm (Web)
    4. 4.4. Renderer in React
    5. 4.5. Renderer in Solid
    6. 4.6. Renderer in Angular
    7. 4.7. Renderer in Vue3
    8. 4.8. Hexo Plugin
  7. 5. Samples
    1. 5.1. Static, Responsive rendering
    2. 5.2. Streaming, Incremental rendering
    3. 5.3. Serverless rendering
  8. 6. Trouble Shooting
  9. Project samples
  10. 8. shiroa
  11. 9. typst-preview
  12. 10. hexo-renderer-typst
  13. References
  14. 13. Routing to Renferences

reflexo-typst Documentation

Claim: the Typst compiling functions is provided by official typst

Example Application: single-file, shiroa and hexo-renderer-typst

#

How does Responsive Rendering Work?

You must prepare a artifact for each document, containing compressed data for different theme and screen settings. The bundle size of artifacts is optimized for typst documents.

Since preparation is offline, it is suitable for static sites and blogs.

After that, we provide a renderer to extract and render artifact in browser. Obviously, it doesn't have capabilities to compile typst code.

Besides static display effect like PDF, by rendering document to canvas, The renderer also overlays SVG for responsive effect by CSS anominations, and HTML layer for semantics embedding and user interactions. If you would like to hack, the HTML elements can be also placed in Typst document.

#

Is it Really Static?

You may doubt that if a renderer is used, it is not static. Though we provide absolutely static renderer that exports typst to browser-directed SVG, official typst also provides PNG, SVG, and PDF export. They are not responsive.

For responsive rendering, it is worth to note that some metadata can be also embedded in HTML. For example, you can embed title, description meta in head to allow page previewing in social media. Though it is not implemented, HTML elements is considered for rendered statically to help SEO.

#

Prepare Artifacts: Precompiler Part

As an example, hexo-renderer-typst utilizes All-in-one Library for Node.js to build its functions. First, it creates a dyn layout compiler for precompiling documents:


        
this.dyn = DynLayoutCompiler.fromBoxed(NodeCompiler.create(compileArgs).intoBoxed());

        
this.dyn = DynLayoutCompiler.fromBoxed(NodeCompiler.create(compileArgs).intoBoxed());

Then, it simply invokes vector() method to compile the document:


        
return this.dyn.vector({ mainFilePath: path });

        
return this.dyn.vector({ mainFilePath: path });

#

Prepare Artifacts: Typst Scripting Part

#

x-page-width (stable)

Retrieving the sys arguments specified by the dynamic layout compiler:


        
/// It is in default A4 paper size (21cm)

        
#let page-width = sys.inputs.at("x-page-width", default: 21cm)

        
/// It is in default A4 paper size (21cm)

        
#let page-width = sys.inputs.at("x-page-width", default: 21cm)

Templating Example:


        
#set page(

        
  width: page-width,

        
  height: auto, // Also, for a website, we don't need pagination.

        
) if is-web-target;

        
#set page(

        
  width: page-width,

        
  height: auto, // Also, for a website, we don't need pagination.

        
) if is-web-target;

#

x-target (unstable)

Note: If you find x-target is not overridden for export web artifacts, the SSG tool you are using may not follow this convention.

Note: Official typst may introduce their owned method to specify target, therefore this feature may move to the native approach in future.

Retrieving the sys arguments specified by SSG Tools:


        
/// The default target is _pdf_.

        
/// `typst.ts` will set it to _web_ when rendering a dynamic layout.

        
#let target = sys.inputs.at("x-target", default: "pdf")

        
/// The default target is _pdf_.

        
/// `typst.ts` will set it to _web_ when rendering a dynamic layout.

        
#let target = sys.inputs.at("x-target", default: "pdf")

Example:


        
#let is-web-target() = target.starts-with("web")

        
#let is-pdf-target() = target.starts-with("pdf")

        
#let is-web-target() = target.starts-with("web")

        
#let is-pdf-target() = target.starts-with("pdf")

#

Build Tools for SSGs (Static Site Generators)

The interface to develop a tools is explored. But there are already easy-touse tools that could be used for your SSG Framework or learned for a new one:

  • shiroa for self-hosted simple book (documentation) site.

  • hexo-renderer-typst for Hexo.

  • apollo-typst for Apollo.