Skip to content

fix: CircuiTikZ loads indefinitely on desktop#349

Closed
kuyacarlo wants to merge 1 commit into
ZenNotes:mainfrom
kuyacarlo:feat/fix-circuitikz
Closed

fix: CircuiTikZ loads indefinitely on desktop#349
kuyacarlo wants to merge 1 commit into
ZenNotes:mainfrom
kuyacarlo:feat/fix-circuitikz

Conversation

@kuyacarlo

@kuyacarlo kuyacarlo commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

On Linux desktop app, rendering circuits with CircuiTikZ loads indefinitely, or crashes entirely.

Technical details (Antigravity)

node-tikzjax uses a WebAssembly port of TeX with a hardcoded memory limit (pool_size = 920,271 characters). ZenNotes was pre-loading the heavy pgfplots package by default for all TikZ blocks, leaving almost no room in the string pool for loading additional large packages like circuitikz.

Changes

  1. Dynamic Loading for pgfplots: Modified apps/desktop/src/main/tikz.ts to inspect the TikZ code block. pgfplots is now only loaded if the code block explicitly contains "pgfplots", "axis", or "plot".
  2. Auto-detection for circuitikz: The runner now scans the code block for "circuitikz" or "ctikzset" and automatically injects the circuitikz package into texPackages. This enables circuit schematics to render out-of-the-box without requiring users to write \usepackage{circuitikz} in their note preambles.
  3. No-op/Minimal Impact: Standard plots continue to load pgfplots automatically, while other diagrams (circuit diagrams, block diagrams, logic trees) gain a significant memory pool margin, resolving the compilation crashes.

Not addressed

  • Circuits flash as I type it in, inside of split view mode.
Screencast.From.2026-07-08.22-26-01.mp4
CircuiTikZ Error TikZ error: TeX engine render failed. Set `options.showConsole` to `true` to see logs.

! Emergency stop.
l.2 \ctikzset
{bipoles/length=.9cm}

CircuiTikZ Code
\ctikzset{bipoles/length=.9cm}
\begin{circuitikz}[american]
    \draw (-3,0.5) -- (3,0.5);
    \draw (0,0.5) -- (0,1) node[above]{$V_{CC}$};
    
    \draw (-3,0.5) to[R=$R_{C1}$] (-3,-1.5)
    -- (-3,-2) node[npn, anchor=C](Q1){$Q_1$};
    
    \draw (3,0.5) to[R=$R_{C2}$] (3,-1.5)
    -- (3,-2) node[npn, anchor=C, xscale=-1](Q2){%
        \scalebox{-1}[1]{$Q_2$}% Prevents label text from being mirrored
    };
    
    \draw (Q1.B) -- (-4.5, 0 |- Q1.B) 
    to[vsourcesin, l_=$v_{in1}$] (-4.5, -4.5) node[ground]{};
    
    \draw (Q2.B) -- (4.5, 0 |- Q2.B) 
    to[vsourcesin, l=$v_{in2}$] (4.5, -4.5) node[ground]{};
    
    \draw (Q1.E) |- (0,-3.5) node[circ]{} -| (Q2.E);
    
    \draw (0,-3.5) to[isource, l=$I_{EE}$] (0,-5)
    node[below]{$V_{EE}$};
\end{circuitikz}
\ctikzset{bipoles/length=.9cm}
\begin{circuitikz}[american]
  % Horizontal VCC rail (at Y = 0.5)
  \draw (-3,0.5) -- (3,0.5);
  \draw (0,0.5) -- (0,1) node[above]{$V_{CC}$};
  
  % Left branch: collector resistor RC1 down to transistor Q1
  \draw (-3,0.5) to[R=$R_{C1}$] (-3,-1.5)
  -- (-3,-2) node[npn, anchor=C](Q1){$Q_1$};
  
  % Right branch: collector resistor RC2 down to transistor Q2 (flipped horizontally)
  \draw (3,0.5) to[R=$R_{C2}$] (3,-1.5)
  -- (3,-2) node[npn, anchor=C, xscale=-1](Q2){%
      \scalebox{-1}[1]{$Q_2$} % Prevents label text from being mirrored
  };
  
  % Base inputs (clean horizontal protruding wires)
  \draw (Q1.B) -- (-4, 0 |- Q1.B) node[left]{$V_{in1}$};
  \draw (Q2.B) -- (4, 0 |- Q2.B) node[right]{$V_{in2}$};
  
  % Emitters merge orthogonally at a common node with a junction dot
  \draw (Q1.E) |- (0,-3.5) node[circ]{} -| (Q2.E);
  
  % Common emitter resistor from junction down to VEE
  \draw (0,-3.5) to[R=$R_E$] (0,-5)
  node[below]{$V_{EE}$};
\end{circuitikz}

Note: Code edited by Google Antigravity

@kuyacarlo
kuyacarlo requested a review from adibhanna as a code owner July 8, 2026 14:07
@kuyacarlo
kuyacarlo force-pushed the feat/fix-circuitikz branch 2 times, most recently from f02dfba to bc45e74 Compare July 8, 2026 14:12
@kuyacarlo
kuyacarlo force-pushed the feat/fix-circuitikz branch from bc45e74 to f74654a Compare July 8, 2026 14:12
@kuyacarlo kuyacarlo changed the title feat(desktop): load pgfplots dynamically to support circuitikz and free pool memory fix: CircuiTikZ loads indefinitely on desktop Jul 8, 2026
@adibhanna

Copy link
Copy Markdown
Contributor

Thanks @kuyacarlo, this is a solid fix and the mechanism is exactly right: node-tikzjax's WASM TeX engine has a fixed string-pool limit, and always pre-loading the heavy pgfplots left no room for circuitikz. Loading pgfplots only when a block references pgfplots/axis/plot, and auto-injecting circuitikz on detection, is the clean solution.

I've merged your commit into the release/v2.12.0 branch (fast-forward, so your authorship is preserved) rather than main, which is why GitHub didn't auto-close this. Closing it manually; it'll ship in v2.12.0.

Verified before merging:

  • Desktop typecheck passes.
  • In-app over CDP: your exact CircuiTikZ repro now renders to a valid SVG, a pgfplots axis/addplot block still renders (no regression), and basic TikZ is unaffected.

The "circuits flash while typing in split view" note is a separate, pre-existing preview-refresh quirk, not something this PR needs to address. Thanks again!

@adibhanna

Copy link
Copy Markdown
Contributor

Merged into release/v2.12.0 (see comment above). Shipping in v2.11.0's successor.

@adibhanna adibhanna closed this Jul 8, 2026
@kuyacarlo
kuyacarlo deleted the feat/fix-circuitikz branch July 10, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants