youfoundjk_TeXcore/docs/features/tikz.md
Jovi Koikkara eea4d67e3e
feat(tikz): major rendering, layout, and editor enhancements (#1)
Fixes
- WebAssembly & initialization
  - Fix TikZJax WebAssembly initialization issues.

- Fonts & symbol rendering
  - Override DVI parser `machine.putText` to use split character code offsets from `tikzjax.js`.
  - Map codes 0–9 starting at 161 to fix incorrect Γ rendering (was showing as Θ).
  - Map codes 10–19 starting at 173 to resolve Ω and ⊗ collisions with soft hyphen.

- Layout & rendering
  - Fix SVG clipping by switching to `position: relative` with `overflow: visible`.
  - Adjust inline SVG behavior to prevent top-of-page clipping.

- Type compatibility
  - Cast types to `unknown` in `TikzJaxLoader` and worker functions for compatibility.

- Error handling & cleanup
  - Improve error handling across TikZ components.
  - Remove unused dependencies and unnecessary console logs.

Features
- Package loading system
  - Add robust dependency resolution in `loader.ts` for:
    - `tikz-cd`
    - `tikz-feynhand`
    - `pgfcalendar`
  - Ensure required libraries and keys load dynamically on demand.

- Rendering & layout improvements
  - Enhance SVG bounding box calculation.
  - Implement dynamic column width calculation.
  - Improve row and column layout alignment and responsiveness.

- TikZ editor enhancements
  - Add keyboard shortcut tooltips to sidebar buttons.
  - Introduce thickness control slider for elements.
  - Improve snapping system with modes:
    - grid
    - half
    - none
  - Add support for new shapes:
    - circles
    - rectangles
    - triangles
  - Improve TikZ code generation error handling.

Improvements
- Selection & editing UX
  - Add lasso selection for multiple vertices in `CanvasGrid`.
  - Support multi-element editing in `RightSidebar`.
  - Refactor `TikzEditorModal` to handle multiple selected vertices.
  - Enable batch updates for selected elements.

- Layout & styling
  - Compact `.block-language-tikz` layout:
    - margin: `1.5em 0` → `0.3em 0`
    - padding: `1rem 0` → `0`
  - Improve canvas controls and interaction styles.

- Component refactoring
  - Refactor `CanvasGrid` to use template literals.
  - Replace inline styles with `setCssStyles`.
  - Improve `TikzCodec` node naming clarity.
  - Improve `history manager` type safety with `EditorElement`.
  - Use `window.setTimeout` in asset manager for better compatibility.

- Accessibility & UI polish
  - Improve sidebar button titles and tooltips.
  - Standardize live preview overlay button titles.
  - Clean up modal styling and text consistency.

Documentation
- Revamp TeXcore plugin documentation:
  - Clarify PDF export features and settings.
  - Improve quick preview architecture explanation.
  - Enhance equation search and autocomplete docs.
  - Streamline snippets usage and transformations.
  - Expand TikZ diagrams section with graphical editor guide.
  - Improve getting started guide with clearer steps.
  - Add navigation and configuration updates.

- Update plugin manifest descriptions for clarity.
2026-06-06 12:08:11 +02:00

3.6 KiB

TikZ Diagrams & Graphical Editor

TeXcore integrates an offline, background-compiled TikZ vector graphics renderer and a fully interactive TikZ Graphical Editor. You can write standard LaTeX TikZ scripts directly inside code blocks or edit them visually using a drag-and-drop CAD-like interface.


Architecture & Worker Compilation

To prevent Obsidian UI freezes during heavy TeX compilations, TeXcore utilizes a decoupled Web Worker Compiler that operates fully offline:

sequenceDiagram
    participant Main as Obsidian Editor
    participant Worker as TikZJax Web Worker
    participant Disk as Local Storage (WASM)
    
    Main->>Disk: Read & decompress core assets (tex.wasm.gz, core.dump.gz)
    Main->>Worker: Spawn thread & send decompressed WebAssembly buffers
    Note over Worker: Spin up virtual memory filesystem
    Main->>Worker: Post compile command (TikZ code)
    Worker->>Worker: Sync compile to DVI format
    Worker-->>Main: Return DVI binary output
    Main->>Main: Translate DVI to SVG using dvi2html & insert into note

Editor Workflows

=== "Using Code Blocks" Create a code block in your markdown document and identify it with tikz. You can include packages like pgfplots or libraries in the preamble:

```tikz
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[xlabel=$x$, ylabel=$y$]
    \addplot[color=red,mark=x] coordinates {
      (2,-3) (3,5) (4,7)
    };
  \end{axis}
\end{tikzpicture}
\end{document}
```

=== "Using the Graphical Editor" 1. Click the Edit visually button on any rendered TikZ SVG block, or use the Command Palette (++ctrl+p++ → Insert display math or search for the TikZ Editor commands). 2. A CAD-style modal opens: - Left Sidebar: Component library featuring core shapes (lines, circles, rectangles) and package modules. - Center Canvas: Interactive grid with zoom (++ctrl+scroll++), panning (++spacebar+drag++), and snapping (toggle via ++g++ or ++h++). - Right Sidebar: Property editor (adjust color, bold, italics, font size, stroke thickness) and raw TikZ Code synchronization. 3. Press ++ctrl+z++ to undo and ++ctrl+y++ to redo actions. 4. Click the Update block button to compile and insert the code block into your note.


Component Package Manager

For complex diagrams (like circuits or flowcharts), the Graphical Editor features a Component Package Manager accessed via the footer button in the Left Sidebar.

!!! info "Package Installation Flow" Click Manage Packages and search for libraries like circuitikz. Installing a package decompresses and caches its TeX dependency files (.tex/.sty) in memory, dynamically expanding your visual element sidebar with custom shapes (e.g. resistors, logic gates, operational amplifiers) that can be drag-dropped onto the grid canvas.


Diagnostics & Troubleshooting

!!! warning "Common TikZ Compilation Hurdles" - Empty Container / Failed rendering: Verify that the tikzjax-assets folder exists inside your plugin installation directory: .obsidian/plugins/TeXcore/tikzjax-assets/. - Package Not Found Error: Double-check spelling inside your block preamble. Only packages included in the asset registry are available offline. - Canvas Panning Locked: Ensure you hold down the ++spacebar++ while dragging on the canvas container to pan the grid layout. - Compilation Timed Out: Avoid infinite loops or extremely dense coordinate calculations that exceed WebAssembly heap size allocations.