b

bullseye

@preview

Hit the target (HTML or paged/PDF) when styling your Typst document

v0.1.0
MIT

Package Information

Last Updated
Minimum Typst Version
0.12.0
Categories
scriptingutility

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/bullseye:0.1.0

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/bullseye:0.1.0": *

Version History

0.1.00.12.0
4959a4fe6742...

Bullseye

This library helps you write target-dependent Typst code, particularly target-dependent content and show rules.

This package consists of two parts:

  • At the foundation, it contains a wrapper around the currently unstable Typst features for target detection and HTML output.
  • Built on top of that are a few helpful functions that allow package and document authors to easily write content and show rules that behave differently based on the target.

Bullseye makes sure that your code compiles even when HTML support is not enabled (e.g. in the web app or when previewing using Tinymist) as long as no HTML specific content ends up in the rendered document, and automatically switches to Typst's HTML support when it is enabled.

Getting Started

To add this package to your project, use this:

#import "@preview/bullseye:0.1.0": *

// apply styling only for non-HTML output
#show: show-target(paged: doc => {
  set page(height: auto)

  import "@preview/codly:1.3.0"
  show: codly.codly-init
  doc
})

// apply image styling only for html output
#show image: show-target(html: img => {
  html.elem("img", attrs: ("src": img.source, "alt": img.alt))
})

// insert content only for HTML output
#context on-target(html: {
  html.elem("a", attrs: (href: "#"))[(back to top)]
})

Usage

See the manual for details.