Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/desktop/src/main/tikz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = { 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",
});
Expand Down