[Forge] Export-as-LaTeX for hypotheses, briefs, and analyses open

← Forge
Tarball export with venue templates + figures + BibTeX bib + Makefile; Overleaf deep link; uses venue-templates+scientific-writing skills.
Spec File

Effort: deep

Goal

A SciDEX synthesizer brief is the closest thing the platform has to
a "publishable artifact" — it has structured sections, citations,
figures, an evidence table. But there's no path from there to a
LaTeX manuscript a researcher can import into Overleaf or submit
to a venue. The K-Dense skills bundle already ships venue-templates, scientific-writing, and latex-posters
skills; lean on them to ship a one-click "Export to LaTeX" path
that emits venue-templated .tex + a tarball of figures and a .bib. Specifically valuable for the synthesizer briefs and for
high-quality hypothesis pages.

Acceptance Criteria

Module scidex/forge/latex_export.py:
- export_artifact_to_latex(artifact_id, venue:
Literal['neurips','nature_methods','plos_one',
'arxiv_preprint']='arxiv_preprint') -> Path
returns a
path to a self-contained tarball with main.tex,
references.bib, figures/, Makefile.
- Pulls the artifact's content_md, citations, and figure
URLs from PG; converts mermaid diagrams to PDF via
existing mermaid_utils.py:render_to_pdf (or shell-out
if absent).
- Uses the venue-templates skill to fetch the right
document class and bib style.
- Citations: each attributed_evidence PMID/DOI is
resolved to a BibTeX entry via Crossref's
https://api.crossref.org/works/<doi>/transform/
application/x-bibtex
(and PubMed for PMIDs without DOIs).
Schema migrations/<date>_latex_exports.sql:

CREATE TABLE latex_exports (
        id UUID PRIMARY KEY,
        artifact_id TEXT NOT NULL REFERENCES artifacts(id),
        venue TEXT NOT NULL,
        export_path TEXT NOT NULL,
        bytes BIGINT,
        figure_count INT,
        bib_entry_count INT,
        created_by TEXT,
        created_at TIMESTAMP NOT NULL DEFAULT NOW()
      );

Route GET /artifacts/{id}/export.tex.tar.gz?venue=X
streams the tarball; first call renders + caches, second
call serves from data/scidex-artifacts/exports/.
Button. Every artifact page (hypothesis, brief,
analysis) gets an "Export → LaTeX" dropdown with the four
venues.
Overleaf deep link. "Open in Overleaf" button posts the
tarball to https://www.overleaf.com/docs?snip_uri=...
pre-baked URL so the user lands directly in the editor.
Tests tests/test_latex_export.py:
- Synthetic 3-section artifact → tarball contains the
right files; make (in a sandbox container) compiles
without errors.
- BibTeX resolution dedup (same DOI cited twice → 1 bib
entry).
- Mermaid → PDF fallback when PDF renderer absent.
Smoke. Export a real synthesizer brief; attach the
compiled PDF to the Work Log.

Approach

  • Tarball generation in a temp dir; copy to
  • data/scidex-artifacts/exports/<artifact_id>/<venue>/.
  • BibTeX resolution is the trickiest piece — cache aggressively
  • in a bib_entries table keyed on doi/pmid.
  • Mermaid → PDF: prefer the existing renderer; fallback to a
  • pre-rendered PNG embedded as \includegraphics.
  • Overleaf link is a pure URL; no extra OAuth needed.
  • Dependencies

    • venue-templates, scientific-writing skills (already in
    vendor/kdense-skills).
    • mermaid_utils.py — diagram rendering.

    Dependents

    • q-integ-cite-this-bibtex — shares the BibTeX resolver
    cache.

    Work Log

    Sibling Tasks in Quest (Forge) ↗