Repository navigation
fix(pdf): auto-install typst on Linux/Windows, render CJK text in PDFs - #30
Merged
Merged
Conversation
mtmatt
added this pull request to stack #31
September 28, 2026 11:55
- typst was listed in tools.toml but never wired into the downloader's Manifest, so ensure_typst failed with "unknown tool: typst" on Linux/Windows. Add it, pin its sha256s, and test that every tools.toml table resolves. - New document/pdf.rs picks pandoc's PDF engine. It passes pandoc the engine name (a full path makes pandoc break typst image paths) and appends engine dirs to pandoc's PATH, so a typst in the app's tool dir is found. - Distro pandoc 3.1.x's typst template defaults to an empty font list, which current typst rejects: md -> pdf via typst failed for every document on Linux. Detect that template and pass a mainfont. - Documents with CJK text get a real CJK font: typst with an installed CJK font list behind its Latin font (instead of arbitrary fallback fonts), or CJKmainfont for XeLaTeX-family engines (preferred for .tex input). Font variables in the document's own front matter are left alone. - image -> pdf stages the image in a temp dir and runs pandoc there: old pandoc ignores --resource-path with typst, and names with spaces or parentheses broke the generated markdown.
mtmatt
force-pushed
the
fix/cjk-pdf-and-typst-install
branch
from
September 28, 2026 11:56
9eec41b to
f17115f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #29. This PR's base is
chore/cleanup-and-linux-fixes, so the diff shows only this change. Merge #29 first, then retarget this PR tomain.Fixes two user reports: the typst engine is never installed automatically, and Chinese text breaks in some conversions such as md→pdf. Reproducing them turned up a few more causes, listed below.
Root causes and fixes
typst never auto-installs on Linux/Windows.
tools.tomlhas a[typst]entry, butdownloader.rs'sManifesthad notypstfield (serde silently ignores the table) andensure_toolhad no"typst"arm. Soensure_typstalways failed withunknown tool: typst.Manifest::spec(name)lookup thattool_versionandensure_toolnow share.tools.tomltable resolves. It fails if thetypstarm is removed.A typst in the tool dir was never used.
detect_pdf_enginereturned the bare name"typst", and pandoc then couldn't find a binary that wasn't onPATH. The newdocument/pdf.rsfinds each engine's full path and appends engine dirs to pandoc'sPATH. Pandoc still gets the engine name, because with a full path it extracts images to absolute temp paths that typst refuses to read, which breaks png→pdf.md→pdf via typst failed for every document on Linux. Distro pandoc 3.1.x (Debian, Ubuntu, Fedora) ships a typst template whose default font list is
(), and current typst rejects an empty list ("font fallback list must not be empty"). The app now detects that template once per run and passes-V mainfont=Libertinus Serif. Newer pandoc gets no extra variables.CJK text. Pandoc's default fonts have no CJK glyphs:
Documents with CJK letters (ideographs, kana or Hangul) now get:
mainfont, pluscodefontfor code blocks). If none of the listed fonts is installed, typst falls back to its own choice and a warning is logged..texinput prefers XeLaTeX-family engines withCJKmainfont, since the typst writer would drop raw LaTeX.image→pdf (found along the way; old pandoc ignores
--resource-pathwith typst, and file names with spaces or parentheses broke): the image is now copied into a temp dir and pandoc runs there.Before / after (macOS, same Chinese/Japanese/Korean sample)
Testing
cjk_pdf_embeds_only_the_chosen_fontsruns real pandoc+typst and fails, naming SIL-Hei, without the fix.image_to_pdf_handles_relative_path_and_awkward_nameis a new CLI test.fonts-noto-cjkembeds Noto Serif CJK plus Libertinusmainfontis respected-D warningsis clean on macOS, Linux and Windows-gnu, and fmt is clean.🤖 Generated with Claude Code