LayMesh
Reproducible scientific figures and precise physical layouts from readable code. Compose native plots, images, vector shapes, text and formulas in one editable .lay source; export SVG, PDF, editable PPTX and PNG/JPEG/TIFF/WebP/BMP/GIF/ICO/PNM/TGA with a native Rust engine.
中文文档 · English documentation · Examples · Source · Video tutorial (Bilibili)
Install
Requires Python 3.10+. Platform releases bundle the native engine. Install from PyPI and use --version to check the installed version; current-source documentation can include features newer than the published package:
python -m pip install laymesh
python -m laymesh --version
Platform wheels bundle one native Rust executable and formula fonts. Rendering requires no Rust compiler, Node.js or TeX installation and downloads no engine or fonts. Body fonts come from the operating system or user-provided files; missing glyphs warn and display vector boxes. Supply font files with a layout for reproducible text across machines.
The standard installation includes NumPy, pandas, Matplotlib and IPython. Data bindings, Matplotlib Figure import and Jupyter magics are ready to use.
Wheel targets are Windows x64, macOS 14+ on Intel and Apple Silicon, and Linux x64 / arm64. Linux requires glibc at least as new as the wheel's manylinux_2_XX tag. Availability depends on uploaded wheels; Alpine/musl, 32-bit platforms and Windows ARM64 have no wheels. Plots are rendered by the native engine.
MP4/GIF animation export reuses existing FFmpeg or requests confirmation before installing it in the shared user directory. Static exports remain complete layouts; animations run only during playback or explicit time/step snapshots. See the animation guide.
First figure: CLI
Save this complete source as figure.lay:
page = canvas(size=(120 mm, 90 mm), background="#ffffff")
p = plot(size=(110 mm, 80 mm),
x=axis(label="Time (s)"), y=axis(label="Signal"))
p.line(x=[0, 1, 2, 3], y=[1, 3, 2, 4], label="Experiment")
p.legend(position="top_left")
page.add(p, offset=(5 mm, 5 mm))
laymesh validate figure.lay
laymesh inspect figure.lay --json
laymesh render figure.lay -o figure.svg
laymesh render figure.lay -o figure.pdf
laymesh render figure.lay -o figure.png --dpi 300
python -m laymesh invokes the same CLI. Geometry defaults to mm; typography and line widths default to pt. Raster DPI changes output pixels while preserving physical dimensions. .lay is a restricted standalone language, separate from Python.
Connect annotations
Line materials may define only their appearance. Both endpoints determine the geometry when placed:
page = canvas(size=(80mm, 50mm))
label = page.add(text(content="Signal"), offset=(10mm, 5mm))
pointer = line(line_color="#d55e00", end_head=head(shape="open"))
page.add(pointer, start=label.bottom_right, end=(60mm, 35mm),
start_offset=(0mm, 1mm))
Endpoints also accept placed chart data points and selected path anchors. Each endpoint offset uses physical units; target-space offsets follow a path's tangent and left normal. Existing line(dx=..., dy=...) and line(length=..., angle=...) materials remain reusable, with endpoints overriding geometry for that placement. Anchors and connections.
Image export options
laymesh render figure.lay -o figure.jpg --dpi 300 --quality 95 --background "#ffffff"
laymesh render figure.lay -o figure.tif --dpi 600 --compression deflate
laymesh render figure.lay -o figure.webp --dpi 300 --webp-lossless false --quality 90 --webp-method 6
render_file and render_source accept dpi, quality, compression, background, webp_lossless, webp_method, webp_alpha_quality and webp_near_lossless. Notebook magics accept the corresponding CLI flags. Raster exports use 8-bit sRGB; PNG/JPEG/TIFF/BMP record DPI metadata. JPEG uses a matte; GIF has binary alpha; RGBA formats retain partial transparency. Export options.
Python API
from laymesh import render_source
source = '''
page = canvas(size=(120 mm, 90 mm), background="#ffffff")
p = plot(size=(110 mm, 80 mm),
x=axis(label="Time (s)"), y=axis(label="Signal"))
p.line(x=[0, 1, 2, 3], y=[1, 3, 2, 4], label="Experiment")
p.legend(position="top_left")
page.add(p, offset=(5 mm, 5 mm))
'''
result = render_source(source, output="python-figure.svg", save_source="python-figure.lay")
print(result.output)
Use render_file("figure.lay", output="figure.pdf") to render existing source. Pass Python variables via namespace={"values": values} and refer to them with an unquoted {{values}} placeholder in .lay. Lists, dictionaries, NumPy arrays and pandas DataFrames can feed native plots. Matplotlib Figures can be placed as image assets. Keep calculations in Python; placeholders accept variable names, not expressions.
save_source saves expanded source and a sibling .assets/ directory for independent CLI rendering. Preserve that directory and any referenced modules, stylesheets or fonts with the .lay file. Python API and data examples.
Jupyter
Install LayMesh in the active kernel's environment. First run:
%load_ext laymesh.ipython
values = [1, 3, 2, 4]
Then run this separate cell:
%%laymesh -o notebook.pdf --save-source notebook.lay
page = canvas(size=(120 mm, 90 mm))
p = plot(size=(110 mm, 80 mm))
p.line(x=[0, 1, 2, 3], y={{values}})
page.add(p, offset=(5 mm, 5 mm))
The magic displays a 192 DPI JPEG preview (quality 95, 4:4:4 sampling, white matte) from the Rust CPU renderer at double pixel density and writes the requested export. The export and preview share one native compilation. --preview-dpi, --preview-quality and --preview-background control the preview independently of export settings; render_source and render_file retain the compatible preview_svg result. %laymesh figure.lay -o figure.png --dpi 300 renders an existing file. Both magics support --warnings show|hide. Notebook guide.
Scope
LayMesh provides physical units, anchors, cropping, paths, reusable modules, LCSS styles and native scientific plots including statistical, polar and radar layers. Artistic text adds glyph gradients and outlines, path text, arc/wave/perspective warps and two-dimensional vector extrusion. Text, shapes, transparent images and groups support inner/outer shadows and glow via effects=[shadow(...), glow(...)]. These source interfaces work through render_source and Notebook cells. PDF subjects stay vector, while effect layers use tiled raster rendering at the configured DPI (default 1200). See the effects guide.
.lay defines one page; .laydoc sequences multiple pages. Panels use explicit positioning. Finish plot layers and decorations before placing a chart. Fixed plot areas keep their physical dimensions; decoration overflow emits a warning. Language reference.
中文
LayMesh 用一个可编辑的 .lay 文件组织科研图表、图片、文字与公式,导出 SVG、PDF、PNG。需要 Python 3.10+;运行 python -m pip install laymesh 即可安装全部功能,包括 NumPy/pandas 数据绑定和 Matplotlib Figure 导入。平台 wheel 内置原生 Rust 引擎和公式字体,正文使用系统或用户字体。支持字形渐变与描边、沿路径排字、弧形/波浪/透视变形、二维矢量挤出,以及文字、形状、透明图片和组的内外阴影与发光。PDF 主体保持矢量,效果层按设置的 DPI 分块渲染,默认 1200 DPI。效果说明。支持 laymesh 命令、Python API 和 Jupyter Magic;保存源码与资源后可独立重新导出。中文入门。
LayMesh is MIT licensed. Bundled native dependencies, formula fonts and colormap data retain their own license texts inside the installed package. _vendor/manifest.json records engine, platform and build hashes; _vendor/licenses/manifest.json records dependency license provenance.
Exports default to 1200 DPI, independently of layout_dpi. PDF accepts dpi, pdf_image_compression, pdf_jpeg_quality, pdf_downsample, pdf_recompress_jpeg, pdf_preserve_16bit, pdf_preserve_alpha, pdf_alpha_background, pdf_auto_palette_limit, and pdf_auto_flatness_threshold. config=PATH selects project defaults; Notebook magics support corresponding --config and --pdf-* flags. See configuration.
Editable PowerPoint export
Available in LayMesh 0.5.0 or later.
from laymesh import render_file
render_file("figure.lay", output="figure.pptx")
CLI and Jupyter magics also accept -o figure.pptx. Each canvas becomes one slide; text is editable, formulas use grouped outlines, and complex effects may fall back locally to PNG. Fonts are not embedded. dpi controls fallback resolution only (default 1200).
多页文档使用 render_document("report.laydoc", output="report.pdf");page=2 导出单页,preview_page=2 只选择 JPEG 预览页。编排文件复用 Lay 语法,详见 多页文档。
Multi-page documents use render_document("report.laydoc", output="report.pdf"); page=2 exports one page and preview_page=2 selects only the JPEG preview. The orchestration file uses the Lay DSL. See multi-page documents.
Styles and animation
Keep repeated appearance in a project theme and placement/data in .lay. Explicit parameters take priority over styles. Current-source manuals cover offline libraries, selective shadow overrides, custom keyframes, all 97 effects and step scheduling: Style manual · Animation manual. New library and diagnostic support requires a build containing those changes.
Animation export and shared FFmpeg
from laymesh import animate_file, animate_source, ffmpeg_status
print(ffmpeg_status()) # Local discovery only; no download.
result = animate_file("figure.lay", "figure.mp4", width=1920, fps=30)
result = animate_source(source, "figure.gif", base_dir=".", width=960, fps=20)
Python uses the same native manager and private FFmpeg directory as the CLI and VS Code on the same host. Existing programs are verified and recorded, without copying. A missing encoder requests confirmation on an interactive terminal; noninteractive calls raise FFmpegDownloadRequired. Use allow_download=True only to authorize that particular call, or run python -m laymesh ffmpeg install --yes once. Global/project JSON settings cannot authorize downloads. config= accepts the same native JSON configuration as the CLI. The manager automatically measures the upstream and China mirror, checks pinned SHA-256 values, and keeps downloaded LICENSE/README files.
Metadata
Release files for laymesh 0.6.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| laymesh-0.6.3-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for laymesh-0.6.3-py3-none-win_amd64.whl |
| laymesh-0.6.3-py3-none-manylinux_2_39_x86_64.whl | Python 3 | none | Linux glibc 2.39+ x86-64 | Details for laymesh-0.6.3-py3-none-manylinux_2_39_x86_64.whl |
| laymesh-0.6.3-py3-none-manylinux_2_39_aarch64.whl | Python 3 | none | Linux glibc 2.39+ ARM64 | Details for laymesh-0.6.3-py3-none-manylinux_2_39_aarch64.whl |
| laymesh-0.6.3-py3-none-macosx_14_0_x86_64.whl | Python 3 | none | macOS 14.0+ x86-64 | Details for laymesh-0.6.3-py3-none-macosx_14_0_x86_64.whl |
| laymesh-0.6.3-py3-none-macosx_14_0_arm64.whl | Python 3 | none | macOS 14.0+ ARM64 | Details for laymesh-0.6.3-py3-none-macosx_14_0_arm64.whl |
Total release size: 93.3 MB
Release files / laymesh-0.6.3-py3-none-win_amd64.whl
| Download URL | laymesh-0.6.3-py3-none-win_amd64.whl |
|---|---|
| Size | 18.6 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a8c956a0142c32aba5cf3c985f99267217708e41c00a2bcdfcc395ab6c16cb30
|
|
BLAKE2b-256 checksum How to use checksums |
848be9770e87de66fd99b881a175781d445cf840f351fb0f0922649731bd9821
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / laymesh-0.6.3-py3-none-manylinux_2_39_x86_64.whl
| Download URL | laymesh-0.6.3-py3-none-manylinux_2_39_x86_64.whl |
|---|---|
| Size | 19.7 MB |
| Tags | Linux glibc 2.39+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
0c7d1fb28b2c708bd4973ec9d35cf562fe2ff2bae8db0be3ad086e3f2a4feae8
|
|
BLAKE2b-256 checksum How to use checksums |
ce90486fea265f3886aa0e1181684819934d5db36356578bf3742f6c9b403b7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / laymesh-0.6.3-py3-none-manylinux_2_39_aarch64.whl
| Download URL | laymesh-0.6.3-py3-none-manylinux_2_39_aarch64.whl |
|---|---|
| Size | 19.0 MB |
| Tags | Linux glibc 2.39+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
cd7bca4a9f06f47c17c72c4cd4d877fdbd59ed99b7f8055737642d5755d95573
|
|
BLAKE2b-256 checksum How to use checksums |
ecd196e443dac779c26e3e6b0b517a876bee27d345f99c0689ec6ed6ec982b18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / laymesh-0.6.3-py3-none-macosx_14_0_x86_64.whl
| Download URL | laymesh-0.6.3-py3-none-macosx_14_0_x86_64.whl |
|---|---|
| Size | 18.4 MB |
| Tags | Python 3 macOS 14.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
904934e235183c4df8b5ce5f971e4a339b0f277f7e0074b885f2d4a57d7848be
|
|
BLAKE2b-256 checksum How to use checksums |
c8c7ab927bab2c42ec1aadbacd6d2418a1069e2a2c89614fd3a93dd55f97b2d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / laymesh-0.6.3-py3-none-macosx_14_0_arm64.whl
| Download URL | laymesh-0.6.3-py3-none-macosx_14_0_arm64.whl |
|---|---|
| Size | 17.5 MB |
| Tags | Python 3 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bcce03685aaba5ad2205e1834e0ce461075013e6d495dd9355e98623daab18ae
|
|
BLAKE2b-256 checksum How to use checksums |
0934cfdc1bc7c27f2f24861135b84a0cf1882fbfa7c1da0af9a73103cb990981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logSecurity for laymesh 0.6.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for laymesh-0.6.3-py3-none-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.