{"id":16118498,"url":"https://github.com/duskmoon314/mdbook-typst-math","last_synced_at":"2025-03-17T18:30:41.527Z","repository":{"id":212706975,"uuid":"727058551","full_name":"duskmoon314/mdbook-typst-math","owner":"duskmoon314","description":"mdbook typst preprocessor","archived":false,"fork":false,"pushed_at":"2024-05-28T05:00:43.000Z","size":126,"stargazers_count":7,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T13:51:15.994Z","etag":null,"topics":["mdbook","mdbook-preprocessor","rust","typst"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/duskmoon314.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-04T05:07:20.000Z","updated_at":"2025-03-03T14:59:37.000Z","dependencies_parsed_at":"2023-12-15T19:21:17.156Z","dependency_job_id":null,"html_url":"https://github.com/duskmoon314/mdbook-typst-math","commit_stats":null,"previous_names":["duskmoon314/mdbook-typst","duskmoon314/mdbook-typst-math"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskmoon314%2Fmdbook-typst-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskmoon314%2Fmdbook-typst-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskmoon314%2Fmdbook-typst-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duskmoon314%2Fmdbook-typst-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duskmoon314","download_url":"https://codeload.github.com/duskmoon314/mdbook-typst-math/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243878456,"owners_count":20362432,"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":["mdbook","mdbook-preprocessor","rust","typst"],"created_at":"2024-10-09T20:49:43.945Z","updated_at":"2025-03-17T18:30:41.258Z","avatar_url":"https://github.com/duskmoon314.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mdbook-typst-math\n\nAn mdbook preprocessor to use [typst](https://typst.app/) to render math.\n\n## Installation\n\n```shell\ncargo install --git https://github.com/duskmoon314/mdbook-typst-math\n# OR\ngit clone https://github.com/duskmoon314/mdbook-typst-math.git\ncargo build --release\n```\n\n## Usage\n\n### Setup preprocessor\n\nAdd the following to your `book.toml`:\n\n```toml\n[preprocessor.typst-math]\ncommand = \"/path/to/mdbook-typst-math\"\n```\n\nThe path is usually `~/.cargo/bin/mdbook-typst-math` if you installed it using `cargo`.\n\nOther configurations see the following section: [Configuration](#configuration).\n\n### Control the style\n\nAdd css to control the style of the typst block:\n\n```css\n/* css/typst.css as an example */\n.typst-inline {\n  display: inline flex;\n  vertical-align: bottom;\n}\n\n.typst-display {\n  display: block flex;\n  justify-content: center;\n}\n\n.typst-display \u003e .typst-doc {\n  transform: scale(1.5);\n}\n```\n\nAdd the following to your `book.toml`:\n\n```toml\n[output.html]\nadditional-css = [\"css/typst.css\"]\n```\n\n### What this preprocessor does\n\nThis preprocessor will convert all math blocks to a `\u003cdiv\u003e` with the class\n`typst-inline`/`typst-display` (depends on the type of math blocks) and a\n`\u003csvg\u003e` with the class `typst-doc` inside.\n\nSay you have the following code block in your markdown:\n\n```markdown\n    hello\n    $$\n    y = f(x)\n    $$\n    world\n```\n\nThis preprocessor will first change it to:\n\n```diff\n    hello\n    $$\n+   #set page(width:auto, height:auto, margin:0.5em)\n+   $ y = f(x) $\n-   y = f(x)\n    $$\n    world\n```\n\nThe above is a valid `typst` code. The dollar signs `$` and whitespaces are used to let typst knows it is a math block instead of an inline math.\n\nThen preprocessor will leverage `typst` to render the math block and change it to:\n\n```html\nhello\n\u003cdiv class=\"typst-display\"\u003e\n  \u003csvg class=\"typst-doc\" ...\u003e\u003c/svg\u003e\n\u003c/div\u003e\nworld\n```\n\n### Configuration\n\nCurrently, only following configurations are supported. Here we use an example to show how to set them:\n\n````toml\n[preprocessor.typst]\n\n# Additional fonts to load\n#\n# Two types are supported: a string or an array of strings\n#\n# Usually, you don't need to set this since the default build of preprocessor\n# will load system fonts and typst embedded fonts.\nfonts = [\"Fira Math\"] # or \"Fira Math\"\n\n# Preamble to be added before the typst code\n#\n# The default preamble is:\n# ```\n# #set page(width:auto, height:auto, margin:0.5em)\n# ```\npreamble = \"\"\"\n#set page(width:auto, height:auto, margin:0.5em)\n#set text(size: 12pt)\n#show math.equation: set text(font: \"Fira Math\")\n\"\"\"\n\n# Preamble to be added before the typst code for inline math\n#\n# If not set, the `preamble` will be used.\n#\n# Usually, this is not needed. But if you want to use different settings for\n# inline math and display math, you can set this.\ninline_preamble = \"\"\"\n#set page(width:auto, height:auto, margin:0.5em)\n#set text(size: 12pt)\n#show math.equation: set text(font: \"Fira Math\")\n\"\"\"\n\n# Preamble to be added before the typst code for display math\n#\n# If not set, the `preamble` will be used.\n#\n# Usually, this is not needed. But if you want to use different settings for\n# inline math and display math, you can set this.\ndisplay_preamble = \"\"\"\n#set page(width:auto, height:auto, margin:0.5em)\n#set text(size: 14pt)\n#show math.equation: set text(font: \"Fira Math\")\n\"\"\"\n````\n\n## TODO\n\n- [x] Integrate `typst` in code instead of using `std::process::Commend`\n  - [ ] Refactor the code to improve readability and maintainability\n- [x] Allow user to configure the preambles through `book.toml`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduskmoon314%2Fmdbook-typst-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduskmoon314%2Fmdbook-typst-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduskmoon314%2Fmdbook-typst-math/lists"}