Skip to content

feat: add LaTeX/TikZ export for generated diagrams and plots#143

Open
YB0y wants to merge 10 commits into
llmsresearch:mainfrom
YB0y:feature/tikz-export
Open

feat: add LaTeX/TikZ export for generated diagrams and plots#143
YB0y wants to merge 10 commits into
llmsresearch:mainfrom
YB0y:feature/tikz-export

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Apr 8, 2026

Summary

  • Adds TikZExporterAgent — a new VLM-powered agent that converts any generated image to compilable LaTeX source by reasoning about its visual structure
  • Integrates export into the pipeline via --export-tikz (diagrams) and --export-pgfplots (plots); the .tex file is saved alongside the raster output in the same run directory
  • Adds a standalone paperbanana tikz --input <image> subcommand for post-hoc conversion of any previously generated image
  • Adds examples/tikz_export.py demonstrating all three usage patterns

Motivation

Academic venues (IEEE, ACL, NeurIPS camera-ready) require editable figure source files. Until now, the only output was raster images (PNG/JPEG/WebP), forcing researchers to manually redraw figures in TikZ after using PaperBanana for the conceptual work. This PR closes that gap without changing any existing behaviour — export is opt-in via flags.

Changes

Area What changed
agents/tikz_exporter.py New TikZExporterAgent extending BaseAgent; VLM call at temperature=0.2 with image + context; strips code fences; prepends metadata header
prompts/diagram/tikz_exporter.txt Prompt instructing the VLM to produce a \begin{tikzpicture} snippet using only standard packages
prompts/plot/tikz_exporter.txt Prompt for PGFPlots output with \begin{axis} structure
core/config.py export_tikz: bool and export_pgfplots: bool settings; YAML key map entries
core/types.py TIKZ_EXPORTER_START/END progress stages; tikz_path: Optional[str] on GenerationOutput
core/pipeline.py Instantiates TikZExporterAgent; runs it after the final image is saved; writes .tex; populates result.tikz_path; budget/cost tracking included
cli.py --export-tikz on generate; --export-pgfplots on plot; tikz_path printed in result output; new tikz subcommand
examples/tikz_export.py Three documented patterns: generate+export, post-hoc export, plot+PGFPlots

Usage

# Generate + export TikZ in one shot
paperbanana generate \
  --input method.txt \
  --caption "Transformer encoder architecture" \
  --export-tikz
# → outputs/<run_id>/final_output.png
# → outputs/<run_id>/final_output.tex

# Convert an existing image post-hoc
paperbanana tikz \
  --input outputs/<run_id>/final_output.png \
  --source-context method.txt \
  --caption "Transformer encoder architecture"

# Statistical plot → PGFPlots
paperbanana plot \
  --data data.csv \
  --intent "Accuracy vs model size" \
  --export-pgfplots

Test plan

  • paperbanana generate --input ... --caption ... --export-tikz produces a .tex file alongside the PNG with correct metadata header
  • paperbanana tikz --input <existing_image> writes a .tex file to the same directory
  • paperbanana plot --data ... --intent ... --export-pgfplots produces PGFPlots output
  • --export-tikz absent → no .tex file written, result.tikz_path is None (no behaviour change)
  • Emitted .tex compiles under pdflatex without errors on a sample diagram
  • paperbanana tikz --help shows all flags correctly

Closes #174

@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Apr 8, 2026

Hi @dippatel1994 I've opened PR for new feature. Could you please review this and share any feedback?

@dippatel1994
Copy link
Copy Markdown
Member

Hey @YB0y, heads up that PR #145 by @itdeveloper1988 implements the same TikZ/LaTeX export feature for the same issue #137. PR #145 includes 19 tests while this one ships examples/tikz_export.py. Could you two coordinate on a single PR? Also lint is failing here - please run ruff check && ruff format and add tests for the agent and CLI paths.

@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Apr 15, 2026

Hi @dippatel1994 Thank you for your feedback. I added test code and fixed lint error. Could you take another look at this?

Copy link
Copy Markdown
Member

@dippatel1994 dippatel1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests added (14 functions covering extract_code, agent run, and CLI subcommand) and lint clean. Nice PGFPlots support and venue/header metadata. Thanks @YB0y!

@dippatel1994
Copy link
Copy Markdown
Member

Hey @YB0y, CI is failing with SyntaxError: '(' was never closed and 4 lint errors. Looks like the merge with main introduced a syntax issue. Please check and fix locally - run python -c 'import paperbanana.cli' to find the unclosed paren, then ruff check to catch the rest.

@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Apr 16, 2026

@dippatel1994 Thank you for taking the time to review my PR. I’ve resolved the conflicts and lint errors. Could you please take another look?

@dippatel1994
Copy link
Copy Markdown
Member

Hey @YB0y, lint passes now but all 9 test jobs are still failing. Please check the test failures locally with pytest tests/ -v --tb=short and push a fix.

@dippatel1994
Copy link
Copy Markdown
Member

Hey @YB0y, tests are still red. Two failures:

  1. test_tikz_subcommand_help - assertion '--input' in output fails because Rich wraps the help text at narrow terminal widths in CI. Try setting terminal_width on the CliRunner or use --no-color / COLUMNS=200.
  2. test_plot_accepts_export_pgfplots_flag - the --export-pgfplots flag is not rendered in plot help at all. Verify the flag is actually wired on the plot command.

YB0y added 2 commits April 22, 2026 19:45
…re/tikz-export

# Conflicts:
#	paperbanana/cli.py
#	paperbanana/core/pipeline.py
#	paperbanana/core/types.py
@YB0y YB0y force-pushed the feature/tikz-export branch from 674dafd to 66c39b2 Compare April 22, 2026 18:19
@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Apr 22, 2026

@dippatel1994 please review this.

@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented May 6, 2026

@dippatel1994 , I’d appreciate it if you could review this when you have time.

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.

[Feature]: Export generated diagrams as LaTeX / TikZ source code

2 participants