From f74654a11dbb8c2c5a1ae0786417d4c2e25a3289 Mon Sep 17 00:00:00 2001 From: Carlo <106532351+kuyacarlo@users.noreply.github.com> Date: Wed, 8 Jul 2026 22:12:45 +0800 Subject: [PATCH] feat(desktop): load pgfplots dynamically to support circuitikz and free pool memory --- apps/desktop/src/main/tikz.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/main/tikz.ts b/apps/desktop/src/main/tikz.ts index 62a23b93..4f396a34 100644 --- a/apps/desktop/src/main/tikz.ts +++ b/apps/desktop/src/main/tikz.ts @@ -157,13 +157,32 @@ export async function renderTikz( try { const fn = await load(); + // Only load pgfplots if it's referenced in the source code. + // pgfplots is extremely heavy and exhausts the TeX engine's pool size + // limit (~920k) when combined with other large packages (like circuitikz). + const texPackages: Record = { amsmath: "", amssymb: "" }; + const usesPgfPlots = + source.includes("pgfplots") || + source.includes("axis") || + source.includes("plot"); + if (usesPgfPlots) { + texPackages.pgfplots = ""; + } + + const usesCircuiTikz = + source.includes("circuitikz") || + source.includes("ctikzset"); + if (usesCircuiTikz) { + texPackages.circuitikz = ""; + } + const svg = await fn(wrapSource(source), { showConsole: true, // Enable the common TikZ libraries people reach for first. The // wasm build ships with everything already compiled, so toggling // these flags only changes which `\usetikzlibrary{…}` / `\usepackage{…}` // statements get injected — negligible runtime cost. - texPackages: { pgfplots: "", amsmath: "", amssymb: "" }, + texPackages, tikzLibraries: "arrows.meta,calc,positioning,shapes,decorations.pathreplacing,intersections,patterns", });