---
name: doc
description: 'Render Markdown, bundles, and LaTeX to PDF; extract text and render pages from PDF and Office files. Tools: extract-text, latex-to-pdf, markdown-to-pdf, pdf-to-images. Use when a request needs any of these; each tool''s own trigger is in SKILL.md.'
compatibility: 'Requires fragletc and Docker. Hermetic: no network access.'
metadata:
  tags: documents
  tools: extract-text.py, latex-to-pdf.sh, markdown-to-pdf.py, pdf-to-images.py
---

# Doc

Render Markdown, bundles, and LaTeX to PDF; extract text and render pages from PDF and Office files.

Every tool below is one executable file beside this `SKILL.md`, in the directory the commands below call `<skill-dir>`. Run it directly. Two host requirements: [`fragletc`](https://github.com/ofthemachine/fraglet) (`curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh && fragletc version`) and Docker; the image, parameters, outputs and network reach are declared in the file itself. Before running a tool, print its contract:

```sh
<skill-dir>/extract-text.py --fraglet-help
```

Parameters are passed as `-p name=value` (a `file` parameter takes a host path); declared outputs are copied out with `--output <name>[=<host path>]`. A missing required parameter fails host-side with exit 2 before any container starts; otherwise the tool's own exit code is the run's. A declared output not named with `--output` is produced and discarded (a stderr note says what you could have copied). Add `--receipt run.json` (or set `FRAGLETC_RECEIPT_DIR`) to record the run: the receipt carries the tool's `procedure_hash`, image digest, parameters, and every input and output by content hash, and `receipt/attest.py` can verify it later without re-running anything.

## Tools

### `extract-text.py`

Extract readable text out of PDF, DOCX, PPTX, XLSX, ODT, RTF, HTML, and plain-text documents into structured Markdown carrying page, slide, and sheet markers. The format is detected from file content, so no extension is needed; pages selects a 1-indexed subset such as "1-5" or "2,4,7-9" (PDF pages, PPTX slides, XLSX sheets).

Use when the user wants the text of a PDF, Word, PowerPoint, Excel, ODT, RTF, or HTML file, or a document's page count.

```sh
<skill-dir>/extract-text.py -p document="<document>" [-p pages="<pages>"] [-p format="<format>"]
```

Parameters:
- `document` (file, required) — Document mounted at /input/document; format sniffed from content
- `pages` (string, optional) — 1-indexed subset like 1-5 or 2,4,7-9 (pages, slides, or sheets)
- `format` (string, optional) — Force a format instead of sniffing: pdf, docx, pptx, xlsx, odt, rtf, html, text

Outputs:
- stdout

Runs in `ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522`; hermetic — `network=none`; a run is a pure function of its inputs and safe to memoize.

### `latex-to-pdf.sh`

Compile a LaTeX document to PDF (full TeX Live, offline, deterministic -- no runtime package fetching). Mounts input TeX file via fragletc file-shaped param (:file) to /input/tex_source.

Use when the user has LaTeX source and wants the compiled PDF.

```sh
<skill-dir>/latex-to-pdf.sh -p tex_source="<tex_source>" [-p engine=pdflatex] --output paper.pdf
```

Parameters:
- `tex_source` (file, required) — TeX source mounted at /input/tex_source
- `engine` (string, optional, default `pdflatex`) — TeX engine: pdflatex, xelatex, or lualatex

Outputs:
- `paper.pdf` — copy out with `--output paper.pdf[=<host path>]`

Runs in `ofthemachine/latex@sha256:add4f310e2fb92ebeeb7bc7fa5a95f920fa78adabcc8565301bbb178eac2a0b3`; hermetic — `network=none`; a run is a pure function of its inputs and safe to memoize.

### `markdown-to-pdf.py`

Render Markdown to one PDF with headless Chromium: inline text, a single .md (or .html) file, or a tar/tar.gz/zip bundle of pages plus the images and fonts they reference by relative path. Several pages become one document with page breaks (ordered by manifest.txt/order.txt when present, else by path) and a table of contents. style=reader applies clean reader typography; style=none renders the page exactly as authored, adding only the page box -- for pages that bring their own <style>, like newspapers, posters, and one-sheets.

Use when the user wants a PDF of some Markdown -- one note, a folder of documents compiled into a digest, or a designed page with its own assets and styling.

```sh
<skill-dir>/markdown-to-pdf.py [-p source="<source>"] [-p text="<text>"] [-p page="<page>"] [-p style=reader] [-p toc=auto] [-p title="<title>"] [-p size=A4] [-p margin="<margin>"] --output document.pdf
```

Parameters:
- `source` (file, optional) — A .md or .html file, or a tar/tar.gz/zip bundle of pages and their assets
- `text` (string, optional) — Inline Markdown (or pipe stdin), when there is no source file
- `page` (string, optional) — Render only this entry of a bundle (e.g. index.html); omitted, every .md in the bundle
- `style` (string, optional, default `reader`) — reader (house typography) or none (the page exactly as authored, plus the page box)
- `toc` (string, optional, default `auto`) — Table of contents: auto (when there is more than one page), true, or false
- `title` (string, optional) — Document title, shown as a heading above the contents (reader style only)
- `size` (string, optional, default `A4`) — Paper size (A4, Letter, ...)
- `margin` (string, optional) — Page margin on all sides (default 18mm for reader, 12mm for none)
- stdin (optional) — piped input is read in full and hashed into the run's receipt

Outputs:
- `document.pdf` — copy out with `--output document.pdf[=<host path>]`

Runs in `ofthemachine/headless-browser@sha256:8ac6f2f481f40e32a0b2f8dd7a834fd03197b1556bd8f55b1f167cd71d4877b0`; hermetic — `network=none`; a run is a pure function of its inputs and safe to memoize.

### `pdf-to-images.py`

Render PDF pages to high-resolution PNG images for visual inspection, slide viewing, or multimodal agent review.

Use when the user wants to see the visual layout of a PDF, inspect slides or figures, or convert PDF pages to PNG images.

```sh
<skill-dir>/pdf-to-images.py -p pdf_source="<pdf_source>" [-p page=1] [-p scale=2.0] --output page.png
```

Parameters:
- `pdf_source` (file, required) — PDF file mounted at /input/pdf_source
- `page` (string, optional, default `1`) — 1-indexed page number to render to page.png, or 'all' to bundle every page into pages.tar.gz
- `scale` (string, optional, default `2.0`) — Render scale factor (1.0 = 72 dpi, 2.0 = 144 dpi, 3.0 = 216 dpi)

Outputs:
- `page.png` — copy out with `--output page.png[=<host path>]`
- `pages.tar.gz` — copy out with `--output pages.tar.gz[=<host path>]`

Runs in `ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522`; hermetic — `network=none`; a run is a pure function of its inputs and safe to memoize.
