Skip to content

Feat/d2 diagrams#16

Merged
JheisonMB merged 6 commits into
developfrom
feat/d2-diagrams
Jun 12, 2026
Merged

Feat/d2 diagrams#16
JheisonMB merged 6 commits into
developfrom
feat/d2-diagrams

Conversation

@JheisonMB

@JheisonMB JheisonMB commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

add d2 diagrams support

JheisonMB and others added 6 commits May 7, 2026 08:59
REGISTRY_REPO still targeted the old JheisonMB/texforge-templates, which only
resolved via GitHub's 301 redirect. Point it at UniverLab/texforge-templates.
Verified template list --all and template add download from the new registry.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diagram pipeline (src/diagrams/mod.rs):
- Cache rendered PNGs by content hash ({env}-{hash}.png), skipping re-render of
  unchanged diagrams across rebuilds (notably under --watch).
- Build the resvg font database once via a shared OnceLock instead of per diagram
  (scanning /mnt/c/Windows/Fonts over WSL 9P was slow).
- Raise rasterization from 1.5x to 3x (~300 dpi at \linewidth) for print quality.
- Fix invalid default \includegraphics[\linewidth] -> width=\linewidth.

Windows / TLS:
- Use TECTONIC_BIN (tectonic.exe on Windows) for the managed binary path so the
  installed tectonic is actually located and executable.
- Switch reqwest off aws-lc-rs to rustls+ring (rustls-no-provider + ring provider
  installed in main), removing the C-toolchain dependency that broke Windows/musl
  builds. Verified aws-lc-sys leaves the tree and HTTPS downloads still work.

Build/assets:
- Output the PDF as <title>.pdf in the project root from a temp build dir.
- Unify sanitize_filename in utils; clean removes the output PDF + legacy build/.
- mirror_assets symlinks nested assets next to .tex files (absolute targets).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add a \begin{d2}...\end{d2} environment that renders like mermaid and graphviz:
same options (width, height, scale, pos, caption, label, keepaspectratio),
same hash-based PNG caching, same figure output.

- Render via d2-little (pure-Rust port of the d2lang pipeline, MPL-2.0) to SVG,
  then through the existing svg_to_png path. No external binary, matching the
  self-contained philosophy of the mermaid/graphviz renderers.
- D2 embeds its fonts as @font-face WOFF, which usvg ignores, so its text relies
  entirely on the sans-serif fallback. Harden configure_sans_serif_family to fall
  back to any available family so D2 text never silently disappears.
- Linter checks \begin{d2} blocks for unclosed envs and invalid pos, like the
  other diagram types.
- Verified end to end: D2 renders node/edge labels and the figure embeds in the
  compiled PDF (Image XObject), alongside mermaid in the same document.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@JheisonMB JheisonMB added the target:develop Targets the develop branch label Jun 12, 2026
@JheisonMB JheisonMB merged commit aebb075 into develop Jun 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

target:develop Targets the develop branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant