Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
de099f1
feat: add webview_output module with QOI rendering
yzr278892 Apr 28, 2026
bf373d9
feat: add 7 new editor commands for webview preview
yzr278892 Apr 28, 2026
7946813
feat: add -webview mode to driver and main event loop
yzr278892 Apr 28, 2026
0fc3d86
fix: build fixes for webview mode - PATH_MAX include, QOI linking
yzr278892 Apr 28, 2026
7cfb884
fix(tikz): prevent page rendering abort on unrecognized specials
yzr278892 Apr 28, 2026
39d4efa
feat(tikz): add pdf:literal handler, route to pdf_code parser
yzr278892 Apr 28, 2026
dc7b408
fix(tikz,webview): add PDF v/y curve operators, fix webview mode crash
yzr278892 Apr 28, 2026
1a83bf7
fix: use SDL_WINDOW_HIDDEN then ShowWindow to avoid blocking
yzr278892 Apr 28, 2026
ae04b70
fix: render pages immediately in webview mode, fix mkstemp template
yzr278892 Apr 28, 2026
1a985cb
feat: dark mode support, incremental render fix, light mode default
yzr278892 Apr 28, 2026
9ce579e
fix: zoom system, scroll, SyncTeX, preview lifecycle, page dimensions…
yzr278892 Apr 29, 2026
dc846a4
fix: incremental rendering with dirty rects, SyncTeX coords, time-bas…
yzr278892 Apr 29, 2026
a6589fc
fix: real-time rendering, page preloading, page input error handling
yzr278892 Apr 29, 2026
66e7d9f
fix: optimize real-time rendering, remove redundant render_page
yzr278892 Apr 29, 2026
9cea046
fix: remove double webview render and lower default resolution to 2x
yzr278892 Apr 29, 2026
57cf7d0
fix: restore immediate webview render with deduplication guard
yzr278892 Apr 29, 2026
0edc128
feat: auto-preload all pages in webview mode, fix go-end cascading
yzr278892 Apr 29, 2026
7f4fbcf
fix: prevent busy loop in webview preloading by only continuing on ne…
yzr278892 Apr 29, 2026
0f063d7
fix: revert complex event-loop changes, use simple preload phase
yzr278892 Apr 29, 2026
5f20c34
fix: poll engine continuously instead of breaking on step() false
yzr278892 Apr 29, 2026
14e8ac4
refactor: remove sync preload, use on-demand page discovery
yzr278892 Apr 29, 2026
c997076
fix: reduce go-end/set-page stalled limit to 50000 (~500ms)
yzr278892 Apr 29, 2026
61b8b26
feat: send synctex-scroll position to webview preview
yzr278892 Apr 29, 2026
73d89bc
fix: change C auto-detect resolution from 2x to 2.5x to match webview…
yzr278892 Apr 29, 2026
94e151c
feat: add -resolution flag to control C-side auto-detect resolution
yzr278892 Apr 29, 2026
c1f0544
fix(tikz): extend dash array capacity from 4 to 32 elements
yzr278892 Apr 29, 2026
aaad85e
feat(tikz): implement PDF text operators for TikZ node labels
yzr278892 Apr 29, 2026
75a393b
feat(tikz): implement no-op handlers for marked content, color spaces…
yzr278892 Apr 29, 2026
0c31b69
feat(tikz): add fill_alpha/stroke_alpha to graphics state for transpa…
yzr278892 Apr 29, 2026
eebd68e
feat(tikz): add papersize= format support, add comprehensive TikZ tes…
yzr278892 Apr 29, 2026
0f5aff7
feat(tikz): implement pgf PostScript shading special parser
yzr278892 Apr 30, 2026
c293060
fix(tikz): suppress unhandled special warnings, keep page rendering a…
yzr278892 May 2, 2026
372c420
fix(tikz): consume operands for all no-op PDF operators to prevent st…
yzr278892 May 2, 2026
cbb7c80
debug(tikz): temporarily hardcode alpha to 1.0 to isolate rendering bug
yzr278892 May 2, 2026
3802431
fix(tikz): initialize PDF text state defaults (Tz scale = 1.0)
yzr278892 May 2, 2026
83601c1
fix(tikz): disable pgf shading handler to prevent format generation c…
yzr278892 May 2, 2026
5b18569
fix(tikz): fix color handling, alpha, and PS state management
yzr278892 May 2, 2026
7a0e1d8
fix(tikz): parse PS setdash array, add path commands in ps_exec_body,…
yzr278892 May 2, 2026
41c4b7b
fix(tikz): add concat, opacity, and PS stack commands to ps_code and …
yzr278892 May 2, 2026
85403cc
fix(tikz): strip [ and ] from PS tokens to correctly parse concat arrays
yzr278892 May 2, 2026
738b80a
fix(tikz): concat from frame base CTM to prevent cumulative position …
yzr278892 May 2, 2026
be628ec
fix(tikz): don't drop path after pgffill, add pgfs/pgfr/pgfo handlers
yzr278892 May 2, 2026
02906ff
fix(tikz): correct PS-to-device Y coordinate conversion in concat
yzr278892 May 2, 2026
8473252
fix(tikz): support 'bind def' in PS function definitions, pre-scan ! …
yzr278892 May 2, 2026
855f807
fix(tikz): drop stale path at end of ps_code/ps_exec_body specials
yzr278892 May 3, 2026
17096a5
fix(tikz): prevent ps_parse_defs from overwriting existing function d…
yzr278892 May 3, 2026
8b83de1
fix(tikz): pgfe shape detection and stroke color fallback
yzr278892 May 3, 2026
e2faf99
fix(tikz): add PS W/W* clip operator and fix pgfe rectangle coords
yzr278892 May 3, 2026
2d661ea
fix(tikz): prevent PS stack corruption from ps_exec_body
yzr278892 May 3, 2026
3257daa
fix(tikz): pgfe rectangle, PS operators, and function table preservation
yzr278892 May 3, 2026
c769bae
fix(tikz): color leak and W clip debug
yzr278892 May 3, 2026
11ec49a
fix(tikz): ! special handler preserves /pgf prefix and add concat debug
yzr278892 May 3, 2026
712127c
fix(tikz): execute pgffc/pgfsc bodies immediately on definition
yzr278892 May 3, 2026
0c75c3a
fix(tikz): move papersize handler from dvi_exec_pdf to dvi_exec_special
yzr278892 May 3, 2026
a80eb89
fix(tikz): fix text positioning, color separation, and stroke fallback
yzr278892 May 3, 2026
2ba3338
fix(tikz): fix text TRM order and add PS clip/eoclip operators
yzr278892 May 3, 2026
f3bf34b
fix(tikz): fix text TRM matrix concatenation order
yzr278892 May 3, 2026
2bf269d
debug(tikz): add DVI text rendering debug output for CTM tracing
yzr278892 May 3, 2026
a42cbf2
experiment(tikz): temporarily disable Y fix in concat to test double-…
yzr278892 May 3, 2026
10f09a9
fix(tikz): use base CTM without Y flip in concat handlers
yzr278892 May 3, 2026
646caa0
fix(tikz): correct concat Y position formula to mat.f + 72
yzr278892 May 3, 2026
7ffb82e
fix(tikz): chain concat to current CTM instead of base_ctm
yzr278892 May 3, 2026
923c5c3
fix(tikz): chain concat to dvi_get_ctm to preserve TeX page position
yzr278892 May 3, 2026
08f21fa
feat(tikz): add PS scale/translate/rotate/currentpoint operators for …
yzr278892 May 4, 2026
869347b
fix(tikz): scale/translate/rotate must apply to full CTM with TeX pos…
yzr278892 May 4, 2026
9939d94
fix(tikz): simplify test document — remove figure floats, fix phase n…
yzr278892 May 4, 2026
d901b62
fix(tikz): replace matrix with manual node grid to avoid \& issues
yzr278892 May 4, 2026
5433425
fix(tikz): remove patterns test — PS pattern operators not yet supported
yzr278892 May 4, 2026
2b7496a
fix(tikz): add scale operator debug output, simplify resizebox test
yzr278892 May 4, 2026
eefc2de
fix(tikz): intercept PGF shading functions in ps_code, scope PS state…
yzr278892 May 4, 2026
99bf146
fix(tikz): parse PS shading pattern dictionaries for native gradient …
yzr278892 May 4, 2026
1d11c17
debug(tikz): add shading parser debug output
yzr278892 May 4, 2026
fe762db
debug(tikz): more shading parser debug output
yzr278892 May 4, 2026
5c00d26
debug(tikz): increase trace limit to 500 chars for shading
yzr278892 May 4, 2026
854fcb3
debug(tikz): dump full shading special content
yzr278892 May 4, 2026
3fb2837
debug(tikz): add CTM and dev debug to shading path
yzr278892 May 4, 2026
d6877dd
fix(tikz): preserve first /C0 instead of last in shading FunctionType 3
yzr278892 May 4, 2026
49093b6
fix(tikz): use path bounds for shading perpendicular extent
yzr278892 May 4, 2026
11f9701
fix(tikz): smooth axial shading with more steps and gradient-axis ove…
yzr278892 May 4, 2026
48bac7e
test(tikz): add new test phases for shading variants, patterns, ancho…
yzr278892 May 4, 2026
21879d7
fix(tikz): proper stitching function evaluation for shading colors
yzr278892 May 4, 2026
a4cfe2f
debug(tikz): add alpha and color sample output to render_axial_shade_…
yzr278892 May 4, 2026
06243f1
fix(tikz): use transparency group for shading with alpha < 1
yzr278892 May 4, 2026
aec03d4
fix(tikz): proper radial shading with stitching function and 400 steps
yzr278892 May 4, 2026
6ee3a5d
fix(tikz): parse 6-value Coords for radial shadings
yzr278892 May 4, 2026
d1d08d6
debug(tikz): add nbounds and color samples to radial shading output
yzr278892 May 4, 2026
2880250
fix(tikz): use full-range lerp for radial shading instead of stitchin…
yzr278892 May 4, 2026
61fe8d9
Revert "fix(tikz): use full-range lerp for radial shading instead of …
yzr278892 May 4, 2026
36bc752
feat(tikz): add native tiling pattern support for PatternType 1 fills
yzr278892 May 4, 2026
0850055
fix(tikz): prevent path drop and body truncation in tiling pattern ha…
yzr278892 May 4, 2026
9a876c8
chore(tikz): regenerate dvi_special.c with clean build
yzr278892 May 4, 2026
1d949ea
fix(tikz): increase PS_FUNC_MAX 16→64 to fix pattern rendering
yzr278892 May 4, 2026
87ec9df
Revert "feat(tikz): add native tiling pattern support for PatternType…
yzr278892 May 4, 2026
65905d5
fix(tikz): remove clip path from render_pattern_tiles
yzr278892 May 4, 2026
21da1a7
fix(tikz): add pattern state init and fields for tiling pattern support
yzr278892 May 4, 2026
0de37d2
Revert "fix(tikz): add pattern state init and fields for tiling patte…
yzr278892 May 4, 2026
a94448e
Revert "fix(tikz): remove clip path from render_pattern_tiles"
yzr278892 May 4, 2026
50cad67
fix(tikz): extract pattern color from pgffc body for pattern fills
yzr278892 May 5, 2026
922ed45
fix(tikz): extract pattern color at pgffc definition time
yzr278892 May 5, 2026
a0cb8c0
feat(tikz): add pattern texture rendering via separate pattern table
yzr278892 May 5, 2026
03e2c6a
revert(tikz): remove pattern texture rendering, keep color extraction
yzr278892 May 5, 2026
24acbde
chore: clean up build artifacts and update .gitignore
yzr278892 May 5, 2026
f5d2789
docs(tikz): add TikZ support documentation and demo screenshots
yzr278892 May 5, 2026
a027de8
docs: add VSCode demo screenshots for pages 1, 3, 5
yzr278892 May 5, 2026
f9c6f81
fix(tikz): address Copilot review comments for TikZ PR #135
yzr278892 May 5, 2026
2f17664
fix(tikz): revert risky Copilot fixes, keep only dquote and SCN/scn
yzr278892 May 5, 2026
54a70c5
fix(tikz): re-apply remaining Copilot review fixes (gs_stack, text re…
yzr278892 May 5, 2026
0e5dcfe
fix(tikz): guard TRACE sp debug logging, fix dirty rect height limit
yzr278892 May 5, 2026
e427598
fix(tikz): restore page-diff JSON format for VSCode extension compati…
yzr278892 May 6, 2026
4ce855d
fix: process RELOAD_EVENT during engine advances in webview mode
yzr278892 May 6, 2026
86423ca
feat(tikz): add graphics state infrastructure and DVI push/pop gs sav…
yzr278892 May 9, 2026
561701c
feat(tikz): add text rendering, alpha propagation, and error resilien…
yzr278892 May 9, 2026
a9f10d9
feat(tikz): add PS interpreter, PGF handlers, gradient shading, and s…
yzr278892 May 9, 2026
f9a898d
chore: remove development debug code from dvi_prim.c
yzr278892 May 9, 2026
044465a
test: add comprehensive TikZ test document
yzr278892 May 9, 2026
3971e86
chore(tikz): remove development debug code
yzr278892 May 9, 2026
9f69bbb
fix(tikz): preserve pattern color extraction across re2c regeneration
yzr278892 May 9, 2026
14c0371
feat: increase default resolution to 3.0 and support dynamic window r…
yzr278892 May 9, 2026
efc84b5
wip: pattern texture support - work in progress
yzr278892 May 21, 2026
38181e2
feat(tikz): use MuPDF fz_begin_tile/fz_end_tile for pattern rendering
yzr278892 May 22, 2026
e7b4206
fix(tikz): add pattern state reset + debug logging for pattern pipeline
yzr278892 May 22, 2026
15fa388
fix(tikz): fix pattern fill bugs in b/B/f operators
yzr278892 May 27, 2026
cffea71
fix(webview): fix dirty rect width miscalculation causing ghost traces
yzr278892 May 31, 2026
5d42427
Merge tikz-demo (comprehensive TikZ test document) into tikz
yzr278892 Jun 3, 2026
9d87e81
Remove all webview code from tikz branch
yzr278892 Jun 3, 2026
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
32 changes: 32 additions & 0 deletions EDITOR-PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ Check the filesystem for changes. This will reload and reprocess any changed fil

Asking the window manager to keep TeXpresso window above the others, or not. This can be convenient to keep a TeXpresso window floating on top of the editor. (`t` and `nil` are the closest approximation of "true" and "false" in emacs-sexp).

```scheme
(register "path")
```

Pre-register a filename that the editor will provide later via `open`. When the engine tries to read this file and it is not yet available, the driver pauses the engine and emits `(lookup-file read promised "path")`. Once the editor sends `open` for the path, the engine resumes without restarting.

```scheme
(pause)
(resume)
```

Suspend (or resume) engine stepping. While paused, TeXpresso keeps reading
stdin and applying editor commands (`open`, `register`, etc.) but does not
advance the TeX engine. Useful at startup with `-stream`: the editor can
prime the VFS via `(register)` and `(open)`, then send `(resume)` to begin
compilation — avoiding restarts from missing files. In `-stream` mode the
engine starts paused, so `(resume)` is required to begin compilation.

```scheme
(synctex-forward "path" line)
```
Expand Down Expand Up @@ -209,3 +227,17 @@ The paths are printed relative to the root file. They might be non-existent on t
Right now, this is implemented by hooking into SyncTeX:
- only text files are tracked (not graphics)
- the indices printed are the SyncTex input indices; they should be attributed no other meaning than being monotonic and useful to detect backtracking occurrences

### File lookups

```
(lookup-file kind status "path")
```

Output by TeXpresso when it tries to look up a file.
- `kind`: either `read` or `write`.
- `status`: either `successful`, `failed`, or `promised` if the editor had previously registered the file.
- `path`: the path to the file.

If `status` is `promised`, document processing will be stuck until the editor fulfills the promise by sending a corresponding `(open "path" ...)` or `(open-base64 "path" ...)` command.
This can only happen if the editor had registered the path using `(register "path")`.
73 changes: 73 additions & 0 deletions doc/TIKZ-SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# TeXpresso TikZ Support — PR Summary

This PR adds TikZ/pgf rendering support to TeXpresso. ~70 commits on branch `tikz` implement a PostScript interpreter and PDF content-stream handler that process the DVI specials emitted by PGF's drivers (dvips and dvipdfmx).

## What Works

### Path & Shape Rendering
`moveto`, `lineto`, `curveto`, `closepath`, `newpath`, rectangles (`pgfe`). All basic TikZ paths render: lines, curves (bézier, parabola), circles, ellipses, rectangles, arcs, grids, plot coordinates.

### Fill & Stroke
`pgffill`, `pgfstr`, `pgfs`/`pgfS`, `pgfr`/`pgfR`, `pgfeofill`. `\fill`, `\draw`, `\filldraw` all work. Stroke keeps the path after fill so `\filldraw` can issue both.

### Color
`setrgbcolor`, `setgray`, `setcmykcolor`, plus PGF's `pgffc`/`pgfsc` color-function scheme. Gray, RGB, and CMYK color spaces. Named xcolor colours resolve correctly.

### Graphics State
`gsave`/`grestore` (`q`/`Q`), line width (`pgfw`, `w`), line join, line cap, miter limit. Dash patterns including long arrays (>4 elements) via `setdash`.

### Transforms
PS `concat` (including `cm` in PDF content streams), `scale`, `translate`, `rotate`, `currentpoint`. CTM is built on the TeX page-position so that PGF coordinate arithmetic is correct. `\resizebox` and `\scalebox` from graphicx are supported.

### Clipping
`W`/`W*` and PS `clip`/`eoclip`. Stacks correctly with `gsave`/`grestore`.

### Text (Basic)
DVI text operators render node labels. Standard PDF 14 fonts are resolved lazily. The TRM matrix is concatenated correctly so that scoped/transformed node text positions are accurate.

### Shadings
Axial and radial gradients (`\shade`). RGB, CMYK, and gray colour models. Rendered natively via MuPDF's `fz_fill_shade`. FunctionType 3 stitching functions are evaluated analytically. Shadings with alpha < 1 use a transparency group.

### Transparency
`fill opacity` and `draw opacity`. Transparency groups (`transparency group` in `\begin{scope}`) render correctly for overlapping semi-transparent objects.

### Decorations
`zigzag`, `snake`, `brace`, `text along path`. Markings with arrow tips at arbitrary positions.

### Node Positioning
`above`, `below`, `left`, `right` with offsets. Named anchors (`.north`, `.south`, `.east`, `.west`, `.north east`, etc.). `fit` library.

### Loops & Maths
`\foreach` with `evaluate`, `count`, `remember`. `calc` library: `($(A)!0.5!(B)$)`, `($(A)+(1,2)$)`, `($(A)!(C)!(B)$)`.

### Matrix (Manual)
A grid of named nodes replaces the `\matrix` command (which requires `&` that conflicts with TeXpresso's frontend). Equivalent output.

### Patterns (Partial)
**Colour extraction works** — pattern-filled shapes show the correct colour. **Texture tiling is not implemented.** See *Known Issues* below.

## Architecture

### Two Special Formats
PGF emits content via two drivers, both are handled:

1. **dvips** — `ps:` and `ps::` DVI specials. Parsed by `ps_code()` in `dvi_special.c`. Tokens are interpreted by a simple stack machine.

2. **dvipdfmx** — `pdf:` DVI specials. Content streams (`pdf:code` / `pdf:literal`) are parsed by `pdf_code()` which uses a vstack-based PDF operator interpreter. Graphics-state specials (`pdf:btrans`/`pdf:etrans`, `pdf:bc`/`pdf:ec`, `pdf:q`/`pdf:Q`) are handled directly.

### PS Function Table
PGF defines ~96 internal functions via `!` specials. TeXpresso stores the 16 most recent in `ps_funcs[]` (PS_FUNC_MAX=16). This limit is a careful trade-off: expanding it lets internal functions leak into the token-dispatch fallback path and corrupt rendering state.

### Shading Pipeline
`try_parse_ps_shading()` intercepts `<<` dictionaries inside `ps:` specials. When it detects a valid shading dictionary (`/ShadingType`, `/Coords`, `/Function`), it parses the parameters and calls `render_axial_shade()` or `render_radial_shade()`, which use MuPDF's `fz_fill_shade` to draw the gradient directly onto the device.

### Colour Management
PGF sets colours by defining a function (`/pgffc{...}def`) and later looking it up (`ps_lookup_func("pgffc")`). TeXpresso executes colour-function bodies at definition time so that inline `setrgbcolor`/`setgray`/`setcmykcolor` commands update `st->gs.colors.fill` and `st->gs.colors.line` immediately. This avoids a round-trip through the PS interpreter when the fill/stroke path is drawn.

## Known Issues

### Pattern Textures (Phase 13)
Pattern fills show the correct colour but no tiled texture. PGF emits patterns as PostScript `makepattern`/`setcolor` operators (dvips driver) or as `pdf:stream`/`pdf:put` specials (dvipdfmx driver). Neither path is handled by the current PS interpreter or PDF special handler. The dvips path requires implementing PatternType 1 tiling with per-tile PaintProc execution and clip management; the dvipdfmx path requires adding `stream`/`obj`/`put` rules in the PDF special dispatcher and modifying the `scn` operator to accept 4-operand pattern colours. Both approaches were prototyped but introduced crashes or incorrect output.

### Single-Page Hang with Direct XDV Rendering
When invoked as `texpresso file.xdv`, only the first page renders before the process hangs. The VSCode extension pipeline does not have this issue. Likely a teardown-path bug in the standalone DVI engine, not related to TikZ support.
Binary file added doc/tikz1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/tikz3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/tikz5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading