Helper Library
Better Reports includes a built-in Typst helper library at helpers/report.typ that provides common utilities for report generation.
Importing
typst
#import "helpers/report.typ": *Functions
format-date
Formats a date string into a readable format.
typst
#format-date("2024-01-15") // January 15, 2024format-number
Formats a number with thousand separators and decimal places.
typst
#format-number(1234567.89) // 1,234,567.89
#format-number(1234567.89, 0) // 1,234,568make-table
Creates a styled table from a 2D array.
typst
#let data = (
("Name", "Score", "Grade"),
("Alice", 95, "A"),
("Bob", 87, "B+"),
("Charlie", 92, "A-"),
)
#make-table(data, columns: (auto, auto, auto))section
Creates a styled section with a header and content.
typst
#section("Student Information")[
Name: #data.name
Course: #data.course
]highlight-box
Creates a colored highlight box for emphasizing content.
typst
#highlight-box[
This is important information that needs to stand out.
]header-footer
Sets up page headers and footers for the report.
typst
#header-footer(
title: "Annual Report",
date: datetime.today(),
)Example Usage
typst
#import "helpers/report.typ": *
#let data = json.decode(sys.inputs.at("data"))
#header-footer(
title: data.title,
date: datetime.today(),
)
= #data.title
#section("Summary")[
Report generated on #format-date(str(datetime.today()))
Total students: #format-number(data.students.len())
]
#section("Results")[
#make-table(data.results, columns: (auto, auto, auto, auto))
]