Resource paths#
Purpose and concepts#
Resource paths are relative to the defining file, not the shell working directory. Material, modules and standalone LCSS retain their own resource origin; the entry path organizes dependencies.
Minimal complete example#
Run this file directly with laymesh validate or laymesh render; it contains its own canvas and required definitions.
# Minimal complete example: imagepage=canvas(size=(100mm,75mm),background="#ffffff")page.add(image(src="../assets/photo.png"),size=(55mm,auto),offset=(8mm,8mm))# Minimal complete example: imagepage=canvas(size=(100mm,75mm),background="#ffffff")page.add(image(src="../assets/photo.png"),size=(55mm,auto),offset=(8mm,8mm))Preview
Dependencies
examples/assets/photo.pngexamples/manual/image.lay
Parameters and default behavior#
Unitless geometry uses the canvas unit; unitless type and stroke sizes use pt. Explicit call parameters override inherited/theme defaults. The linked interface reference lists accepted types, choices and defaults per parameter.
Composition#
Keep pictures, fonts and components beside the work and use relative paths. Python save_source writes bound data/images to a sibling .assets directory; preserve relative locations when sharing.
first = page.add(card("A"), target=page.top_left, offset=(8 mm, 29 mm))page.add(card("B"), target=first.top_right, offset=(13 mm, 0 mm))# Gallery: containers / module-importimport { card } from "./card-component.lay"page = canvas(name="Imported component", size=(120 mm, 80 mm), background="#f7f9fc")font = "DejaVu Sans"heading = text(content="Imported component", font_family=font, font_size=14 pt, color="#203864")page.add(heading, target=page.top_left, offset=(7 mm, 5 mm))# BEGIN DEMOfirst = page.add(card("A"), target=page.top_left, offset=(8 mm, 29 mm))page.add(card("B"), target=first.top_right, offset=(13 mm, 0 mm))# END DEMO## @lang zh-CN## 创建圆角卡片,并将标题放在中央。## @param {string} label - 标题文字;支持行内公式。## @returns {group} 可重复放置的卡片,宽 42mm、高 31mm。## @example## item = card("结果")## @lang en## Create a rounded card with a centered caption.## @param {string} label - Caption text; supports inline mathematics.## @returns {group} Reusable card material, 42mm wide and 31mm high.## @example## item = card("Result")export function card(label) { item = group() plate = item.add(rect(size=(42 mm, 31 mm), border_radius=3 mm, fill="#d8f0ec", border_color="#087f8c", border_width=0.5 mm), target=item.top_left) item.add(text(content=label, font_family="DejaVu Sans", font_size=11 pt, color="#203864"), anchor=center, target=plate.center) return item}Preview
Dependencies
examples/gallery/containers/card-component.layexamples/gallery/containers/module-import.lay
Common errors and limits#
WASM’s virtual file map must contain every dependency; a browser cannot freely read local files. Resource errors locate the defining file, and font-name resolution depends on the runtime.
Individual functions#
Detailed behavior and further examples#
Parameters#
| Parameter | Purpose | Default or requirement |
|---|---|---|
src |
Image or data path | Relative to defining file |
font_family |
Font family or file | Optional; depends on installed fonts |
Directory relationships#
examples/├── assets/│ └── Custom.ttf└── plot/ ├── figure.lay └── results.csvfont_family="../assets/Custom.ttf" resolves from plot/figure.lay to the sibling font directory; table(src="results.csv") refers to data beside the source. Rename assets if you also update paths. Resources inside components resolve relative to the component file, not the entry file.
Use font_family="DejaVu Sans" only if that family is installed on the system. The path above selects a user-provided font. No body fonts are bundled; unavailable glyphs warn and render as vector boxes.
Limits and related topics#
Image import and cropping · Text and fonts · Mathematical formulas · Shapes and paths · Fills, gradients and outlines

