An AI-agent skill for recreating mathematical scans, photos, and PDFs as visually faithful LaTeX projects.
Retypeset turns scanned mathematics into clean, publication-ready LaTeX—capturing the equations, theorem structure, cross-references, and typographic rhythm that ordinary text extraction leaves behind.
It tells an agent to:
- preserve source wording unless an edit is requested;
- build real LaTeX structure instead of using a page image as a shortcut;
- return editable
.texsource, not only a PDF; and - compile and compare the result with the reference whenever the environment allows it.
Each example pairs the visual source with its editable LaTeX reconstruction.
| Reference scan | LaTeX reconstruction |
|---|---|
![]() |
![]() |
| Reference scan | LaTeX reconstruction |
|---|---|
![]() |
![]() |
| Reference scan | LaTeX reconstruction |
|---|---|
![]() |
![]() |
Clone the skill repository:
git clone git@github.com:yunhaixiang/retypeset-skill.git
Then use the integration your agent supports:
| Agent setup | Use it this way |
|---|---|
| Codex | Register the repository as a SKILL.md skill. |
| Claude Code | Install the repository as a custom SKILL.md skill. |
| Cursor | Keep the repository in the project so Cursor reads the root AGENTS.md. |
| Other project-instruction agents | Copy SKILL.md into the agent's instruction file. |
| Chat based | Attach or paste SKILL.md together with the reference document. |
Codex and Claude Code use the canonical SKILL.md; Cursor reads AGENTS.md, which points back to the same instructions.
Stage 1: Preprocess the source
│
▼
Render pages, index the book, and create the LaTeX scaffold
│
▼
Stage 2: Transcribe one user-requested chunk
│
▼
Compile, compare, and audit that chunk
│
▼
Stage 3: Audit one user-requested completed chunk
The agent does not advance to the next chapter or stage unless the user requests it. It selects the LaTeX engine based on the document's actual needs, keeps dependencies practical, and records any nonstandard build requirement.
Use the Retypeset skill to recreate the attached document as a LaTeX project. Preserve the text and page layout. Use
main.texas the entry point, compile it, and include the compiled PDF for comparison. Flag any text that cannot be read reliably.
For the most faithful result, supply every page of the source and specify any required document class, TeX engine, fonts, and bibliography format. Retypeset uses direct visual inspection and never uses OCR.
For a multi-file document, a typical result looks like this:
document-name/
├── main.tex # Editable LaTeX entry point
├── figures/ # Original artwork that cannot be recreated natively
├── main.pdf # Compiled preview, when compilation is available
└── README.md # Build instructions, only when nonstandard steps are needed
The .tex source is the primary deliverable. The PDF is a verification artifact, not a substitute for editable source.
Retypeset is intentionally tool-neutral. Any capable AI agent that can read Markdown instructions and work with the supplied files can use it.
Visual verification requires both a LaTeX compiler and a way to render PDFs. If either is unavailable, the agent should still produce the source and clearly disclose that it could not verify the compiled visual result.
.
├── SKILL.md # Canonical skill instructions
├── AGENTS.md # Project-instruction discovery entry
├── assets/ # README example images
├── references/
│ ├── style.md # Mandatory mathematical typesetting conventions
│ └── book-workflow.md # Staged preprocessing, transcription, and audit workflow
└── agents/openai.yaml # Optional Codex/OpenAI UI metadata
The skill's behavior lives in SKILL.md. Keep changes focused on guidance that improves document-to-LaTeX fidelity or makes the workflow more reliable across agent environments.
Distributed under the MIT License.





