{"id":15140946,"url":"https://github.com/peterhellberg/typ","last_synced_at":"2025-10-23T18:30:21.862Z","repository":{"id":256616742,"uuid":"855937759","full_name":"peterhellberg/typ","owner":"peterhellberg","description":"A small Zig ⚡ module, as a convenience for me when writing WebAssembly plugins for Typst","archived":false,"fork":false,"pushed_at":"2024-09-12T08:32:42.000Z","size":25,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T20:05:40.830Z","etag":null,"topics":["module","typesetting","typst","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterhellberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-11T17:48:48.000Z","updated_at":"2024-10-18T21:34:04.000Z","dependencies_parsed_at":"2024-09-21T14:00:50.238Z","dependency_job_id":null,"html_url":"https://github.com/peterhellberg/typ","commit_stats":null,"previous_names":["peterhellberg/typ"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Ftyp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Ftyp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Ftyp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Ftyp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhellberg","download_url":"https://codeload.github.com/peterhellberg/typ/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237869121,"owners_count":19379269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["module","typesetting","typst","zig"],"created_at":"2024-09-26T08:42:36.987Z","updated_at":"2025-10-23T18:30:21.857Z","avatar_url":"https://github.com/peterhellberg.png","language":"Zig","readme":"# typ :printer:\n\nA small [Zig](https://ziglang.org/) ⚡ module, as a convenience for me when writing WebAssembly\n[plugins](https://typst.app/docs/reference/foundations/plugin/) for [Typst](https://typst.app/)\n\n\u003e [!NOTE]\n\u003e Initially based on the [hello.zig](https://github.com/astrale-sharp/wasm-minimal-protocol/blob/master/examples/hello_zig/hello.zig)\n\u003e example in [wasm-minimal-protocol](https://github.com/astrale-sharp/wasm-minimal-protocol/)\n\n## Requirements\n\nYou will want to have a fairly recent [Zig](https://ziglang.org/download/#release-master)\nas well as the [Typst CLI](https://github.com/typst/typst?tab=readme-ov-file#installation)\n\n\u003e [!IMPORTANT]\n\u003e I had to `rustup default 1.79.0` when compiling the latest `typst`\n\u003e as there were some breaking change in `1.80.0`\n\n\u003e [!TIP]\n\u003e Some of the software that I have installed for a pretty\n\u003e nice **Typst** workflow in [Neovim](https://neovim.io/):\n\u003e\n\u003e - https://github.com/nvarner/typst-lsp\n\u003e - https://github.com/kaarmu/typst.vim\n\u003e - https://github.com/chomosuke/typst-preview.nvim\n\n## Usage\n\nUse `zig fetch` to add a `.typ` to the `.dependencies` in your `build.zig.zon`\n\n```console\nzig fetch --save https://github.com/peterhellberg/typ/archive/refs/tags/v0.1.0.tar.gz\n```\n\n\u003e [!NOTE]\n\u003e You should now be able to update your `build.zig` as described below.\n\n#### `build.zig`\n```zig\nconst std = @import(\"std\");\n\npub fn build(b: *std.Build) void {\n    const target = b.resolveTargetQuery(.{\n        .cpu_arch = .wasm32,\n        .os_tag = .freestanding,\n    });\n\n    const hello = b.addExecutable(.{\n        .name = \"hello\",\n        .root_module = b.createModule(.{\n            .root_source_file = b.path(\"hello.zig\"),\n            .strip = true,\n            .target = target,\n            .optimize = .ReleaseSmall,\n        }),\n    });\n\n    const typ = b.dependency(\"typ\", .{}).module(\"typ\");\n\n    hello.root_module.addImport(\"typ\", typ);\n    hello.entry = .disabled;\n    hello.rdynamic = true;\n\n    b.installArtifact(hello);\n}\n```\n\n#### `hello.zig`\n```zig\nconst typ = @import(\"typ\");\n\nexport fn hello() i32 {\n    const msg = \"*Hello* from `hello.wasm` written in Zig!\";\n\n    return typ.str(msg);\n}\n\nexport fn echo(len: usize) i32 {\n    var res = typ.alloc(u8, len * 2) catch return 1;\n    defer typ.free(res);\n\n    typ.write(res.ptr);\n\n    for (0..len) |i| {\n        res[i + len] = res[i];\n    }\n\n    return typ.ok(res);\n}\n```\n\n#### `hello.typ`\n```typst\n#set page(width: 10cm, height: 10cm)\n#set text(font: \"Inter\")\n\n== A WebAssembly plugin for Typst\n\n#line(length: 100%)\n\n#emph[Typst is capable of interfacing with plugins compiled to WebAssembly.]\n\n#line(length: 100%)\n\n#let p = plugin(\"zig-out/bin/hello.wasm\")\n\n#eval(str(p.hello()), mode: \"markup\")\n\n#eval(str(p.echo(bytes(\"1+2\"))), mode: \"code\")\n```\n\n#### Expected output\n\n![hello.png](https://github.com/user-attachments/assets/a1cd9c86-ef94-4d1f-a44c-b958475f79b0)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Ftyp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhellberg%2Ftyp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Ftyp/lists"}